Reputation: 186
I am starting a project and decided to use the new version version of **Freezed** for my models, but when I run flutter *pub run build_runner build* to generate my code I get the following error:
>The parameter 'placeFormattedAddress' of 'Address' is non-nullbale but is neither required nor marked with @Default
>
I am importing the **Meta** package and also including the *@required* annotation; the funny thing is that when I change the parameters from named to positional (without the curly braces, it works well).
Here is the code ¿Could anybody please point me what is wrong?
**Here is the class**
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
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
Upvotes: 4
Views: 3899
Reputation: 186
I finally found the answer; with null-safe dart the @ is no longer needed to mark a required parameter; so instead of @required, now the syntax is only 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.
https://dart.dev/null-safety/faq
Upvotes: 9