我正在尝试新的 dart 3功能,但我的应用程序不会编译。
packages/charts_repository/lib/src/models/peak_mean.dart:35:14: Error: Expected ')' before this.
if (json case {'DataSavedTime': final date, 'Value': final value}) {
^^^^
packages/charts_repository/lib/src/models/peak_mean.dart:36:38: Error: Undefined name 'date'.
return PeakMean(DateTime.parse(date), num.parse(value));
^^^^
packages/charts_repository/lib/src/models/peak_mean.dart:36:55: Error: Undefined name 'value'.
return PeakMean(DateTime.parse(date), num.parse(value));
^^^^^
packages/charts_repository/lib/src/models/peak_mean.dart:35:9: Error: A value of type 'Map<String, dynamic>' can't be assigned to a variable of type 'bool'.
- 'Map' is from 'dart:core'.
if (json case {'DataSavedTime': final date, 'Value': final value}) {
这里是新的 dart 3功能造成的错误
class PeakMean {
final DateTime x;
final num y;
PeakMean(this.x, this.y);
factory PeakMean.fromJson(Map<String, dynamic> json) {
if (json case {'DataSavedTime': final date, 'Value': final value}) {
return PeakMean(DateTime.parse(date), num.parse(value));
}
throw const FormatException('Unexpected JSON format');
}
}
flutter doctor -v
的输出
• Flutter version 3.10.4 on channel stable at C:\Users\itsroom\Development\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 682aa387cf (3 days ago), 2023-06-05 18:04:56 -0500
• Engine revision 2a3401c9bb
• Dart version 3.0.3
• DevTools version 2.23.1
pubspec.yaml
environment:
sdk: ">=3.0.0 <4.0.0"
1条答案
按热度按时间mspsb9vt1#
flutter pub upgrade
命令为我解决了这个问题。尝试升级您的软件包以及flutter clean。