From 3496605f3faac914026124106452ee70d61072a7 Mon Sep 17 00:00:00 2001 From: Ivan Antunes Date: Wed, 4 Sep 2024 09:33:07 -0300 Subject: [PATCH] =?UTF-8?q?fix:=20Notifica=C3=A7=C3=B5es=20/=20Permiss?= =?UTF-8?q?=C3=B5es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/app_state.dart | 15 +++++++++++++++ .../notifications/notification_service.dart | 16 ++++++++++------ lib/main.dart | 5 +++-- pubspec.yaml | 2 +- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/lib/app_state.dart b/lib/app_state.dart index d6ae1b91..b01723f7 100644 --- a/lib/app_state.dart +++ b/lib/app_state.dart @@ -163,6 +163,10 @@ class AppState extends ChangeNotifier { await _safeInitAsync(() async { _haveLocal = await secureStorage.getBool('ff_have_local') ?? _haveLocal; }); + + await _safeInitAsync(() async { + _isRequestOSNotification = await secureStorage.getBool('ff_request_os_notification') ?? _isRequestOSNotification; + }); } void update(VoidCallback callback) { @@ -171,9 +175,20 @@ class AppState extends ChangeNotifier { } 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 get whatsapp => _whatsapp; + set whatsapp(bool value) { _whatsapp = value; secureStorage.setBool('whatsapp', value); diff --git a/lib/backend/notifications/notification_service.dart b/lib/backend/notifications/notification_service.dart index 8a535379..a494b6b6 100644 --- a/lib/backend/notifications/notification_service.dart +++ b/lib/backend/notifications/notification_service.dart @@ -1,6 +1,7 @@ import 'dart:developer'; import 'package:awesome_notifications/awesome_notifications.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.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'; @@ -37,13 +38,16 @@ class NotificationService { channelGroupKey: 'basic_channel_group', channelGroupName: 'group_1') ], - debug: true); - await AwesomeNotifications() - .isNotificationAllowed() - .then((isAllowed) async { - if (!isAllowed) { - await AwesomeNotifications().requestPermissionToSendNotifications(); + debug: kDebugMode); + + await AwesomeNotifications().isNotificationAllowed().then((isAllowed) async { + if (!AppState().isRequestOSNotification) { + if (!isAllowed) { + AppState().isRequestOSNotification = true; + await AwesomeNotifications().requestPermissionToSendNotifications(); + } } + return; }); await AwesomeNotifications().setListeners( diff --git a/lib/main.dart b/lib/main.dart index 224f6fc1..eb886a2a 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -24,6 +24,9 @@ Future initializeApp() async { final status = await AppTrackingTransparency.requestTrackingAuthorization(); + final appState = AppState(); + await appState.initializePersistedState(); + await Firebase.initializeApp(); await FirebaseMessagingService().initNotifications(); await NotificationService.initialize(); @@ -41,8 +44,6 @@ Future initializeApp() async { await FlutterFlowTheme.initialize(); await FFLocalizations.initialize(); - final appState = AppState(); - await appState.initializePersistedState(); GoRouter.optionURLReflectsImperativeAPIs = true; usePathUrlStrategy(); } diff --git a/pubspec.yaml b/pubspec.yaml index 4f66d5e2..36f3d38f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: A new Flutter project. publish_to: "none" -version: 1.0.0+6 +version: 1.0.0+7 environment: sdk: ">=3.0.0 <4.0.0"