@@ -2,71 +2,12 @@ part of flutter_parse_sdk_flutter;
2
2
3
3
/// A class that provides a mechanism for showing system notifications in the app.
4
4
class ParseNotification {
5
- static final ParseNotification instance = ParseNotification ._internal ();
6
- static String keyNotificationChannelName = "parse" ;
5
+ ParseNotification ({required this .onShowNotification});
7
6
8
- final FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin =
9
- FlutterLocalNotificationsPlugin ();
10
-
11
- AndroidInitializationSettings ? _androidNotificationSettings;
12
- DarwinInitializationSettings ? _iOSNotificationSettings;
13
- DarwinInitializationSettings ? _macOSNotificationSettings;
14
- LinuxInitializationSettings ? _linuxNotificationSettings;
15
-
16
- factory ParseNotification () {
17
- return instance;
18
- }
19
-
20
- ParseNotification ._internal () {
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,
48
- );
49
-
50
- await _flutterLocalNotificationsPlugin.initialize (initializationSettings);
51
-
52
- await _flutterLocalNotificationsPlugin
53
- .resolvePlatformSpecificImplementation<
54
- AndroidFlutterLocalNotificationsPlugin > ()
55
- ? .createNotificationChannel (channel);
56
- }
7
+ final void Function (String value) onShowNotification;
57
8
58
9
/// Show notification
59
10
void showNotification (title) {
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
- ));
11
+ onShowNotification.call (title);
71
12
}
72
13
}
0 commit comments