-
-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Support for Fields which cannot be null #34
Comments
@vladaman Please show me your source code. |
@hukusuke1007 I am facing similar issue, it would be nice if the package would be able to support something like this (please pay attention on class ProfileModel extends Document<ProfileModel> {
ProfileModel({
String? id,
DocumentSnapshot<Json>? snap,
Json? values,
}) : super(
id: id,
snapshot: snap,
values: values,
collectionPath: 'profile',
);
@Field()
bool onBoardingCompleted = false;
@Field()
String? firstName;
@Field()
String? lastName;
@override
Json toData() => _$toData(this);
@override
void fromData(Json data) => _$fromData(this, data);
} Right not it generates code that cannot be compiled - /// For load data
void _$fromData(ProfileModel doc, Map<String, dynamic> data) {
doc.onBoardingCompleted = Helper.valueFromKey<bool>(
data, 'onBoardingCompleted',
defaultValue: null);
doc.firstName =
Helper.valueFromKey<String?>(data, 'firstName', defaultValue: null);
doc.lastName =
Helper.valueFromKey<String?>(data, 'lastName', defaultValue: null);
} |
@dmba I'm consider new solution. Tentatively, please set nullable type like this.
I'll suggest new solution in near future. |
Unfortunately this may work "technically" but IDE tooling suggests you have not handled null condition on these fields. IDE is not aware that this may not hold null value. |
We have following field which has no value in Firestore. If we fetch this model we get an error. We do not want to add
bool?
since we take this value as default if it's not present.The text was updated successfully, but these errors were encountered: