fix: Notificações / Permissões

This commit is contained in:
Ivan Antunes 2024-09-04 09:33:07 -03:00
parent 7b0b66683c
commit 3496605f3f
4 changed files with 29 additions and 9 deletions

View File

@ -163,6 +163,10 @@ class AppState extends ChangeNotifier {
await _safeInitAsync(() async { await _safeInitAsync(() async {
_haveLocal = await secureStorage.getBool('ff_have_local') ?? _haveLocal; _haveLocal = await secureStorage.getBool('ff_have_local') ?? _haveLocal;
}); });
await _safeInitAsync(() async {
_isRequestOSNotification = await secureStorage.getBool('ff_request_os_notification') ?? _isRequestOSNotification;
});
} }
void update(VoidCallback callback) { void update(VoidCallback callback) {
@ -171,9 +175,20 @@ class AppState extends ChangeNotifier {
} }
late FlutterSecureStorage secureStorage; late FlutterSecureStorage secureStorage;
bool _isRequestOSNotification = false;
bool get isRequestOSNotification => _isRequestOSNotification;
set isRequestOSNotification(bool value) {
_isRequestOSNotification = value;
secureStorage.setBool('ff_request_os_notification', value);
}
void deleteIsRequestOSNotification() {
secureStorage.delete(key: 'ff_request_os_notification');
}
bool _whatsapp = false; bool _whatsapp = false;
bool get whatsapp => _whatsapp; bool get whatsapp => _whatsapp;
set whatsapp(bool value) { set whatsapp(bool value) {
_whatsapp = value; _whatsapp = value;
secureStorage.setBool('whatsapp', value); secureStorage.setBool('whatsapp', value);

View File

@ -1,6 +1,7 @@
import 'dart:developer'; import 'dart:developer';
import 'package:awesome_notifications/awesome_notifications.dart'; import 'package:awesome_notifications/awesome_notifications.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:hub/actions/actions.dart'; import 'package:hub/actions/actions.dart';
import 'package:hub/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_widget.dart'; import 'package:hub/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_widget.dart';
@ -37,13 +38,16 @@ class NotificationService {
channelGroupKey: 'basic_channel_group', channelGroupKey: 'basic_channel_group',
channelGroupName: 'group_1') channelGroupName: 'group_1')
], ],
debug: true); debug: kDebugMode);
await AwesomeNotifications()
.isNotificationAllowed() await AwesomeNotifications().isNotificationAllowed().then((isAllowed) async {
.then((isAllowed) async { if (!AppState().isRequestOSNotification) {
if (!isAllowed) { if (!isAllowed) {
await AwesomeNotifications().requestPermissionToSendNotifications(); AppState().isRequestOSNotification = true;
await AwesomeNotifications().requestPermissionToSendNotifications();
}
} }
return;
}); });
await AwesomeNotifications().setListeners( await AwesomeNotifications().setListeners(

View File

@ -24,6 +24,9 @@ Future<void> initializeApp() async {
final status = await AppTrackingTransparency.requestTrackingAuthorization(); final status = await AppTrackingTransparency.requestTrackingAuthorization();
final appState = AppState();
await appState.initializePersistedState();
await Firebase.initializeApp(); await Firebase.initializeApp();
await FirebaseMessagingService().initNotifications(); await FirebaseMessagingService().initNotifications();
await NotificationService.initialize(); await NotificationService.initialize();
@ -41,8 +44,6 @@ Future<void> initializeApp() async {
await FlutterFlowTheme.initialize(); await FlutterFlowTheme.initialize();
await FFLocalizations.initialize(); await FFLocalizations.initialize();
final appState = AppState();
await appState.initializePersistedState();
GoRouter.optionURLReflectsImperativeAPIs = true; GoRouter.optionURLReflectsImperativeAPIs = true;
usePathUrlStrategy(); usePathUrlStrategy();
} }

View File

@ -3,7 +3,7 @@ description: A new Flutter project.
publish_to: "none" publish_to: "none"
version: 1.0.0+6 version: 1.0.0+7
environment: environment:
sdk: ">=3.0.0 <4.0.0" sdk: ">=3.0.0 <4.0.0"