first commit
This commit is contained in:
114
siro_rider/lib/main.dart
Normal file
114
siro_rider/lib/main.dart
Normal file
@@ -0,0 +1,114 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'package:siro_rider/app_bindings.dart';
|
||||
import 'package:siro_rider/controller/functions/crud.dart';
|
||||
import 'package:siro_rider/views/home/HomePage/contact_us.dart';
|
||||
import 'package:siro_rider/views/home/HomePage/share_app_page.dart';
|
||||
import 'package:siro_rider/views/home/my_wallet/passenger_wallet.dart';
|
||||
import 'package:siro_rider/views/home/profile/passenger_profile_page.dart';
|
||||
import 'package:firebase_core/firebase_core.dart';
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:get_storage/get_storage.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:wakelock_plus/wakelock_plus.dart';
|
||||
import 'constant/info.dart';
|
||||
import 'controller/home/ios_live_activity_service.dart';
|
||||
import 'controller/local/local_controller.dart';
|
||||
import 'controller/local/translations.dart';
|
||||
import 'controller/themes/themes.dart';
|
||||
import 'firebase_options.dart';
|
||||
import 'models/db_sql.dart';
|
||||
import 'print.dart';
|
||||
import 'splash_screen_page.dart';
|
||||
|
||||
// -- Global instances for easy access --
|
||||
final box = GetStorage();
|
||||
final storage = FlutterSecureStorage();
|
||||
DbSql sql = DbSql.instance;
|
||||
|
||||
// Firebase background message handler must be a top-level function.
|
||||
@pragma('vm:entry-point')
|
||||
Future<void> backgroundMessageHandler(RemoteMessage message) async {
|
||||
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
|
||||
Log.print("Handling a background message: ${message.messageId}");
|
||||
}
|
||||
|
||||
void main() {
|
||||
// Use runZonedGuarded to catch all unhandled exceptions in the app.
|
||||
runZonedGuarded<Future<void>>(() async {
|
||||
// --- Step 1: Critical initializations before runApp() ---
|
||||
// These must complete before the UI can be built.
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await GetStorage.init();
|
||||
WakelockPlus.enable();
|
||||
if (Platform.isAndroid || Platform.isIOS) {
|
||||
await Firebase.initializeApp(
|
||||
options: DefaultFirebaseOptions.currentPlatform);
|
||||
FirebaseMessaging.onBackgroundMessage(backgroundMessageHandler);
|
||||
}
|
||||
// ✅ التعديل هنا: تهيئة خدمة الـ Live Activity للآيفون
|
||||
IosLiveActivityService.init();
|
||||
|
||||
// Lock screen orientation.
|
||||
await SystemChrome.setPreferredOrientations([
|
||||
DeviceOrientation.portraitUp,
|
||||
DeviceOrientation.portraitDown,
|
||||
]);
|
||||
Get.put(LocaleController());
|
||||
// --- Step 2: Run the app immediately ---
|
||||
// All heavy initializations are deferred to the SplashScreen.
|
||||
runApp(const MyApp());
|
||||
}, (error, stack) {
|
||||
// Global error handler.
|
||||
final s = error.toString();
|
||||
final ignored = s.contains('PERMISSION_DENIED') ||
|
||||
s.contains('FormatException') ||
|
||||
s.contains('Null check operator used on a null value');
|
||||
|
||||
if (!ignored) {
|
||||
CRUD.addError(s, stack.toString(), 'main_zone_guard');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Get.find() is used here because LocaleController is already put in AppBindings.
|
||||
final LocaleController localController = Get.find<LocaleController>();
|
||||
|
||||
return GetMaterialApp(
|
||||
title: AppInformation.appName,
|
||||
translations: MyTranslation(),
|
||||
debugShowCheckedModeBanner: false,
|
||||
locale: localController.language,
|
||||
theme: localController.language?.languageCode.startsWith('ar') == true
|
||||
? lightThemeArabic
|
||||
: lightThemeEnglish,
|
||||
darkTheme: localController.language?.languageCode.startsWith('ar') == true
|
||||
? darkThemeArabic
|
||||
: darkThemeEnglish,
|
||||
themeMode: localController.themeMode,
|
||||
|
||||
// --- [CRITICAL] ---
|
||||
// initialBinding tells GetX to run AppBindings once at the start.
|
||||
// This sets up all our controllers (put, lazyPut) for the entire app lifecycle.
|
||||
initialBinding: AppBindings(),
|
||||
|
||||
initialRoute: '/',
|
||||
getPages: [
|
||||
GetPage(name: '/', page: () => const SplashScreen()),
|
||||
// These routes are used by QuickActions and other navigation events.
|
||||
GetPage(name: '/shareApp', page: () => ShareAppPage()),
|
||||
GetPage(name: '/wallet', page: () => const PassengerWallet()),
|
||||
GetPage(name: '/profile', page: () => PassengerProfilePage()),
|
||||
GetPage(name: '/contactSupport', page: () => ContactUsPage()),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user