WIP
This commit is contained in:
parent
e557601a90
commit
e903683f07
|
@ -56,14 +56,14 @@
|
|||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
<intent-filter android:autoVerify="true">
|
||||
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
|
||||
<action android:name="mensagem" />
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<data android:scheme="frehub" android:host="frehub.com" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
|
||||
<action android:name="mensagem" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</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/shared/utils/dialog_util.dart';
|
||||
|
||||
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'];
|
||||
|
||||
Future<void> onMessageReceived(
|
||||
Map<String, dynamic> payload, String? extra, String? handleClick) async {
|
||||
final localId = jsonDecode(payload['local']!)['CLI_ID'];
|
||||
|
||||
log('payload: $payload');
|
||||
|
@ -309,6 +262,59 @@ class NotificationService {
|
|||
// 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(
|
||||
ReceivedNotification receivedNotification) async {}
|
||||
|
||||
|
|
|
@ -9,10 +9,6 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.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/flutter_flow/flutter_flow_theme.dart';
|
||||
import 'package:hub/flutter_flow/flutter_flow_util.dart';
|
||||
|
@ -51,16 +47,16 @@ Future<void> initializeApp() async {
|
|||
usePathUrlStrategy();
|
||||
}
|
||||
|
||||
Future<void> handleMessage(RemoteMessage message) async {
|
||||
Future<void> foregroundHandleMessage(RemoteMessage message) async {
|
||||
NotificationService.show(
|
||||
title: message.notification!.title!,
|
||||
body: message.notification!.body!,
|
||||
payload: Map<String, String>.from(message.data));
|
||||
}
|
||||
|
||||
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
|
||||
await Firebase.initializeApp();
|
||||
log('Background message: ${message.toMap()}');
|
||||
Future<void> _backgroundHandleMessage(RemoteMessage message) async {
|
||||
log('Handling a background message: ${message.messageId}');
|
||||
// Add your message handling logic here
|
||||
}
|
||||
|
||||
void main() async {
|
||||
|
@ -95,17 +91,15 @@ class _AppState extends State<App> {
|
|||
Future.delayed(const Duration(milliseconds: 1000),
|
||||
() => setState(() => _appStateNotifier.stopShowingSplashImage()));
|
||||
|
||||
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
|
||||
log('Received message: ${message.toMap()}');
|
||||
});
|
||||
FirebaseMessaging.onMessage.listen(foregroundHandleMessage);
|
||||
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) {
|
||||
if (message != null) {
|
||||
log('Initial message: ${message.notification?.body}');
|
||||
_backgroundHandleMessage(message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue