Complete the code to initialize Firebase in a Flutter app.
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.[1]();
runApp(MyApp());
}You must call Firebase.initializeApp() to set up Firebase before using its services.
Complete the code to request notification permissions on iOS.
FirebaseMessaging messaging = FirebaseMessaging.instance;
NotificationSettings settings = await messaging.[1]();The method requestPermission() asks the user for notification permissions on iOS devices.
Fix the error in the code to listen for foreground messages.
FirebaseMessaging.onMessage.[1]((RemoteMessage message) { print('Message received: ${message.notification?.title}'); });
The correct method to listen to the stream of messages is listen.
Fill both blanks to handle background messages correctly.
Future<void> [1](RemoteMessage message) async { print('Handling a background message: ${message.messageId}'); } FirebaseMessaging.[2]([1]);
The background handler function is named by you (here firebaseMessagingBackgroundHandler), and you register it with FirebaseMessaging.onBackgroundMessage().
Fill all three blanks to get the device token and print it.
FirebaseMessaging messaging = FirebaseMessaging.instance; String? [1] = await messaging.[2](); print('Device token: ' + [3]!);
You store the token in a variable (here token), get it by calling getToken(), and print the variable token.