Reputation: 2091
Well this is very strange, I'm using removeWhere to remove all null values in a map but they get through! What the heck!
firebaseUploadMap.removeWhere((key, value) => value == null);
Here's a print off of the map after it's been run:
{languages: null, latitude: 55.9521138, longitude: -3.196447, houseNum: 1, street: Princes Street, city: Edinburgh, postcode: EH2 2EQ, country: GB, toolsInPossession: null, jobsPropositioned: null, jobsCompleted: null, jobTypesLiked: null, jobsShared: null, jobRatings: null, signUpDate: Timestamp(seconds=1586989986, nanoseconds=301779000)}
Lots of Null values still there. Is it something to do with variable type? languages is a List and my null remover is missing it. jobRatings is a boolean and null, can Dart not recognise these as Null?
I've tried copying the map, iterating over the keys in the original map and deleting them in the copy but the output matches that of Dart's .removeWhere.
How do I solve this?
Upvotes: 1
Views: 2965
Reputation: 2091
Ah OK. Sorry for your attention folks, @jamesdlin led me to the answer. In trying to provide a fully reproducible example, I discovered that when I turn my Person object to a map, for some reason I'd decided that all fields of the object should be made strings, so languages: String(value). So I turned null as in NULL, to "Null" type String. Hence I was unable to remove them.
I've rectified this, left the keys mapping to the original datatypes and removeWhere now fully works. I presume my Firebase database is going to automatically translate Dart Lists into their Array data type, so the lesson is: don't turn nullable fields to Strings, if you want to strip out Nullable entries.
Again sorry to have wasted folk's time, happy to have it solved.
Upvotes: 2