flutter build runner 不工作 - getter 'uri' 被调用为 null
flutter build runner not working - The getter 'uri' was called on null
我在 build runner 中完美地使用了 flutter,但今天它只是得到了这个 null 错误。
甚至以为我恢复了我的代码更改,但仍然是同样的错误。
错误:
>[SEVERE] json_serializable:json_serializable on test/widget_test.dart:
>NoSuchMethodError: The getter 'uri' was called on null.
>Receiver: null
>Tried calling: uri
>[INFO] 3.3s elapsed, 1/17 actions completed.
>[INFO] 4.4s elapsed, 1/17 actions completed.
>[INFO] 5.4s elapsed, 1/17 actions completed.
>[INFO] 6.4s elapsed, 1/17 actions completed.
>[INFO] 7.5s elapsed, 1/17 actions completed.
>[INFO] 8.5s elapsed, 1/17 actions completed.
>[INFO] 9.6s elapsed, 1/17 actions completed.
>[INFO] 10.7s elapsed, 1/17 actions completed.
>[INFO] 11.8s elapsed, 1/17 actions completed.
>[INFO] 12.9s elapsed, 1/17 actions completed.
>[INFO] 14.0s elapsed, 1/17 actions completed.
>[INFO] 15.0s elapsed, 1/17 actions completed.
>[INFO] 16.1s elapsed, 1/17 actions completed.
>[INFO] 17.1s elapsed, 1/17 actions completed.
>[WARNING] No actions completed for 15.1s, waiting on:
> json_serializable:json_serializable on lib/common_widgets/alert_screens.dart
> json_serializable:json_serializable on lib/common_widgets/app_logo.dart
> json_serializable:json_serializable on lib/common_widgets/app_tab_bar.dart
> json_serializable:json_serializable on lib/common_widgets/buttons_widgets.dart
> json_serializable:json_serializable on lib/common_widgets/cards.dart
> .. and 11 more
> [INFO] 18.2s elapsed, 1/17 actions completed.
> [INFO] 19.3s elapsed, 1/17 actions completed.
它一直这样下去。
我正在使用:
sdk: ">=2.7.0 <3.0.0"
flutter: ^1.22.0
build_runner: ^1.10.0
json_serializable: ^3.5.0
analyzer: ^0.41.1
我要生成的模型:
import 'package:flutter/foundation.dart';
import 'package:json_annotation/json_annotation.dart';
part 'clinic.g.dart';
@JsonSerializable()
class Clinic {
final int establishmentYear;
final String workingHours;
final String phoneNumber;
final String location;
Clinic({
@required this.establishmentYear,
@required this.workingHours,
@required this.phoneNumber,
@required this.location,
});
factory Clinic.fromJson(Map<String, dynamic> json) => _$ClinicFromJson(json);
Map<String, dynamic> toJson() => _$ClinicToJson(this);
}
更新到最新的 flutter 版本解决了这个问题
根据 this issue 你必须清理你的项目,获取依赖项并最终升级你的包:
flutter clean
flutter pub get
flutter packages upgrade
我在 build runner 中完美地使用了 flutter,但今天它只是得到了这个 null 错误。 甚至以为我恢复了我的代码更改,但仍然是同样的错误。
错误:
>[SEVERE] json_serializable:json_serializable on test/widget_test.dart:
>NoSuchMethodError: The getter 'uri' was called on null.
>Receiver: null
>Tried calling: uri
>[INFO] 3.3s elapsed, 1/17 actions completed.
>[INFO] 4.4s elapsed, 1/17 actions completed.
>[INFO] 5.4s elapsed, 1/17 actions completed.
>[INFO] 6.4s elapsed, 1/17 actions completed.
>[INFO] 7.5s elapsed, 1/17 actions completed.
>[INFO] 8.5s elapsed, 1/17 actions completed.
>[INFO] 9.6s elapsed, 1/17 actions completed.
>[INFO] 10.7s elapsed, 1/17 actions completed.
>[INFO] 11.8s elapsed, 1/17 actions completed.
>[INFO] 12.9s elapsed, 1/17 actions completed.
>[INFO] 14.0s elapsed, 1/17 actions completed.
>[INFO] 15.0s elapsed, 1/17 actions completed.
>[INFO] 16.1s elapsed, 1/17 actions completed.
>[INFO] 17.1s elapsed, 1/17 actions completed.
>[WARNING] No actions completed for 15.1s, waiting on:
> json_serializable:json_serializable on lib/common_widgets/alert_screens.dart
> json_serializable:json_serializable on lib/common_widgets/app_logo.dart
> json_serializable:json_serializable on lib/common_widgets/app_tab_bar.dart
> json_serializable:json_serializable on lib/common_widgets/buttons_widgets.dart
> json_serializable:json_serializable on lib/common_widgets/cards.dart
> .. and 11 more
> [INFO] 18.2s elapsed, 1/17 actions completed.
> [INFO] 19.3s elapsed, 1/17 actions completed.
它一直这样下去。
我正在使用:
sdk: ">=2.7.0 <3.0.0"
flutter: ^1.22.0
build_runner: ^1.10.0
json_serializable: ^3.5.0
analyzer: ^0.41.1
我要生成的模型:
import 'package:flutter/foundation.dart';
import 'package:json_annotation/json_annotation.dart';
part 'clinic.g.dart';
@JsonSerializable()
class Clinic {
final int establishmentYear;
final String workingHours;
final String phoneNumber;
final String location;
Clinic({
@required this.establishmentYear,
@required this.workingHours,
@required this.phoneNumber,
@required this.location,
});
factory Clinic.fromJson(Map<String, dynamic> json) => _$ClinicFromJson(json);
Map<String, dynamic> toJson() => _$ClinicToJson(this);
}
更新到最新的 flutter 版本解决了这个问题
根据 this issue 你必须清理你的项目,获取依赖项并最终升级你的包:
flutter clean
flutter pub get
flutter packages upgrade