dart format
This commit is contained in:
@@ -13,20 +13,29 @@ class NotificationController {
|
||||
NotificationTasks.updateBadgeCount(message);
|
||||
}
|
||||
|
||||
static Future<void> onForegroundMessageHandler(RemoteMessage message, BuildContext context) async {
|
||||
static Future<void> onForegroundMessageHandler(
|
||||
RemoteMessage message,
|
||||
BuildContext context,
|
||||
) async {
|
||||
NotificationTasks.updateProviders(context);
|
||||
NotificationTasks.updateBadgeCount(message);
|
||||
}
|
||||
|
||||
static Future<void> onAppOpenedByNotification(RemoteMessage message, BuildContext context) async {
|
||||
NotificationTasks.navigateToTalk(context, chatToken: _extractChatToken(message));
|
||||
static Future<void> onAppOpenedByNotification(
|
||||
RemoteMessage message,
|
||||
BuildContext context,
|
||||
) async {
|
||||
NotificationTasks.navigateToTalk(
|
||||
context,
|
||||
chatToken: _extractChatToken(message),
|
||||
);
|
||||
NotificationTasks.updateProviders(context);
|
||||
|
||||
DebugTile(context).run(() {
|
||||
InfoDialog.show(
|
||||
context,
|
||||
'Dieser Bericht wird angezeigt, da du den Entwicklermodus aktiviert hast und die App über eine Benachrichtigung geöffnet wurde.\n\n'
|
||||
'${JsonViewer.format(message.data)}',
|
||||
'${JsonViewer.format(message.data)}',
|
||||
copyable: true,
|
||||
title: 'Notification report',
|
||||
);
|
||||
|
||||
@@ -7,16 +7,15 @@ class NotificationService {
|
||||
|
||||
NotificationService._internal();
|
||||
|
||||
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
|
||||
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
|
||||
FlutterLocalNotificationsPlugin();
|
||||
|
||||
Future<void> initializeNotifications() async {
|
||||
const androidSettings = AndroidInitializationSettings(
|
||||
'@mipmap/ic_launcher'
|
||||
);
|
||||
|
||||
final iosSettings = DarwinInitializationSettings(
|
||||
'@mipmap/ic_launcher',
|
||||
);
|
||||
|
||||
final iosSettings = DarwinInitializationSettings();
|
||||
|
||||
final initializationSettings = InitializationSettings(
|
||||
android: androidSettings,
|
||||
@@ -24,13 +23,16 @@ class NotificationService {
|
||||
);
|
||||
|
||||
await flutterLocalNotificationsPlugin.initialize(
|
||||
settings: initializationSettings
|
||||
settings: initializationSettings,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> showNotification({required String title, required String body, required int badgeCount}) async {
|
||||
const androidPlatformChannelSpecifics =
|
||||
AndroidNotificationDetails(
|
||||
Future<void> showNotification({
|
||||
required String title,
|
||||
required String body,
|
||||
required int badgeCount,
|
||||
}) async {
|
||||
const androidPlatformChannelSpecifics = AndroidNotificationDetails(
|
||||
'marmobile',
|
||||
'Marianum Fulda',
|
||||
importance: Importance.defaultImportance,
|
||||
@@ -42,14 +44,14 @@ class NotificationService {
|
||||
|
||||
const platformChannelSpecifics = NotificationDetails(
|
||||
android: androidPlatformChannelSpecifics,
|
||||
iOS: iosPlatformChannelSpecifics
|
||||
iOS: iosPlatformChannelSpecifics,
|
||||
);
|
||||
|
||||
await flutterLocalNotificationsPlugin.show(
|
||||
id: 0,
|
||||
title: title,
|
||||
body: body,
|
||||
notificationDetails: platformChannelSpecifics
|
||||
notificationDetails: platformChannelSpecifics,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,9 @@ import '../state/app/modules/chat_list/bloc/chat_list_bloc.dart';
|
||||
|
||||
class NotificationTasks {
|
||||
static void updateBadgeCount(RemoteMessage notification) {
|
||||
FlutterAppBadge.count(int.parse((notification.data['unreadCount'] as String?) ?? '0'));
|
||||
FlutterAppBadge.count(
|
||||
int.parse((notification.data['unreadCount'] as String?) ?? '0'),
|
||||
);
|
||||
}
|
||||
|
||||
static void updateProviders(BuildContext context) {
|
||||
|
||||
@@ -10,33 +10,42 @@ import '../state/app/modules/settings/bloc/settings_cubit.dart';
|
||||
import '../widget/confirm_dialog.dart';
|
||||
|
||||
class NotifyUpdater {
|
||||
static ConfirmDialog enableAfterDisclaimer(SettingsCubit settings) => ConfirmDialog(
|
||||
title: 'Warnung',
|
||||
icon: Icons.warning_amber,
|
||||
content: ''
|
||||
'Die Push-Benachrichtigungen werden durch mhsl.eu versendet.\n\n'
|
||||
'Durch das aktivieren dieser Funktion wird dein Nutzername, dein Password und eine Geräte-ID von mhsl dauerhaft gespeichert und verarbeitet.\n\n'
|
||||
'Für mehr Informationen drücke lange auf die Einstellungsoption!',
|
||||
confirmButton: 'Aktivieren',
|
||||
onConfirm: () {
|
||||
unawaited(FirebaseMessaging.instance.requestPermission(provisional: false));
|
||||
settings.val(write: true).notificationSettings.enabled = true;
|
||||
unawaited(NotifyUpdater.registerToServer());
|
||||
},
|
||||
static ConfirmDialog enableAfterDisclaimer(
|
||||
SettingsCubit settings,
|
||||
) => ConfirmDialog(
|
||||
title: 'Warnung',
|
||||
icon: Icons.warning_amber,
|
||||
content:
|
||||
''
|
||||
'Die Push-Benachrichtigungen werden durch mhsl.eu versendet.\n\n'
|
||||
'Durch das aktivieren dieser Funktion wird dein Nutzername, dein Password und eine Geräte-ID von mhsl dauerhaft gespeichert und verarbeitet.\n\n'
|
||||
'Für mehr Informationen drücke lange auf die Einstellungsoption!',
|
||||
confirmButton: 'Aktivieren',
|
||||
onConfirm: () {
|
||||
unawaited(
|
||||
FirebaseMessaging.instance.requestPermission(provisional: false),
|
||||
);
|
||||
settings.val(write: true).notificationSettings.enabled = true;
|
||||
unawaited(NotifyUpdater.registerToServer());
|
||||
},
|
||||
);
|
||||
|
||||
static Future<void> registerToServer() async {
|
||||
final fcmToken = await FirebaseMessaging.instance.getToken();
|
||||
if (fcmToken == null) {
|
||||
throw Exception('Failed to register push notification because there is no FBC token!');
|
||||
throw Exception(
|
||||
'Failed to register push notification because there is no FBC token!',
|
||||
);
|
||||
}
|
||||
|
||||
unawaited(NotifyRegister(
|
||||
NotifyRegisterParams(
|
||||
username: AccountData().getUsername(),
|
||||
password: AccountData().getPassword(),
|
||||
fcmToken: fcmToken,
|
||||
),
|
||||
).run());
|
||||
unawaited(
|
||||
NotifyRegister(
|
||||
NotifyRegisterParams(
|
||||
username: AccountData().getUsername(),
|
||||
password: AccountData().getPassword(),
|
||||
fcmToken: fcmToken,
|
||||
),
|
||||
).run(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user