Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize Firebase in a Flutter app.
Flutter
await Firebase.[1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using runApp instead of initializeApp
Calling startApp which does not exist
✗ Incorrect
Firebase apps start by calling initializeApp() to set up backend services.
2fill in blank
mediumComplete the code to add a document to Firestore database.
Flutter
FirebaseFirestore.instance.collection('users').[1]({'name': 'Anna'});
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using get which reads data
Using update which modifies existing data
✗ Incorrect
The add() method adds a new document to a Firestore collection.
3fill in blank
hardFix the error in the code to listen for authentication state changes.
Flutter
FirebaseAuth.instance.authStateChanges().[1]((User? user) { if (user == null) { print('User signed out'); } else { print('User signed in'); } });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using subscribe which is not a Dart Stream method
Using onChange which does not exist
✗ Incorrect
The listen() method subscribes to stream events like auth state changes.
4fill in blank
hardFill both blanks to create a map of user IDs to their email addresses from a list.
Flutter
var userMap = {user.[1]: user.[2] for user in users}; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using name or id which are not standard Firebase user properties
✗ Incorrect
Each user object has a unique ID as uid and an email as email.
5fill in blank
hardFill all three blanks to filter and map Firestore documents with age over 18.
Flutter
var adults = {doc.[1]: doc.data()[[2]] for doc in snapshot.docs if doc.data()[[3]] > 18}; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up field names or using data instead of id for keys
✗ Incorrect
Use id for document ID, 'name' for mapping, and filter by 'age' field.