Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize Firebase in a Flutter app.
Firebase
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase[1]();
runApp(MyApp());
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like startApp or setupFirebase.
Forgetting to call ensureInitialized before initializing Firebase.
✗ Incorrect
The correct method to initialize Firebase in Flutter is initializeApp().
2fill in blank
mediumComplete the code to get an instance of Firestore in Flutter.
Firebase
final FirebaseFirestore firestore = FirebaseFirestore.[1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to call getInstance() which does not exist in Flutter Firestore.
Using incorrect method names like getFirestore.
✗ Incorrect
The correct way to get Firestore instance is using the instance getter.
3fill in blank
hardFix the error in the code to add a document to Firestore collection.
Firebase
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 non-existent methods like addDocument or insert.
Confusing with create which is not a Firestore method.
✗ Incorrect
The correct method to add a document to a collection is add().
4fill in blank
hardFill both blanks to read a document from Firestore and print its data.
Firebase
DocumentSnapshot snapshot = await firestore.collection('users').[1]('user123').[2](); print(snapshot.data());
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'document' instead of 'doc' which is deprecated.
Using 'fetch' which is not a Firestore method.
✗ Incorrect
Use doc() to specify the document and get() to fetch it.
5fill in blank
hardFill all three blanks to update a Firestore document with new data.
Firebase
await firestore.collection('users').[1]('user123').[2]([3]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'set' instead of 'update' which overwrites the whole document.
Passing data as a string instead of a map.
✗ Incorrect
Use doc() to select the document, update() to modify it, and pass the new data as a map.