'How to add an empty Map into Firestore in flutter?
Is there a way to add an empty Map into firestore in the Update function?
This is my code for updating some values in the database. I want the users value to be an empty Map. It shouldn't contain any kind of empty child values in it like how I have in my code.
addEventDetails() async {
if (_eventNameTextEditingController.text.isNotEmpty &&
_eventDescTextEditingController.text.isNotEmpty &&
_eventLocationTextEditingController.text.isNotEmpty &&
_eventTicketPriceTextEditingController.text.isNotEmpty &&
formattedDate != null) {
documentReference.update({
"createdBy": orgUid,
"eventName": _eventNameTextEditingController.text,
"eventDesc": _eventDescTextEditingController.text,
"eventLoc": _eventLocationTextEditingController.text,
"ticketPrice": _eventTicketPriceTextEditingController.text,
"eventDate": formattedDate,
"addedDate": addedDate,
"eventId": documentReference.id,
"users.emptyValue": {},
});
await displayDialog("Event added successfully!");
clearValues();
// Navigator.push(
// context, MaterialPageRoute(builder: (context) => OrgHomePage()));
} else {
displayDialog("Please fill all the fields");
}
}
Solution 1:[1]
Fields without values are not stored in Firestore, and thus are not shown in the Firebase console.
A common practice is to store default values, for example empty strings, in those fields. An empty string is a value, so the field will be stored when you make its value an empty string, and thus it will show up in the console.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Frank van Puffelen |

