WIP
This commit is contained in:
parent
e557601a90
commit
e903683f07
|
@ -56,14 +56,14 @@
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
<intent-filter android:autoVerify="true">
|
<intent-filter android:autoVerify="true">
|
||||||
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
|
<action android:name="mensagem" />
|
||||||
<action android:name="android.intent.action.VIEW" />
|
<action android:name="android.intent.action.VIEW" />
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
<category android:name="android.intent.category.BROWSABLE" />
|
<category android:name="android.intent.category.BROWSABLE" />
|
||||||
<data android:scheme="frehub" android:host="frehub.com" />
|
<data android:scheme="frehub" android:host="frehub.com" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
|
<action android:name="mensagem" />
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
|
|
|
@ -14,55 +14,8 @@ import 'package:hub/flutter_flow/flutter_flow_widgets.dart';
|
||||||
import 'package:hub/flutter_flow/nav/nav.dart';
|
import 'package:hub/flutter_flow/nav/nav.dart';
|
||||||
import 'package:hub/shared/utils/dialog_util.dart';
|
import 'package:hub/shared/utils/dialog_util.dart';
|
||||||
|
|
||||||
class NotificationService {
|
Future<void> onMessageReceived(
|
||||||
static Future<void> initialize() async {
|
Map<String, dynamic> payload, String? extra, String? handleClick) async {
|
||||||
await AwesomeNotifications().initialize(
|
|
||||||
'resource://drawable/notification_icon',
|
|
||||||
[
|
|
||||||
NotificationChannel(
|
|
||||||
channelKey: 'basic_channel',
|
|
||||||
channelGroupKey: 'basic_channel',
|
|
||||||
channelName: 'Notificações do App',
|
|
||||||
channelDescription: 'Canal de notificação do Aplicativo',
|
|
||||||
importance: NotificationImportance.Max,
|
|
||||||
channelShowBadge: false,
|
|
||||||
playSound: true,
|
|
||||||
criticalAlerts: true,
|
|
||||||
onlyAlertOnce: true,
|
|
||||||
defaultColor: Colors.green,
|
|
||||||
ledColor: Colors.white,
|
|
||||||
)
|
|
||||||
],
|
|
||||||
channelGroups: [
|
|
||||||
NotificationChannelGroup(
|
|
||||||
channelGroupKey: 'basic_channel_group',
|
|
||||||
channelGroupName: 'group_1')
|
|
||||||
],
|
|
||||||
debug: kDebugMode);
|
|
||||||
|
|
||||||
await AwesomeNotifications().isNotificationAllowed().then((isAllowed) async {
|
|
||||||
if (!AppState().isRequestOSNotification) {
|
|
||||||
if (!isAllowed) {
|
|
||||||
AppState().isRequestOSNotification = true;
|
|
||||||
await AwesomeNotifications().requestPermissionToSendNotifications();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
});
|
|
||||||
|
|
||||||
await AwesomeNotifications().setListeners(
|
|
||||||
onActionReceivedMethod: onActionReceivedMethod,
|
|
||||||
onNotificationCreatedMethod: onNotificationCreatedMethod,
|
|
||||||
onNotificationDisplayedMethod: onNotificationDisplayedMethod,
|
|
||||||
onDismissActionReceivedMethod: onDismissActionReceivedMethod);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Future<void> onActionReceivedMethod(
|
|
||||||
ReceivedAction receivedAction) async {
|
|
||||||
final payload = receivedAction.payload ?? {};
|
|
||||||
final extra = receivedAction.body;
|
|
||||||
final handleClick = payload['click_action'];
|
|
||||||
|
|
||||||
final localId = jsonDecode(payload['local']!)['CLI_ID'];
|
final localId = jsonDecode(payload['local']!)['CLI_ID'];
|
||||||
|
|
||||||
log('payload: $payload');
|
log('payload: $payload');
|
||||||
|
@ -309,6 +262,59 @@ class NotificationService {
|
||||||
// showAlertDialog(AppState().context!, 'Test', 'Test', () async {});
|
// showAlertDialog(AppState().context!, 'Test', 'Test', () async {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class NotificationService {
|
||||||
|
static Future<void> initialize() async {
|
||||||
|
await AwesomeNotifications().initialize(
|
||||||
|
'resource://drawable/notification_icon',
|
||||||
|
[
|
||||||
|
NotificationChannel(
|
||||||
|
channelKey: 'basic_channel',
|
||||||
|
channelGroupKey: 'basic_channel',
|
||||||
|
channelName: 'Notificações do App',
|
||||||
|
channelDescription: 'Canal de notificação do Aplicativo',
|
||||||
|
importance: NotificationImportance.Max,
|
||||||
|
channelShowBadge: false,
|
||||||
|
playSound: true,
|
||||||
|
criticalAlerts: true,
|
||||||
|
onlyAlertOnce: true,
|
||||||
|
defaultColor: Colors.green,
|
||||||
|
ledColor: Colors.white,
|
||||||
|
)
|
||||||
|
],
|
||||||
|
channelGroups: [
|
||||||
|
NotificationChannelGroup(
|
||||||
|
channelGroupKey: 'basic_channel_group',
|
||||||
|
channelGroupName: 'group_1')
|
||||||
|
],
|
||||||
|
debug: kDebugMode);
|
||||||
|
|
||||||
|
await AwesomeNotifications()
|
||||||
|
.isNotificationAllowed()
|
||||||
|
.then((isAllowed) async {
|
||||||
|
if (!AppState().isRequestOSNotification) {
|
||||||
|
if (!isAllowed) {
|
||||||
|
AppState().isRequestOSNotification = true;
|
||||||
|
await AwesomeNotifications().requestPermissionToSendNotifications();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
|
||||||
|
await AwesomeNotifications().setListeners(
|
||||||
|
onActionReceivedMethod: onActionReceivedMethod,
|
||||||
|
onNotificationCreatedMethod: onNotificationCreatedMethod,
|
||||||
|
onNotificationDisplayedMethod: onNotificationDisplayedMethod,
|
||||||
|
onDismissActionReceivedMethod: onDismissActionReceivedMethod);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> onActionReceivedMethod(
|
||||||
|
ReceivedAction receivedAction) async {
|
||||||
|
final payload = receivedAction.payload ?? {};
|
||||||
|
final extra = receivedAction.body;
|
||||||
|
final handleClick = payload['click_action'];
|
||||||
|
onMessageReceived(payload, extra, handleClick);
|
||||||
|
}
|
||||||
|
|
||||||
static Future<void> onNotificationCreatedMethod(
|
static Future<void> onNotificationCreatedMethod(
|
||||||
ReceivedNotification receivedNotification) async {}
|
ReceivedNotification receivedNotification) async {}
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,6 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||||
import 'package:flutter_web_plugins/url_strategy.dart';
|
import 'package:flutter_web_plugins/url_strategy.dart';
|
||||||
import 'package:hub/backend/api_requests/api_calls.dart';
|
|
||||||
import 'package:hub/backend/api_requests/api_manager.dart';
|
|
||||||
import 'package:hub/backend/notifications/firebase_messaging_service.dart';
|
|
||||||
import 'package:hub/shared/utils/log_util.dart';
|
|
||||||
import 'package:hub/backend/notifications/notification_service.dart';
|
import 'package:hub/backend/notifications/notification_service.dart';
|
||||||
import 'package:hub/flutter_flow/flutter_flow_theme.dart';
|
import 'package:hub/flutter_flow/flutter_flow_theme.dart';
|
||||||
import 'package:hub/flutter_flow/flutter_flow_util.dart';
|
import 'package:hub/flutter_flow/flutter_flow_util.dart';
|
||||||
|
@ -51,16 +47,16 @@ Future<void> initializeApp() async {
|
||||||
usePathUrlStrategy();
|
usePathUrlStrategy();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> handleMessage(RemoteMessage message) async {
|
Future<void> foregroundHandleMessage(RemoteMessage message) async {
|
||||||
NotificationService.show(
|
NotificationService.show(
|
||||||
title: message.notification!.title!,
|
title: message.notification!.title!,
|
||||||
body: message.notification!.body!,
|
body: message.notification!.body!,
|
||||||
payload: Map<String, String>.from(message.data));
|
payload: Map<String, String>.from(message.data));
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
|
Future<void> _backgroundHandleMessage(RemoteMessage message) async {
|
||||||
await Firebase.initializeApp();
|
log('Handling a background message: ${message.messageId}');
|
||||||
log('Background message: ${message.toMap()}');
|
// Add your message handling logic here
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
|
@ -95,17 +91,15 @@ class _AppState extends State<App> {
|
||||||
Future.delayed(const Duration(milliseconds: 1000),
|
Future.delayed(const Duration(milliseconds: 1000),
|
||||||
() => setState(() => _appStateNotifier.stopShowingSplashImage()));
|
() => setState(() => _appStateNotifier.stopShowingSplashImage()));
|
||||||
|
|
||||||
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
|
FirebaseMessaging.onMessage.listen(foregroundHandleMessage);
|
||||||
log('Received message: ${message.toMap()}');
|
|
||||||
});
|
|
||||||
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
|
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
|
||||||
log('Message opened: ${message.notification?.body}');
|
onMessageReceived(message.data, '', message.data['click_action']);
|
||||||
});
|
});
|
||||||
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
|
FirebaseMessaging.onBackgroundMessage(_backgroundHandleMessage);
|
||||||
|
|
||||||
FirebaseMessaging.instance.getInitialMessage().then((message) {
|
FirebaseMessaging.instance.getInitialMessage().then((message) {
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
log('Initial message: ${message.notification?.body}');
|
_backgroundHandleMessage(message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue