Reputation: 23
I use JSON serialization to upload documents to firestore.
I just updated my flutter project to nullsafety and now i get this error on any NULL field:
Error: [cloud_firestore/unknown] Expected a value of type 'Object', but got one of type 'Null'
My fields in class are nullabe:
String? field;
Is this a bug or am i doing something wrong? I was able to have null fields before this update. I use web build
Upvotes: 2
Views: 726
Reputation: 3156
The new Cloud Firestore library cannot store null values because of the new null safety feature. I would recommend you use a keyword, like an empty space or intricate piece of string as your custom null variable which should work Declare
String newNull = 'IntricateNull';
Pass to Firestore
'nullValue':newNull
Use it when receiving data
if (value != newNull){//To check value is not null
}
Its not a favorable solution but it is what it is. Null safety has its downsides and upsides.
Upvotes: 3