0
0
Fluttermobile~10 mins

Push notifications (FCM) in Flutter - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to initialize Firebase in a Flutter app.

Flutter
void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.[1]();
  runApp(MyApp());
}
Drag options to blanks, or click blank then click option'
AstartApp
BinitializeApp
CinitFirebase
DsetupFirebase
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent method like startApp or setupFirebase.
2fill in blank
medium

Complete the code to request notification permissions on iOS.

Flutter
FirebaseMessaging messaging = FirebaseMessaging.instance;
NotificationSettings settings = await messaging.[1]();
Drag options to blanks, or click blank then click option'
AgetPermission
BaskPermission
CenablePermission
DrequestPermission
Attempts:
3 left
💡 Hint
Common Mistakes
Using methods that do not exist like askPermission or enablePermission.
3fill in blank
hard

Fix the error in the code to listen for foreground messages.

Flutter
FirebaseMessaging.onMessage.[1]((RemoteMessage message) {
  print('Message received: ${message.notification?.title}');
});
Drag options to blanks, or click blank then click option'
Asubscribe
BonData
Clisten
DaddListener
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like subscribe or addListener on the stream.
4fill in blank
hard

Fill both blanks to handle background messages correctly.

Flutter
Future<void> [1](RemoteMessage message) async {
  print('Handling a background message: ${message.messageId}');
}

FirebaseMessaging.[2]([1]);
Drag options to blanks, or click blank then click option'
AfirebaseMessagingBackgroundHandler
BonBackgroundMessage
ChandleBackgroundMessage
DsetBackgroundHandler
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong method names like setBackgroundHandler or handleBackgroundMessage.
5fill in blank
hard

Fill all three blanks to get the device token and print it.

Flutter
FirebaseMessaging messaging = FirebaseMessaging.instance;
String? [1] = await messaging.[2]();
print('Device token: ' + [3]!);
Drag options to blanks, or click blank then click option'
Atoken
BgetToken
DfetchToken
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong method names like fetchToken or mismatching variable names.