43 lines
1.4 KiB
Dart
43 lines
1.4 KiB
Dart
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
|
|
|
class MyNotification {
|
|
static Future initialize(
|
|
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin) async {
|
|
var androidInitialize =
|
|
const AndroidInitializationSettings('mipmap/ic_launcher');
|
|
var iOSInitialize = const DarwinInitializationSettings();
|
|
var initializeSettings =
|
|
InitializationSettings(android: androidInitialize, iOS: iOSInitialize);
|
|
await flutterLocalNotificationsPlugin.initialize(initializeSettings);
|
|
}
|
|
|
|
Future showNotification(
|
|
{var id = 0,
|
|
var title,
|
|
var body,
|
|
var payload,
|
|
required FlutterLocalNotificationsPlugin
|
|
flutterLocalNotificationsPlugin}) async {
|
|
AndroidNotificationDetails androidPlatformChannelSpecifics =
|
|
const AndroidNotificationDetails(
|
|
'07eff3c8-e3d7-4386-b8a1-e6588cd9fbb5', // channelId
|
|
'channel_name',
|
|
sound: RawResourceAndroidNotificationSound('notification_fuck'),
|
|
importance: Importance.max,
|
|
priority: Priority.high,
|
|
);
|
|
|
|
var iOSPlatformChannelSpecifics = const DarwinNotificationDetails();
|
|
var platformChannelSpecifics = NotificationDetails(
|
|
android: androidPlatformChannelSpecifics,
|
|
iOS: iOSPlatformChannelSpecifics);
|
|
await flutterLocalNotificationsPlugin.show(
|
|
id,
|
|
title,
|
|
body,
|
|
platformChannelSpecifics,
|
|
payload: payload,
|
|
);
|
|
}
|
|
}
|