0
0
Fluttermobile~20 mins

Cloud Firestore CRUD in Flutter - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Firestore CRUD Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
Firestore Document Creation Behavior
What will be the result on Firestore after running this Flutter code snippet to add a new document?
Flutter
FirebaseFirestore.instance.collection('users').add({'name': 'Alice', 'age': 30});
AThe document with ID 'users' is overwritten with the new data.
BA new document with an auto-generated ID is created in the 'users' collection with fields 'name' and 'age'.
CAn error occurs because the document ID is missing.
DNo document is created because 'add' only updates existing documents.
Attempts:
2 left
💡 Hint
Remember that 'add' creates a new document with a random ID.
📝 Syntax
intermediate
1:30remaining
Correct Firestore Document Update Syntax
Which option correctly updates the 'age' field of a Firestore document with ID 'user123' in the 'users' collection?
Flutter
FirebaseFirestore.instance.collection('users').doc('user123').???({'age': 31});
Aupdate
Bset
Cadd
Dcreate
Attempts:
2 left
💡 Hint
Use the method that modifies existing fields without overwriting the whole document.
lifecycle
advanced
2:00remaining
Firestore Stream Listener Behavior
What happens in the Flutter app when using this Firestore stream to listen to 'users' collection changes?
Flutter
FirebaseFirestore.instance.collection('users').snapshots().listen((snapshot) {
  print('Documents count: ${snapshot.docs.length}');
});
AThe listener prints the document count only once when the app starts.
BThe listener prints the document count only when a new document is added, not when updated or deleted.
CThe listener causes an error because snapshots() returns a Future, not a Stream.
DThe listener prints the current number of documents every time the 'users' collection changes in Firestore.
Attempts:
2 left
💡 Hint
Streams update on any change in the collection including add, update, or delete.
🔧 Debug
advanced
2:00remaining
Fix Firestore Document Deletion Error
This Flutter code tries to delete a Firestore document but will not work as expected. What is the cause?
Flutter
FirebaseFirestore.instance.collection('users').doc().delete();
AThe doc() method is called without an ID, so it targets a non-existing document.
BThe delete() method requires a callback function to confirm deletion.
CThe collection name 'users' is invalid and causes the error.
DThe code is correct and should not cause any error.
Attempts:
2 left
💡 Hint
Deleting requires specifying the exact document ID.
🧠 Conceptual
expert
2:30remaining
Firestore Offline Persistence Behavior
Which statement best describes Firestore offline persistence in a Flutter app?
AFirestore does not support offline data; all reads and writes require internet connection.
BFirestore requires manual syncing of data after reconnecting to the internet.
CFirestore caches data locally and syncs changes automatically when the device reconnects to the internet.
DFirestore deletes local data cache every time the app restarts.
Attempts:
2 left
💡 Hint
Think about how apps work when you lose internet but still see data.