Google’s Cloud Firestore is a tool that should be in every mobile app developer’s tool belt. The flexible and scalable database that it provides is unlike anything a coder could create alone and if your app is designed for a global audience, there aren’t many solutions like it. Plus, there’s a Flutter package ( cloud_firestore) that’s designed to make Flutter and Flame play nicely together.
Unfortunately, there is one downside. The tool isn’t free to use and every read/write transaction your app makes with the Firestore database is counted against your daily quota (50,000 daily reads and 20,000 daily writes for the free tier plan). Therefore, it’s essential you design your database with these usage limits in mind…otherwise, your dreams of creating a profitable mobile app will be stamped out like a flame.
In this article, I’m going to discuss how you can use nested objects in your Firestore database to reduce the amount of transactions you’re making. Rather than retrieve data from one document and two different subcollections, you’ll be able to query a single document and handle the nested data on the client side. #MoneyMoves.
The simplest way to save nested data to a Firestore document is by using a map. After setting up Firestore in your Flutter app and creating a database, you can save nested map data like this:
void SaveNestedData() { Firestore.instance.collection("exercises").add(
{ "name": "Dumbbell curl",
"muscle": "Biceps",
"sets": {
"reps": 10,
"weight": 40}
});
}
#firestore #flutter #flutterdev