import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.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; const AndroidNotificationChannel channel = AndroidNotificationChannel( 'high_importance_channel', // id 'High Importance Notifications', // title description: 'This channel is used for important notifications.', // description importance: Importance.high, playSound: true); final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); 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(); Map data = message.data; logDev.log(data.toString(), name: "NOTIF Messaging"); String body = data['body'].toString(); logDev.log(body, name: "NOTIF Body"); print("Handling a background message: ${message.messageId}"); } void main() async{ WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp( options: DefaultFirebaseOptions.currentPlatform, ); FirebaseMessaging messaging = FirebaseMessaging.instance; FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler); 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 message) async { Map data = message.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: ${message.data}'); if (message.notification != null) { print('Message also contained a notification: ${message.notification}'); } }); SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle( statusBarColor: Colors.transparent, )); FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler); await flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation()?.createNotificationChannel(channel); await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions( alert: true, badge: true, sound: true, ); 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(), ); } }