feat: request notifications access only AFTER user action
This commit is contained in:
parent
c42c4e9be7
commit
9c4ad5cdb2
@ -6,11 +6,7 @@ import 'services/notification_service.dart';
|
|||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
await Firebase.initializeApp(
|
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
|
||||||
options: DefaultFirebaseOptions.currentPlatform,
|
|
||||||
);
|
|
||||||
|
|
||||||
NotificationService().initialize();
|
|
||||||
|
|
||||||
runApp(MyApp());
|
runApp(MyApp());
|
||||||
}
|
}
|
||||||
@ -61,6 +57,9 @@ class _LandingPageState extends State<LandingPage>
|
|||||||
_showBottomSheet = true;
|
_showBottomSheet = true;
|
||||||
});
|
});
|
||||||
_animationController.forward();
|
_animationController.forward();
|
||||||
|
|
||||||
|
// Request notification permissions on user action
|
||||||
|
NotificationService().requestPermissionAndSetup();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _hideBottomSheet() {
|
void _hideBottomSheet() {
|
||||||
@ -78,6 +77,9 @@ class _LandingPageState extends State<LandingPage>
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _navigateToHome() {
|
void _navigateToHome() {
|
||||||
|
// Request notification permissions on user action
|
||||||
|
NotificationService().requestPermissionAndSetup();
|
||||||
|
|
||||||
Navigator.of(
|
Navigator.of(
|
||||||
context,
|
context,
|
||||||
).push(MaterialPageRoute(builder: (context) => HomeScreen()));
|
).push(MaterialPageRoute(builder: (context) => HomeScreen()));
|
||||||
|
|||||||
@ -31,15 +31,36 @@ class NotificationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_messaging = FirebaseMessaging.instance;
|
_messaging = FirebaseMessaging.instance;
|
||||||
|
|
||||||
await _requestPermission();
|
|
||||||
await _subscribeToTopics();
|
|
||||||
await _setupMessageHandlers();
|
await _setupMessageHandlers();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('Error initializing notifications: $e');
|
print('Error initializing notifications: $e');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> requestPermissionAndSetup() async {
|
||||||
|
try {
|
||||||
|
if (!kIsWeb) {
|
||||||
|
print('Notifications are only supported on web platform');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_isNotificationSupported()) {
|
||||||
|
print('Notifications are not supported in this browser');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_messaging == null) {
|
||||||
|
_messaging = FirebaseMessaging.instance;
|
||||||
|
await _setupMessageHandlers();
|
||||||
|
}
|
||||||
|
|
||||||
|
await _requestPermission();
|
||||||
|
await _subscribeToTopics();
|
||||||
|
} catch (e) {
|
||||||
|
print('Error requesting notification permission: $e');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool _isNotificationSupported() {
|
bool _isNotificationSupported() {
|
||||||
if (!kIsWeb) return false;
|
if (!kIsWeb) return false;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user