showLocalNotification static method
Presents a local notification. @param id The id of the notification. @param date The date when the notification will be presented. @param title The title of the notification. @param body The body of the notification. @param badge The badge of the notification. @param launchImage The launch image for the notification. @param sound A custom sound for the notification. @param media The path of a media that will be showed with the notification. @param mediaType The media type.
Implementation
static Future<bool> showLocalNotification({
required String id,
required DateTime date,
required String title,
required String body,
required int? badge,
required String? launchImage,
required String? sound,
required String? media,
required String? mediaType,
}) async {
MPAndroidNotificationsSettings? androidNotificationsSettings =
MBPush.androidPushNotificationsSettings;
if (Platform.isAndroid && androidNotificationsSettings == null) {
return false;
}
Map<String, dynamic> arguments = {
'id': id.hashCode,
'date': date.millisecondsSinceEpoch ~/ 1000,
'title': title,
'body': body,
'badge': badge,
'launchImage': launchImage,
'sound': sound,
'media': media,
'mediaType': mediaType,
'channelId': androidNotificationsSettings?.channelId,
'channelName': androidNotificationsSettings?.channelName,
'channelDescription': androidNotificationsSettings?.channelDescription,
'icon': androidNotificationsSettings?.icon,
};
if (androidNotificationsSettings != null) {
arguments.addAll(androidNotificationsSettings.toMethodChannelArguments());
}
dynamic result = await _channel.invokeMethod('showNotification', arguments);
bool booleanResult = result is bool ? result : false;
return booleanResult;
}