|
@@ -1,53 +1,56 @@
|
|
|
-// import 'dart:io';
|
|
|
-//
|
|
|
-// import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
|
|
-//
|
|
|
-// class NotificationService {
|
|
|
-// static final NotificationService instance =
|
|
|
-// NotificationService._privateConstructor();
|
|
|
-//
|
|
|
-// NotificationService._privateConstructor();
|
|
|
-// final FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin =
|
|
|
-// FlutterLocalNotificationsPlugin();
|
|
|
-//
|
|
|
-// Future<void> init() async {
|
|
|
-// if (!Platform.isAndroid) {
|
|
|
-// return;
|
|
|
-// }
|
|
|
-// const AndroidInitializationSettings initializationSettingsAndroid =
|
|
|
-// AndroidInitializationSettings('notification_icon');
|
|
|
-// const InitializationSettings initializationSettings =
|
|
|
-// InitializationSettings(
|
|
|
-// android: initializationSettingsAndroid,
|
|
|
-// );
|
|
|
-// await _flutterLocalNotificationsPlugin.initialize(
|
|
|
-// initializationSettings,
|
|
|
-// onSelectNotification: selectNotification,
|
|
|
-// );
|
|
|
-// }
|
|
|
-//
|
|
|
-// Future selectNotification(String? payload) async {}
|
|
|
-//
|
|
|
-// Future<void> showNotification(String title, String message) async {
|
|
|
-// if (!Platform.isAndroid) {
|
|
|
-// return;
|
|
|
-// }
|
|
|
-// const AndroidNotificationDetails androidPlatformChannelSpecifics =
|
|
|
-// AndroidNotificationDetails(
|
|
|
-// 'io.ente.photos',
|
|
|
-// 'ente',
|
|
|
-// channelDescription: 'ente alerts',
|
|
|
-// importance: Importance.max,
|
|
|
-// priority: Priority.high,
|
|
|
-// showWhen: false,
|
|
|
-// );
|
|
|
-// const NotificationDetails platformChannelSpecifics =
|
|
|
-// NotificationDetails(android: androidPlatformChannelSpecifics);
|
|
|
-// await _flutterLocalNotificationsPlugin.show(
|
|
|
-// 0,
|
|
|
-// title,
|
|
|
-// message,
|
|
|
-// platformChannelSpecifics,
|
|
|
-// );
|
|
|
-// }
|
|
|
-// }
|
|
|
+import 'dart:io';
|
|
|
+
|
|
|
+import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
|
|
+
|
|
|
+class NotificationService {
|
|
|
+ static final NotificationService instance =
|
|
|
+ NotificationService._privateConstructor();
|
|
|
+
|
|
|
+ NotificationService._privateConstructor();
|
|
|
+ final FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin =
|
|
|
+ FlutterLocalNotificationsPlugin();
|
|
|
+
|
|
|
+ Future<void> init() async {
|
|
|
+ if (!Platform.isAndroid) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const AndroidInitializationSettings initializationSettingsAndroid =
|
|
|
+ AndroidInitializationSettings('notification_icon');
|
|
|
+ const InitializationSettings initializationSettings =
|
|
|
+ InitializationSettings(
|
|
|
+ android: initializationSettingsAndroid,
|
|
|
+ );
|
|
|
+ await _flutterLocalNotificationsPlugin.initialize(
|
|
|
+ initializationSettings,
|
|
|
+ );
|
|
|
+ final implementation =
|
|
|
+ _flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation<
|
|
|
+ AndroidFlutterLocalNotificationsPlugin>();
|
|
|
+ if (implementation != null) {
|
|
|
+ implementation.requestPermission();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Future<void> showNotification(String title, String message) async {
|
|
|
+ if (!Platform.isAndroid) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const AndroidNotificationDetails androidPlatformChannelSpecifics =
|
|
|
+ AndroidNotificationDetails(
|
|
|
+ 'io.ente.auth',
|
|
|
+ 'auth',
|
|
|
+ channelDescription: 'auth alerts',
|
|
|
+ importance: Importance.max,
|
|
|
+ priority: Priority.high,
|
|
|
+ showWhen: false,
|
|
|
+ );
|
|
|
+ const NotificationDetails platformChannelSpecifics =
|
|
|
+ NotificationDetails(android: androidPlatformChannelSpecifics);
|
|
|
+ await _flutterLocalNotificationsPlugin.show(
|
|
|
+ 0,
|
|
|
+ title,
|
|
|
+ message,
|
|
|
+ platformChannelSpecifics,
|
|
|
+ );
|
|
|
+ }
|
|
|
+}
|