我使用 flutter sdk 中提供的 dart sdk 创建了一个简单的独立应用程序
如果我运行这段代码
main() {
MyClass myObj=MyClass();
}
class MyClass{
}
NoSuchMethodError: Attempted to use type 'MyClass' as a function. Since types do not define a method 'call', this is not possible. Did you intend to call the MyClass constructor and forget the 'new' operator?
颤动--版本
- Flutter 0.3.2 • channel 测试版 • https://github.com/flutter/flutter.git
- 框架 • 修订版 44b7e7d3f4(3 周前) • 2018-04-20 01:02:44 -0700
- 引擎 • 修订版 09d05a3891
- 工具 • Dart 2.0.0-dev.48.0.flutter-fe606f890b
那么我在这里做错了什么? 我想获得可选的 new 和 const
最佳答案
flutter 版本
如果您有 Dart 独立应用程序,则无关紧要。 dart --version
打印相关信息。
您需要使用 --preview-dart-2
运行,直到 Dart 2 语义成为默认值。在 Flutter 中,这已经是默认设置。
dart --preview-dart-2 bin/main.dart
在 IntelliJ 中,您可以在“运行/调试配置”>“VM 选项”中传递此选项。
这也将很快成为独立 Dart 中的默认设置。
关于dart - Dart 2 中可选的 new 和 const,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50306197/