小编Ash*_*Ash的帖子

尝试在材质应用程序内使用文本时,AppBar 内出现 Flutter 非常量构造函数错误

您好,我有一个简单的问题,我在这里做错了什么?我正在尝试在脚手架中创建一个 AppBar,但是当我尝试使用 Text 时,它似乎不起作用,并要求添加一个 Const,但是当我这样做时,它并不能解决问题。

抱歉,如果已经有这方面的信息,我只是不知道解决此问题所需查找的具体条款。我知道您可以将 AppBar 放在 void main() 中,但是我正在遵循教程,并且希望以类似的方式进行操作。

import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: Text('My First App'),
          ),
          body: Text('This is the body of text.')
      ),
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

这是输出的错误:

12:25:错误:无法调用需要 const 表达式的非“const”构造函数。尝试使用“const”的构造函数或工厂。appBar: const AppBar( ^^^^^^

新错误:

../../runtime/platform/allocation.cc:14:错误:内存不足。版本=2.14.4(稳定)(2021 年 10 月 13 日星期三 11:11:32 +0200)在“windows_x64”上 pid=24408,线程=30512,isolate_group=(nil)(0000000000000000),isolate=(nil)(0000000000000000) isolate_instructions=0, vm_instructions=7ff65bad4f10 pc 0x00007ff65bcdaa42 fp 0x00000056bb8ff3c0 …

dart flutter flutter-text

3
推荐指数
1
解决办法
3117
查看次数

标签 统计

dart ×1

flutter ×1

flutter-text ×1