@@ -5,30 +5,68 @@ class ParseNotification {
5
5
static final ParseNotification instance = ParseNotification ._internal ();
6
6
static String keyNotificationChannelName = "parse" ;
7
7
8
+ final FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin =
9
+ FlutterLocalNotificationsPlugin ();
10
+
11
+ AndroidInitializationSettings ? _androidNotificationSettings;
12
+ DarwinInitializationSettings ? _iOSNotificationSettings;
13
+ DarwinInitializationSettings ? _macOSNotificationSettings;
14
+ LinuxInitializationSettings ? _linuxNotificationSettings;
15
+
8
16
factory ParseNotification () {
9
17
return instance;
10
18
}
11
19
12
20
ParseNotification ._internal () {
13
- // Initialize notifications helper package
14
- AwesomeNotifications ().initialize (
15
- null ,
16
- [
17
- NotificationChannel (
18
- channelKey: keyNotificationChannelName,
19
- channelName: keyNotificationChannelName,
20
- channelDescription: 'Notification channel for parse' )
21
- ],
21
+ _initialize ();
22
+ }
23
+
24
+ setNotificationSettings (
25
+ {AndroidInitializationSettings ? androidNotificationSettings,
26
+ DarwinInitializationSettings ? iOSNotificationSettings,
27
+ DarwinInitializationSettings ? macOSNotificationSettings,
28
+ LinuxInitializationSettings ? linuxNotificationSettings}) {
29
+ _androidNotificationSettings = androidNotificationSettings;
30
+ _iOSNotificationSettings = iOSNotificationSettings;
31
+ _macOSNotificationSettings = macOSNotificationSettings;
32
+ _linuxNotificationSettings = linuxNotificationSettings;
33
+ }
34
+
35
+ /// Initialize notification helper
36
+ Future <void > _initialize () async {
37
+ InitializationSettings initializationSettings = InitializationSettings (
38
+ android: _androidNotificationSettings ??
39
+ const AndroidInitializationSettings ('launch_background' ),
40
+ iOS: _iOSNotificationSettings,
41
+ linux: _linuxNotificationSettings,
42
+ macOS: _macOSNotificationSettings);
43
+
44
+ AndroidNotificationChannel channel = AndroidNotificationChannel (
45
+ keyNotificationChannelName, // id
46
+ keyNotificationChannelName, // title
47
+ importance: Importance .max,
22
48
);
49
+
50
+ await _flutterLocalNotificationsPlugin.initialize (initializationSettings);
51
+
52
+ await _flutterLocalNotificationsPlugin
53
+ .resolvePlatformSpecificImplementation<
54
+ AndroidFlutterLocalNotificationsPlugin > ()
55
+ ? .createNotificationChannel (channel);
23
56
}
24
57
25
58
/// Show notification
26
59
void showNotification (title) {
27
- AwesomeNotifications ().createNotification (
28
- content: NotificationContent (
29
- id: Random ().nextInt (1000 ),
30
- channelKey: keyNotificationChannelName,
31
- title: title,
32
- ));
60
+ _flutterLocalNotificationsPlugin.show (
61
+ Random ().nextInt (1000 ),
62
+ title,
63
+ null ,
64
+ NotificationDetails (
65
+ android: AndroidNotificationDetails (
66
+ keyNotificationChannelName,
67
+ keyNotificationChannelName,
68
+ // other properties...
69
+ ),
70
+ ));
33
71
}
34
72
}
0 commit comments