No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.dart 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import 'package:firebase_core/firebase_core.dart';
  2. import 'package:firebase_messaging/firebase_messaging.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter/services.dart';
  5. import 'package:hris_selfservice_mobile/Screens/Splash/splash_screen.dart';
  6. //import 'package:hris_selfservice_mobile/Screens/ForgotPassword/forgotPassword_screen.dart';
  7. import 'constants.dart';
  8. import 'firebase_options.dart';
  9. import 'dart:developer' as logDev;
  10. @pragma('vm:entry-point')
  11. Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
  12. // If you're going to use other Firebase services in the background, such as Firestore,
  13. // make sure you call `initializeApp` before using other Firebase services.
  14. await Firebase.initializeApp();
  15. print("Handling a background message: ${message.messageId}");
  16. }
  17. void main() async{
  18. WidgetsFlutterBinding.ensureInitialized();
  19. await Firebase.initializeApp(
  20. options: DefaultFirebaseOptions.currentPlatform,
  21. );
  22. FirebaseMessaging messaging = FirebaseMessaging.instance;
  23. NotificationSettings settings = await messaging.requestPermission(
  24. alert: true,
  25. announcement: false,
  26. badge: true,
  27. carPlay: false,
  28. criticalAlert: false,
  29. provisional: false,
  30. sound: true,
  31. );
  32. print('User granted permission: ${settings.authorizationStatus}');
  33. FirebaseMessaging.onMessage.listen((RemoteMessage remoteMessage) async {
  34. Map<String, dynamic> data = remoteMessage.data;
  35. logDev.log(data.toString(), name: "NOTIF Messaging");
  36. String body = data['body'].toString();
  37. logDev.log(body, name: "NOTIF Body");
  38. print('Got a message whilst in the foreground!');
  39. print('Message data: ${remoteMessage.data}');
  40. if (remoteMessage.notification != null) {
  41. print('Message also contained a notification: ${remoteMessage.notification}');
  42. }
  43. });
  44. SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
  45. statusBarColor: Colors.transparent,
  46. ));
  47. FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
  48. runApp(MyApp());
  49. }
  50. class MyApp extends StatelessWidget {
  51. const MyApp({super.key});
  52. @override
  53. Widget build(BuildContext context) {
  54. return MaterialApp(
  55. debugShowCheckedModeBanner: false,
  56. title: 'Flutter Welcome Screen',
  57. theme: ThemeData(
  58. primaryColor: kPrimaryColor,
  59. scaffoldBackgroundColor: Colors.white
  60. ),
  61. home: Splash(),
  62. );
  63. }
  64. }