import 'dart:ui'; import 'package:firebase_crashlytics/firebase_crashlytics.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/material.dart'; import 'firebase_options.dart'; void initializeFirebase() async { await Firebase.initializeApp( options: DefaultFirebaseOptions.currentPlatform, ); await FirebaseMessaging.instance.requestPermission( alert: true, announcement: false, badge: true, carPlay: false, criticalAlert: false, provisional: false, sound: true, ); FlutterError.onError = (errorDetails) { FirebaseCrashlytics.instance.recordFlutterFatalError(errorDetails); }; PlatformDispatcher.instance.onError = (error, stack) { FirebaseCrashlytics.instance.recordError(error, stack, fatal: true); return true; }; } Future initializeFirebaseMessaging() async { try { final fcmToken = await FirebaseMessaging.instance.getToken(); return fcmToken; } catch (e) { print("failed to setup firebase messaging: $e"); return null; } }