diff options
Diffstat (limited to 'lib/util/notifications.dart')
-rw-r--r-- | lib/util/notifications.dart | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/util/notifications.dart b/lib/util/notifications.dart new file mode 100644 index 0000000..91280da --- /dev/null +++ b/lib/util/notifications.dart @@ -0,0 +1,32 @@ +import 'package:open_file/open_file.dart'; +import 'package:flutter_local_notifications/flutter_local_notifications.dart'; + +/// Handles all the notification related things. +class Notifications { + static FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); + + /// Specifies the exact notification behavior on android. + static const AndroidNotificationDetails _androidSpecifics = AndroidNotificationDetails( + 'com.davidpenkowoj.kulinar', + 'Kulinar', + importance: Importance.defaultImportance, + priority: Priority.defaultPriority, + autoCancel: true, + playSound: false, + showWhen: false, + ); + + /// Is called when the notification is pressed. + static Future<dynamic> selectNotification(String? payload) async { + if (payload != null) { + OpenFile.open(payload, type: "*/*"); // TODO: FIXME: Still doesnt work (sometimes) + } + } + + /// Launches the notification + static Future<void> notify(String title, String description, String payload) async { + const NotificationDetails _platformChannelSpecifics = NotificationDetails(android: _androidSpecifics); + + await flutterLocalNotificationsPlugin.show(0, title, description, _platformChannelSpecifics, payload: payload); + } +} |