Open vladaman opened 3 years ago
@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 bool onBoardingCompleted = false;
field):
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 - defaultValue: null
, it should be defaultValue: false
:
/// 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.
@Field()
bool? onBoardingCompleted = false;
I'll suggest new solution in near future.
@dmba I'm consider new solution. Tentatively, please set nullable type like this.
@Field() bool? onBoardingCompleted = false;
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.