|
1 | 1 | import 'package:firebase_messaging/firebase_messaging.dart'; |
2 | 2 | import 'package:flutter/material.dart'; |
| 3 | +import 'package:flutter_bloc/flutter_bloc.dart'; |
3 | 4 | import 'package:flutter_svg/flutter_svg.dart'; |
4 | 5 | import 'package:go_router/go_router.dart'; |
5 | 6 | import 'package:on_time_front/core/services/notification_service.dart'; |
6 | 7 | import 'package:on_time_front/l10n/app_localizations.dart'; |
| 8 | +import 'package:on_time_front/presentation/app/cubit/notification_gate_cubit.dart'; |
7 | 9 | import 'package:on_time_front/presentation/shared/components/modal_wide_button.dart'; |
8 | 10 | import 'package:on_time_front/presentation/shared/components/two_action_dialog.dart'; |
9 | 11 | import 'package:on_time_front/presentation/shared/constants/app_colors.dart'; |
@@ -69,7 +71,9 @@ class _Buttons extends StatelessWidget { |
69 | 71 | ), |
70 | 72 | ), |
71 | 73 | GestureDetector( |
72 | | - onTap: () { |
| 74 | + onTap: () async { |
| 75 | + await context.read<NotificationGateCubit>().dismissPrompt(); |
| 76 | + if (!context.mounted) return; |
73 | 77 | context.go('/home'); |
74 | 78 | }, |
75 | 79 | child: SizedBox( |
@@ -160,35 +164,50 @@ Future<void> _handleNotificationPermission(BuildContext context) async { |
160 | 164 | if (!context.mounted) return; |
161 | 165 |
|
162 | 166 | if (currentStatus == AuthorizationStatus.authorized) { |
163 | | - await notificationService.initialize(); |
| 167 | + await context.read<NotificationGateCubit>().markPermissionAllowed(); |
164 | 168 | if (context.mounted) { |
165 | 169 | context.go('/home'); |
166 | 170 | } |
167 | 171 | } else if (currentStatus == AuthorizationStatus.denied) { |
168 | 172 | final shouldOpenSettings = await _showGoToSettingsDialog(context); |
169 | 173 | if (shouldOpenSettings == true) { |
170 | 174 | await notificationService.openNotificationSettings(); |
| 175 | + } else if (context.mounted) { |
| 176 | + await context.read<NotificationGateCubit>().dismissPrompt(); |
| 177 | + if (context.mounted) { |
| 178 | + context.go('/home'); |
| 179 | + } |
171 | 180 | } |
172 | 181 | } else if (currentStatus == AuthorizationStatus.notDetermined) { |
173 | 182 | final newStatus = await notificationService.requestPermission(); |
174 | 183 |
|
175 | 184 | if (!context.mounted) return; |
176 | 185 |
|
177 | 186 | if (newStatus == AuthorizationStatus.authorized) { |
178 | | - await notificationService.initialize(); |
| 187 | + await context.read<NotificationGateCubit>().markPermissionAllowed(); |
179 | 188 | if (context.mounted) { |
180 | 189 | context.go('/home'); |
181 | 190 | } |
182 | 191 | } else if (newStatus == AuthorizationStatus.denied) { |
183 | 192 | final shouldOpenSettings = await _showGoToSettingsDialog(context); |
184 | 193 | if (shouldOpenSettings == true) { |
185 | 194 | await notificationService.openNotificationSettings(); |
| 195 | + } else if (context.mounted) { |
| 196 | + await context.read<NotificationGateCubit>().dismissPrompt(); |
| 197 | + if (context.mounted) { |
| 198 | + context.go('/home'); |
| 199 | + } |
186 | 200 | } |
187 | 201 | } |
188 | 202 | } else { |
189 | 203 | final shouldOpenSettings = await _showGoToSettingsDialog(context); |
190 | 204 | if (shouldOpenSettings == true) { |
191 | 205 | await notificationService.openNotificationSettings(); |
| 206 | + } else if (context.mounted) { |
| 207 | + await context.read<NotificationGateCubit>().dismissPrompt(); |
| 208 | + if (context.mounted) { |
| 209 | + context.go('/home'); |
| 210 | + } |
192 | 211 | } |
193 | 212 | } |
194 | 213 | } |
|
0 commit comments