0
0
Fluttermobile~20 mins

Push notifications (FCM) in Flutter - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
FCM Push Notifications Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
Handling Notification Tap Behavior
What happens when a user taps a push notification in a Flutter app configured with Firebase Cloud Messaging (FCM) using the following code snippet?
Flutter
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
  Navigator.pushNamed(context, '/details', arguments: message.data);
});
AThe app crashes due to missing context.
BThe app closes immediately without any navigation.
CThe app navigates to the '/details' screen passing the notification data as arguments.
DThe app shows a toast message but does not navigate.
Attempts:
2 left
💡 Hint
Think about what the listener for onMessageOpenedApp is designed to do.
🧠 Conceptual
intermediate
1:30remaining
FCM Token Usage
What is the main purpose of the FCM device token in a Flutter app using Firebase Cloud Messaging?
AIt stores the user's login credentials securely.
BIt uniquely identifies the device to send targeted push notifications.
CIt is used to style the notification appearance on the device.
DIt tracks the number of notifications received by the device.
Attempts:
2 left
💡 Hint
Think about how Firebase knows which device to send a notification to.
lifecycle
advanced
2:00remaining
App State and Notification Handling
Consider a Flutter app with FCM configured. Which callback handles messages received when the app is in the foreground?
AFirebaseMessaging.onBackgroundMessage
BFirebaseMessaging.getInitialMessage
CFirebaseMessaging.onMessageOpenedApp
DFirebaseMessaging.onMessage
Attempts:
2 left
💡 Hint
Foreground means the app is open and visible to the user.
🔧 Debug
advanced
2:30remaining
Debugging Missing Notifications
A Flutter app with FCM does not receive notifications when the app is killed (not running). What is a likely cause?
AThe onBackgroundMessage handler is not registered or missing.
BThe Firebase project is not linked to the app.
CThe app does not have internet permission in AndroidManifest.xml.
DThe notification payload is missing the title field.
Attempts:
2 left
💡 Hint
Background messages require a special handler to be registered.
📝 Syntax
expert
3:00remaining
Correct Syntax for Background Message Handler
Which of the following is the correct way to define and register a background message handler in Flutter with FCM?
Flutter
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
  // Handle background message
}

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
  runApp(MyApp());
}
A
Future&lt;void&gt; _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
  // Handle background message
}

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
  runApp(MyApp());
}
B
void _firebaseMessagingBackgroundHandler(RemoteMessage message) {
  // Handle background message
}

void main() {
  FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
  runApp(MyApp());
}
C
Future&lt;void&gt; _firebaseMessagingBackgroundHandler() async {
  // Handle background message
}

void main() {
  FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
  runApp(MyApp());
}
D
Future&lt;void&gt; _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
  // Handle background message
}

void main() {
  runApp(MyApp());
  FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
}
Attempts:
2 left
💡 Hint
The handler must be async, accept RemoteMessage, and be registered before runApp.