65 lines
2.2 KiB
Dart
65 lines
2.2 KiB
Dart
import 'package:firebase_messaging/firebase_messaging.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:firebase_core/firebase_core.dart';
|
|
import 'app/routes/app_pages.dart';
|
|
import 'core/services/push_notification_service.dart';
|
|
import 'core/services/upload_progress_service.dart';
|
|
import 'core/services/home_widget_service.dart';
|
|
import 'core/services/shorebird_update_service.dart';
|
|
import 'core/services/device_security_service.dart';
|
|
import 'app/theme/app_theme.dart';
|
|
|
|
@pragma('vm:entry-point')
|
|
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
|
|
await Firebase.initializeApp();
|
|
debugPrint("Handling a background message: ${message.messageId}");
|
|
}
|
|
|
|
void main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
// 1. Initialize Firebase
|
|
await Firebase.initializeApp();
|
|
|
|
// 2. Register the background handler BEFORE any listener is attached, so a
|
|
// message arriving during startup is not lost.
|
|
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
|
|
|
|
// 3. Notifications (permissions, Android channel, tap routing, token refresh)
|
|
await PushNotificationService.initialize();
|
|
|
|
// 4. Security check (MUST be first)
|
|
Get.put(DeviceSecurityService(), permanent: true);
|
|
|
|
// 5. Register global services
|
|
Get.put(UploadProgressService(), permanent: true);
|
|
Get.put(HomeWidgetService(), permanent: true);
|
|
Get.put(ShorebirdUpdateService(), permanent: true);
|
|
|
|
// 6. Re-sync the push token on every launch. It can rotate while the app is
|
|
// closed (reinstall, restore from backup, FCM rotation), and a stale token on
|
|
// the server means the device silently stops receiving notifications.
|
|
PushNotificationService.registerTokenWithServer();
|
|
|
|
runApp(const MusadaqApp());
|
|
}
|
|
|
|
class MusadaqApp extends StatelessWidget {
|
|
const MusadaqApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return GetMaterialApp(
|
|
title: 'Musadaq',
|
|
theme: AppTheme.lightTheme,
|
|
darkTheme: AppTheme.darkTheme,
|
|
themeMode: ThemeMode.system,
|
|
initialRoute: AppPages.INITIAL,
|
|
getPages: AppPages.routes,
|
|
debugShowCheckedModeBanner: false,
|
|
locale: const Locale('ar', 'JO'), // Arabic by default
|
|
);
|
|
}
|
|
}
|