show method
Future<void>
show({
- required int id,
- String? title,
- String? body,
- NotificationDetails? notificationDetails,
- String? payload,
Show a notification with an optional payload that will be passed back to the app when a notification is tapped.
Implementation
Future<void> show({
required int id,
String? title,
String? body,
NotificationDetails? notificationDetails,
String? payload,
}) async {
if (kIsWeb) {
await resolvePlatformSpecificImplementation<
WebFlutterLocalNotificationsPlugin
>()
?.show(
id: id,
title: title,
body: body,
payload: payload,
notificationDetails: notificationDetails?.web,
);
return;
}
if (defaultTargetPlatform == TargetPlatform.android) {
await resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin
>()
?.show(
id: id,
title: title,
body: body,
notificationDetails: notificationDetails?.android,
payload: payload,
);
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
await resolvePlatformSpecificImplementation<
IOSFlutterLocalNotificationsPlugin
>()
?.show(
id: id,
title: title,
body: body,
notificationDetails: notificationDetails?.iOS,
payload: payload,
);
} else if (defaultTargetPlatform == TargetPlatform.macOS) {
await resolvePlatformSpecificImplementation<
MacOSFlutterLocalNotificationsPlugin
>()
?.show(
id: id,
title: title,
body: body,
notificationDetails: notificationDetails?.macOS,
payload: payload,
);
} else if (defaultTargetPlatform == TargetPlatform.linux) {
await resolvePlatformSpecificImplementation<
LinuxFlutterLocalNotificationsPlugin
>()
?.show(
id: id,
title: title,
body: body,
notificationDetails: notificationDetails?.linux,
payload: payload,
);
} else if (defaultTargetPlatform == TargetPlatform.windows) {
await resolvePlatformSpecificImplementation<
FlutterLocalNotificationsWindows
>()
?.show(
id: id,
title: title,
body: body,
notificationDetails: notificationDetails?.windows,
payload: payload,
);
} else {
await FlutterLocalNotificationsPlatform.instance.show(
id: id,
title: title,
body: body,
payload: payload,
);
}
}