Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Firestore package in Flutter.
Flutter
import 'package:cloud_firestore/[1].dart';
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'firebase' instead of 'firestore' in the import path.
Trying to import 'firestore_flutter' which does not exist.
✗ Incorrect
The correct import for Firestore in Flutter is cloud_firestore/firestore.dart.
2fill in blank
mediumComplete the code to get a Firestore instance in Flutter.
Flutter
final FirebaseFirestore firestore = FirebaseFirestore.[1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'getInstance()' which is not defined in Flutter Firestore.
Trying to call 'initialize()' or 'create()' which do not exist.
✗ Incorrect
Use FirebaseFirestore.instance to get the Firestore instance.
3fill in blank
hardFix the error in the code to add a new document to the 'users' collection.
Flutter
await firestore.collection('users').[1]({'name': 'Alice', 'age': 25});
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'update' which requires an existing document.
Using 'set' without specifying a document ID.
Using 'insert' which is not a Firestore method.
✗ Incorrect
To add a new document with an auto-generated ID, use add().
4fill in blank
hardFill both blanks to update the 'age' field of a user document with ID 'user123'.
Flutter
await firestore.collection('users').doc([1]).[2]({'age': 30});
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'set' which overwrites the whole document.
Using wrong document ID like 'user456'.
✗ Incorrect
Use doc('user123') to select the document, then update() to change fields.
5fill in blank
hardFill all three blanks to delete a document with ID 'doc789' from the 'items' collection.
Flutter
await firestore.collection([1]).doc([2]).[3]();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'remove' which is not a Firestore method.
Using wrong collection or document IDs.
✗ Incorrect
Use collection('items'), then doc('doc789'), and finally delete() to remove the document.