Challenge - 5 Problems
Firebase Flutter Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
Firebase Authentication UI Behavior
What will happen when the following Flutter code tries to sign in a user with Firebase Authentication using an email and password that do not exist in Firebase?
Firebase
try { UserCredential userCredential = await FirebaseAuth.instance.signInWithEmailAndPassword( email: 'nonexistent@example.com', password: 'wrongpassword' ); print('Signed in: ${userCredential.user?.uid}'); } catch (e) { print('Error: $e'); }
Attempts:
2 left
💡 Hint
Think about what Firebase does when credentials are invalid.
✗ Incorrect
Firebase Authentication throws a FirebaseAuthException when the email or password is incorrect. The catch block prints the error message.
🧠 Conceptual
intermediate1:30remaining
Firebase Firestore Data Structure
In Firebase Firestore, which of the following best describes how data is organized?
Attempts:
2 left
💡 Hint
Think about how Firestore groups related data.
✗ Incorrect
Firestore organizes data in collections and documents. Documents can contain fields and nested collections, allowing flexible hierarchical data.
❓ lifecycle
advanced2:00remaining
Firebase StreamBuilder Lifecycle
Consider this Flutter widget using StreamBuilder to listen to Firestore changes. What happens if the widget is removed from the widget tree?
Firebase
StreamBuilder<QuerySnapshot>( stream: FirebaseFirestore.instance.collection('messages').snapshots(), builder: (context, snapshot) { if (!snapshot.hasData) return CircularProgressIndicator(); return ListView( children: snapshot.data!.docs.map((doc) => Text(doc['text'])).toList(), ); }, )
Attempts:
2 left
💡 Hint
Think about how StreamBuilder manages streams internally.
✗ Incorrect
StreamBuilder automatically cancels its stream subscription when the widget is disposed, preventing memory leaks.
advanced
2:00remaining
Firebase Auth State and Navigation
In a Flutter app using Firebase Authentication, which approach correctly navigates the user to the home screen only after successful login?
Firebase
FirebaseAuth.instance.authStateChanges().listen((User? user) {
if (user != null) {
Navigator.pushReplacementNamed(context, '/home');
} else {
Navigator.pushReplacementNamed(context, '/login');
}
});Attempts:
2 left
💡 Hint
Consider when and where you can safely use Navigator with context.
✗ Incorrect
Using Navigator inside a stream listener without checking widget lifecycle or context validity can cause errors. The context may be invalid if the widget is disposed.
🔧 Debug
expert2:30remaining
Debugging Firestore Query Results
Given this Firestore query in Flutter, why does the app always show an empty list even though the collection has documents?
Firebase
StreamBuilder<QuerySnapshot>( stream: FirebaseFirestore.instance.collection('tasks').where('done' == true).snapshots(), builder: (context, snapshot) { if (!snapshot.hasData) return CircularProgressIndicator(); return ListView( children: snapshot.data!.docs.map((doc) => Text(doc['title'])).toList(), ); }, )
Attempts:
2 left
💡 Hint
Look carefully at the syntax inside the where() method.
✗ Incorrect
The expression 'done' == true evaluates immediately to false, so the where clause becomes .where(false), which is invalid. The correct syntax is .where('done', isEqualTo: true).