[英]Freezed package flutter throwing non-nullable error in code generation
import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:flutter/foundation.dart'; part 'address.freezed.dart'; part 'address.g.dart'; @freezed class Address with _$Address { const factory Address({ @required String placeFormattedAddress, @required String placeName, @required String placeId,@required double latitude, @required double longitude,}) = _Address; factory Address.fromJson(Map<String, dynamic> json) =>_$AddressFromJson(json);}
Here is my pubspec.yaml这是我的 pubspec.yaml
publish_to: 'none' version: 1.0.0+1 environment: sdk: ">=2.12.0 <3.0.0" dependencies: flutter: sdk: flutter freezed_annotation: ^0.14.1 json_serializable: ^4.1.0 flutter_hooks: ^0.16.0 hooks_riverpod: ^0.13.1 dev_dependencies: flutter_test: sdk: flutter lint: ^1.0.0 build_runner: freezed: ^0.14.1+2
I finally found the answer;我终于找到了答案; with null-safe dart the @ is no longer needed to mark a required parameter;
使用 null-safe dart 不再需要 @ 来标记必需的参数; so instead of @required , now the syntax is only required
所以现在只需要语法而不是@required
When null safe code is called from legacy code the required keyword is treated exactly like the @required annotation: failure to supply the argument will cause an analyzer hint.
当从遗留代码调用 null 安全代码时,所需关键字的处理方式与 @required 注释完全相同:未能提供参数将导致分析器提示。
https://dart.dev/null-safety/faq https://dart.dev/null-safety/faq
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.