34 lines
1.3 KiB
Dart
34 lines
1.3 KiB
Dart
import 'package:aitrainer_app/service/logging.dart';
|
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
|
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
|
|
|
class PushNotificationsManager with Logging {
|
|
PushNotificationsManager._();
|
|
|
|
factory PushNotificationsManager() => _instance;
|
|
|
|
static final PushNotificationsManager _instance = PushNotificationsManager._();
|
|
|
|
Future<void> init() async {
|
|
const AndroidNotificationChannel channel = AndroidNotificationChannel(
|
|
'high_importance_channel', // id
|
|
'High Importance Notifications', // title
|
|
'This channel is used for important notifications.', // description
|
|
importance: Importance.max,
|
|
);
|
|
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
|
|
|
|
await flutterLocalNotificationsPlugin
|
|
.resolvePlatformSpecificImplementation<AndroidFlutterLocalNotificationsPlugin>()
|
|
?.createNotificationChannel(channel);
|
|
|
|
await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(
|
|
alert: true, // Required to display a heads up notification
|
|
badge: true,
|
|
sound: true,
|
|
);
|
|
String? token = await FirebaseMessaging.instance.getToken();
|
|
print("FirebaseMessaging tokne $token");
|
|
}
|
|
}
|