简体   繁体   English

被调用的构造函数不是 const 构造函数?

[英]The constructor being called isn't a const constructor?

I am brand new to flutter and programming in general -so please bear with me-, so I am taking a course on udemy and I stumbled with this error (The constructor being called isn't a const constructor) This is the code:我是 flutter 和一般编程的新手 - 所以请耐心等待 - 所以我正在上 udemy 的课程,我偶然发现了这个错误(被调用的构造函数不是 const 构造函数)这是代码:

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar:AppBar(
          title: Text('My First App'),
        ),
        body: Text('This is my default text'),
      ),
    );
  }
}

Try below code hope its help to you.试试下面的代码希望它对你有帮助。 remove const keyword删除const关键字

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('My First App'),
        ),
        body: Text('This is my default text'),
      ),
    );
  }
}

Your result screen->您的结果屏幕-> 在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 被调用的构造函数不是 const 构造函数 - The constructor being called isn't a const constructor Flutter 错误:被调用的构造函数不是 const 构造函数 - Flutter error : The constructor being called isn't a const constructor 被调用的构造函数不是 const 构造函数。 尝试从构造函数调用中删除“const”。 Flutter怎么解决? - The constructor being called isn't a const constructor. Try removing 'const' from the constructor invocation. Flutter How to solve? Flutter 错误 - 如何解决:被调用的构造函数不是 const 构造函数。 尝试从构造函数调用中删除“const” - Flutter Error - how to solve: The constructor being called isn't a const constructor. Try removing 'const' from the constructor invocation Dart 使用 FlexibleSpaceBar 背景属性时“被调用的构造函数不是常量构造函数” - Dart 'the constructor being called isn't a const constructor' when using FlexibleSpaceBar background property 更喜欢带有常量构造函数的 const - prefer const with constant constructor flutter const 构造函数错误 - flutter const constructor error 错误:找不到构造函数“ImagePickerOptions”。 ImagePickerOptions 选项 = const ImagePickerOptions() - Error: Couldn't find constructor 'ImagePickerOptions'. ImagePickerOptions options = const ImagePickerOptions() const 构造函数和 no_const 构造函数有什么区别? - What's the difference between const constructor and no_const constructor? Dart:使用const构造函数有不利之处吗? - Dart: Is there a disadvantage to using const constructor?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM