0
0
Fluttermobile~10 mins

Notifications (local) 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 the Flutter local notifications plugin.

Flutter
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await flutterLocalNotificationsPlugin.[1]();
  runApp(MyApp());
}
Drag options to blanks, or click blank then click option'
Ainitialize
Bstart
Csetup
Dlaunch
Attempts:
3 left
💡 Hint
Common Mistakes
Using start() or setup() which do not exist.
Forgetting to call initialize before using notifications.
2fill in blank
medium

Complete the code to show a simple notification with a title and body.

Flutter
await flutterLocalNotificationsPlugin.show(
  0,
  'Hello',
  'This is a notification',
  [1]
);
Drag options to blanks, or click blank then click option'
ANotificationSettings()
BNotificationConfig()
CNotificationDetails(android: AndroidNotificationDetails('channelId', 'channelName', importance: Importance.defaultImportance))
DNotificationOptions()
Attempts:
3 left
💡 Hint
Common Mistakes
Passing NotificationSettings or other incorrect classes.
Not providing NotificationDetails causes errors.
3fill in blank
hard

Fix the error in the AndroidNotificationDetails constructor by completing the missing required parameter.

Flutter
const AndroidNotificationDetails(
  'channelId',
  'channelName',
  [1]
)
Drag options to blanks, or click blank then click option'
Asound: RawResourceAndroidNotificationSound('sound')
Bpriority: Priority.high
Cicon: 'app_icon'
Dimportance: Importance.max
Attempts:
3 left
💡 Hint
Common Mistakes
Using priority instead of importance in AndroidNotificationDetails.
Omitting importance causes runtime errors.
4fill in blank
hard

Fill both blanks to create a notification channel with high importance and enable vibration.

Flutter
const AndroidNotificationDetails(
  'channelId',
  'channelName',
  importance: [1],
  vibrationPattern: [2]
)
Drag options to blanks, or click blank then click option'
AImportance.high
B[0, 1000, 500, 2000]
CImportance.low
D[100, 200, 300]
Attempts:
3 left
💡 Hint
Common Mistakes
Using Importance.low for high priority notifications.
Providing incorrect vibration pattern format.
5fill in blank
hard

Fill all three blanks to schedule a notification 5 seconds from now with a specific channel and title.

Flutter
await flutterLocalNotificationsPlugin.zonedSchedule(
  1,
  [1],
  'Scheduled Notification',
  tz.TZDateTime.now(tz.local).add(const Duration(seconds: [2])),
  NotificationDetails(
    android: AndroidNotificationDetails(
      [3],
      'Scheduled Channel',
      importance: Importance.high
    )
  ),
  androidAllowWhileIdle: true,
  uiLocalNotificationDateInterpretation: UILocalNotificationDateInterpretation.absoluteTime
);
Drag options to blanks, or click blank then click option'
A'Reminder'
B5
C'scheduled_channel_id'
D'Alert'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong channel id string.
Setting wrong delay duration.
Confusing title with channel name.