0
0
Firebasecloud~20 mins

Firebase with Flutter - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Firebase Flutter Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2: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');
}
AThe app prints the user ID of the signed-in user.
BThe app crashes with a null pointer exception.
CThe app prints an error message indicating wrong credentials.
DThe app signs in anonymously instead.
Attempts:
2 left
💡 Hint
Think about what Firebase does when credentials are invalid.
🧠 Conceptual
intermediate
1:30remaining
Firebase Firestore Data Structure
In Firebase Firestore, which of the following best describes how data is organized?
AData is stored in collections containing documents, which can have nested collections.
BData is stored only as key-value pairs without any hierarchy.
CData is stored as plain text files on the server.
DData is stored in tables with rows and columns like SQL databases.
Attempts:
2 left
💡 Hint
Think about how Firestore groups related data.
lifecycle
advanced
2: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(),
    );
  },
)
AThe app crashes because the stream is not closed manually.
BThe stream subscription is automatically cancelled to avoid memory leaks.
CThe stream keeps running and causes a memory leak.
DThe stream pauses but does not cancel, so updates are delayed.
Attempts:
2 left
💡 Hint
Think about how StreamBuilder manages streams internally.
navigation
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');
  }
});
AThis code works correctly and navigates based on auth state changes.
BThis code does not navigate because authStateChanges() never emits events.
CThis code causes infinite navigation loops because it listens continuously.
DThis code causes navigation errors because context is not valid inside the listener.
Attempts:
2 left
💡 Hint
Consider when and where you can safely use Navigator with context.
🔧 Debug
expert
2: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(),
    );
  },
)
AThe where clause is incorrect; 'done' == true is a boolean expression, not a field filter.
BThe collection 'tasks' does not exist in Firestore.
CThe StreamBuilder is missing a required key parameter.
DThe snapshot data is null because the app lacks Firestore read permissions.
Attempts:
2 left
💡 Hint
Look carefully at the syntax inside the where() method.