import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:hris_selfservice_mobile/Screens/Splash/splash_screen.dart'; //import 'package:hris_selfservice_mobile/Screens/ForgotPassword/forgotPassword_screen.dart'; import 'constants.dart'; import 'firebase_options.dart'; import 'dart:developer' as logDev; @pragma('vm:entry-point') Future _firebaseMessagingBackgroundHandler(RemoteMessage message) async { // If you're going to use other Firebase services in the background, such as Firestore, // make sure you call `initializeApp` before using other Firebase services. await Firebase.initializeApp(); print("Handling a background message: ${message.messageId}"); } void main() async{ WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp( options: DefaultFirebaseOptions.currentPlatform, ); FirebaseMessaging messaging = FirebaseMessaging.instance; NotificationSettings settings = await messaging.requestPermission( alert: true, announcement: false, badge: true, carPlay: false, criticalAlert: false, provisional: false, sound: true, ); print('User granted permission: ${settings.authorizationStatus}'); FirebaseMessaging.onMessage.listen((RemoteMessage remoteMessage) async { Map data = remoteMessage.data; logDev.log(data.toString(), name: "NOTIF Messaging"); String body = data['body'].toString(); logDev.log(body, name: "NOTIF Body"); print('Got a message whilst in the foreground!'); print('Message data: ${remoteMessage.data}'); if (remoteMessage.notification != null) { print('Message also contained a notification: ${remoteMessage.notification}'); } }); SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle( statusBarColor: Colors.transparent, )); FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler); runApp(MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, title: 'Flutter Welcome Screen', theme: ThemeData( primaryColor: kPrimaryColor, scaffoldBackgroundColor: Colors.white ), home: Splash(), ); } }