dart - Dart 2 中可选的 new 和 const

标签 dart

我使用 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 中的默认设置。

enter image description here

关于dart - Dart 2 中可选的 new 和 const,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50306197/

相关文章:

flutter - 为什么我的切换按钮有问题

dart - AngularDart的角度组件的应用布局

dart - Paper-textarea在AngularDart组件中为只读

layout - 如何正确设置 ListView 的高度

flutter - 如何在 flutter 朔迷离中实现17主机与agora io?

android - 任务 ':app:processDebugResources' 的 Flutter 执行失败。 AAPT : error: resource string/app_name not found

flutter - 在Google map 上重新热加载之前,标记不会显示

bash - 安装 Flutter 后从 Mac OS 终端运行 Dart 程序

flutter - CERTIFICATE_VERIFY_FAILED 虽然它应该是有效的?

generics - Dart:通用方法不起作用