dart - 尽管使用了 Dart 2.0,但不能省略 'new' 关键字
问题描述
当我运行我的应用程序的测试时,我得到了这个异常:
NoSuchMethodError: Attempted to use type 'SimplePipe' as a function. Since types do not define a method 'call', this is not possible. Did you intend to call the SimplePipe constructor and forget the 'new' operator?
我从这条错误消息中得出结论,我的项目实际上不是使用 Dart 2.0 而是使用 Dart 1.0。不过,sdk 设置为>=2.0.0-dev.53.0 <2.0.0
in pubspec.yaml
。
我的一个朋友在他的 PC 上在相同条件下运行相同测试时收到此错误消息。他已经试过跑步了pub get
。
Dart 2.0.0-dev.54.0.flutter-46ab040e58 is incompatible with your dependencies' SDK constraints. Please run "pub get" again
pubspec.yaml
:
name: timecoder_common
description: A Dart Libary containin all the shared logic
version: 0.0.1
environment:
sdk: '>=2.0.0-dev.53.0 <2.0.0'
dependencies:
uuid: "^0.5.3"
json_annotation: "^0.2.3"
http: "^0.11.3"
rxdart: "^0.16.6"
test: "^0.12.34"
dev_dependencies:
build_runner: "^0.8.0"
json_serializable: "^0.5.0"
解决方案
Dart 2.0 SDK 默认不启用此功能(目前)。
对于 Flutter,您需要使用最新的 SDK:
在这篇博文中,我们将深入了解我们在 Beta 3 本身中所做的具体改进。
对于命令行 VM,如评论中所述,您必须选择加入:
dart --preview-dart-2 bin/main.dart
推荐阅读
- javascript - 使用 SVG 图像边框制作交互式画布
- html - 如何使用 RVEST 抓取不同的 HTML 文件并将其存储到 Excel 文件表中?
- javascript - 如何通过 HTML Canvas 中的 for 循环绘制点?
- tensorflow - 如何通过将 keras 包装在估算器中来简单地在分布式配置中使用 keras
- shell - 将矩阵写入 shell 中的一列或使用 awk
- php - 一般问题:XAMPP 和 MySQL 数据库如何协同工作?
- debugging - 为什么 gdb 终端中的 Ctrl-c 不会向 gdb 进程发送 STOP 信号
- unity3d - 切换音频对象仅存在于一个场景中,但在所有场景中播放 从另一个场景开/关
- excel - 如何复制范围并粘贴唯一值升序
- angular - Angular 库:配置导出的成员