0
0
Fluttermobile~20 mins

Notifications (local) in Flutter - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Local Notifications Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
What happens when this Flutter local notification code runs?

Consider this Flutter code snippet that schedules a local notification:

await flutterLocalNotificationsPlugin.zonedSchedule(
  0,
  'Reminder',
  'Time to drink water!',
  tz.TZDateTime.now(tz.local).add(const Duration(seconds: 5)),
  const NotificationDetails(
    android: AndroidNotificationDetails('channelId', 'channelName'),
  ),
  androidAllowWhileIdle: true,
  uiLocalNotificationDateInterpretation: UILocalNotificationDateInterpretation.absoluteTime,
);

What will the user experience?

Flutter
await flutterLocalNotificationsPlugin.zonedSchedule(
  0,
  'Reminder',
  'Time to drink water!',
  tz.TZDateTime.now(tz.local).add(const Duration(seconds: 5)),
  const NotificationDetails(
    android: AndroidNotificationDetails('channelId', 'channelName'),
  ),
  androidAllowWhileIdle: true,
  uiLocalNotificationDateInterpretation: UILocalNotificationDateInterpretation.absoluteTime,
);
AA notification titled 'Reminder' with message 'Time to drink water!' appears after 5 seconds.
BThe notification appears immediately without delay.
CThe notification never appears because the scheduling method is incorrect.
DThe app crashes due to missing permission handling.
Attempts:
2 left
💡 Hint

Look at the add(const Duration(seconds: 5)) part in the scheduled time.

lifecycle
intermediate
2:00remaining
What happens if you schedule a local notification without initializing the plugin?

In Flutter, if you try to schedule a local notification without calling initialize() on FlutterLocalNotificationsPlugin, what will happen?

AThe app will throw an exception at runtime.
BThe notification will not appear but no error is thrown.
CThe notification will be scheduled and shown normally.
DThe app will crash immediately on startup.
Attempts:
2 left
💡 Hint

Think about what initialize() does for the plugin.

📝 Syntax
advanced
2:00remaining
Which option correctly requests notification permissions on iOS in Flutter?

Which code snippet correctly requests notification permissions on iOS using flutter_local_notifications?

Flutter
final bool result = await flutterLocalNotificationsPlugin
  .resolvePlatformSpecificImplementation<IOSFlutterLocalNotificationsPlugin>()
  ?.requestPermissions(alert: true, badge: true, sound: true) ?? false;
Aawait flutterLocalNotificationsPlugin.requestPermissions(alert: true, badge: true, sound: true);
Bawait flutterLocalNotificationsPlugin.requestIOSPermissions(alert: true, badge: true, sound: true);
Cawait flutterLocalNotificationsPlugin.initialize(requestPermissions: true);
Dawait flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation<IOSFlutterLocalNotificationsPlugin>()?.requestPermissions(alert: true, badge: true, sound: true) ?? false;
Attempts:
2 left
💡 Hint

Look for the platform-specific implementation method.

navigation
advanced
2:00remaining
What happens when a user taps a local notification with this setup?

Given this Flutter notification initialization code:

await flutterLocalNotificationsPlugin.initialize(
  InitializationSettings(
    android: AndroidInitializationSettings('@mipmap/ic_launcher'),
    iOS: IOSInitializationSettings(),
  ),
  onDidReceiveNotificationResponse: (NotificationResponse response) {
    Navigator.of(context).pushNamed('/details');
  },
);

What happens when the user taps the notification?

AThe app navigates to the '/details' screen.
BThe app crashes due to missing context.
CThe notification is dismissed but no navigation occurs.
DNothing happens because Navigator cannot be used here.
Attempts:
2 left
💡 Hint

Consider where context comes from in the callback.

🧠 Conceptual
expert
2:00remaining
Why is timezone setup important for scheduling local notifications in Flutter?

In Flutter local notifications, why must you configure timezone data (e.g., using timezone package) before scheduling notifications with zonedSchedule?

ATo enable notifications to show on Android only.
BTo reduce battery usage by the notification plugin.
CTo ensure notifications appear at the correct local time even if the device timezone changes.
DTo allow notifications to include images and sounds.
Attempts:
2 left
💡 Hint

Think about what happens if the device timezone changes after scheduling.