flutter在生成g.dart文件时报错
[SEVERE] Failed to snapshot build script .dart_tool/build/entrypoint/build.dart.
This is likely caused by a misconfigured builder definition.
[SEVERE] .dart_tool/build/entrypoint/build.dart:23:3: Warning:
Operand of null-aware operation '?.' has type 'SendPort' which
excludes null. - 'SendPort' is from 'dart:isolate'.
sendPort?.send(result); ^Error: Cannot run with sound null
safety, because the following dependenciesdon't support null
safety: - package:build_runner_core - package:json_serializable - package:source_gen - package:build_config - package:build_runner - package:build - package:json_annotation
- package:glob - package:crypto - package:logging - package:watcher - package:build_resolvers - package:timing -
- package:graphs - package:package_config - package:yaml - package:analyzer - package:dart_style - package:checked_yaml -
- package:pubspec_parse - package:build_daemon - package:args -
- package:io - package:convert - package:pub_semver - package:_fe_analyzer_shared - package:http_multi_server -
- package:shelf - package:stream_transform - package:http_parser - package:mime - package:shelf_web_socket -
- package:web_socket_channel - package:cli_utilFor solutions,
- see https://dart.dev/go/unsound-null-
- safety.dart_tool/build/entrypoint/build.dart:21:44: Error: The
- parameter 'sendPort' can't have a value of 'null' because of its type 'SendPort', but the implicit default value is 'null'.
- - 'SendPort' is from 'dart:isolate'.Try adding either an explicit non-'null' default value or the 'required'
- modifier.void main(List<String> args, [_i5.SendPort
- sendPort]) async {
报这个错可能是版本的问题。
sdk: ">=2.12.0 <3.0.0" 改为 sdk: ">=2.8.0 <3.0.0"
相关依赖
dev_dependencies:
cupertino_icons: ^1.0.2
json_annotation: ^3.1.1
build_runner: ^1.1.3
json_serializable: ^3.5.1
改完之后更新下flutter
flutter packages upgrade
最后执行
flutter packages pub run build_runner build
本文来自博客园,作者:zhooke,转载请注明原文链接:https://www.cnblogs.com/zhooke/p/15399357.html