TF-2464 Cannot request notification permission when reload app

(cherry picked from commit a98cff8871065c3354c4daaa31e0c29b64f93d65)
This commit is contained in:
dab246
2024-01-18 14:31:09 +07:00
committed by Dat PHAM HOANG
parent 1835e9fad7
commit 1d9cdadefb
@@ -25,7 +25,6 @@ class LocalNotificationManager {
final _localNotificationsPlugin = FlutterLocalNotificationsPlugin(); final _localNotificationsPlugin = FlutterLocalNotificationsPlugin();
bool _notificationsEnabled = false;
bool _isNotificationClickedOnTerminate = false; bool _isNotificationClickedOnTerminate = false;
Stream<NotificationResponse> get localNotificationStream => localNotificationsController.stream; Stream<NotificationResponse> get localNotificationStream => localNotificationsController.stream;
@@ -34,7 +33,8 @@ class LocalNotificationManager {
Future<void> setUp() async { Future<void> setUp() async {
try { try {
await _initLocalNotification(); final isInitialNotification = await _initLocalNotification();
log('LocalNotificationManager::setUp:isInitialNotification: $isInitialNotification');
await _checkLocalNotificationPermission(); await _checkLocalNotificationPermission();
if (PlatformInfo.isAndroid) { if (PlatformInfo.isAndroid) {
await _createAndroidNotificationChannelGroup(); await _createAndroidNotificationChannelGroup();
@@ -79,19 +79,13 @@ class LocalNotificationManager {
} }
Future<void> _checkLocalNotificationPermission() async { Future<void> _checkLocalNotificationPermission() async {
if (_notificationsEnabled) {
return Future.value(null);
}
if (PlatformInfo.isAndroid) { if (PlatformInfo.isAndroid) {
final granted = await _isAndroidPermissionGranted(); final granted = await _isAndroidPermissionGranted();
if (!granted) { if (!granted) {
_notificationsEnabled = await _requestPermissions(); await _requestPermissions();
} else {
_notificationsEnabled = granted;
} }
} else if (PlatformInfo.isIOS) { } else if (PlatformInfo.isIOS) {
_notificationsEnabled = await _requestPermissions(); await _requestPermissions();
} }
} }