flutter(rider): rebuild lib on Cubit/Bloc + Tripz backend (core + auth slice)
- keep store identity (com.mobileapp.store.ride, shorebird, firebase, fonts); old lib -> lib_old_getx - core: config/di/router(go_router)/theme/api_client(dio+tenant+bearer)/token_store(secure) - auth: repo + AuthCubit + OTP phone/otp screens; home: flutter_map (OSM placeholder, انطلق TODO) - android usesCleartextTraffic=true for http API; maps=flutter_map (no Google), state=Cubit Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+11
-109
@@ -1,114 +1,16 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'package:Tripz/app_bindings.dart';
|
||||
import 'package:Tripz/controller/functions/crud.dart';
|
||||
import 'package:Tripz/views/home/HomePage/contact_us.dart';
|
||||
import 'package:Tripz/views/home/HomePage/share_app_page.dart';
|
||||
import 'package:Tripz/views/home/my_wallet/passenger_wallet.dart';
|
||||
import 'package:Tripz/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:flutter_stripe/flutter_stripe.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/api_key.dart';
|
||||
import 'constant/info.dart';
|
||||
import 'controller/functions/add_error.dart';
|
||||
import 'controller/home/ios_live_activity_service.dart';
|
||||
import 'controller/local/local_controller.dart';
|
||||
import 'controller/local/translations.dart';
|
||||
import 'package:firebase_core/firebase_core.dart';
|
||||
import 'firebase_options.dart';
|
||||
import 'models/db_sql.dart';
|
||||
import 'splash_screen_page.dart';
|
||||
import 'core/di.dart';
|
||||
import 'app.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);
|
||||
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();
|
||||
// Stripe key initialization is very fast.
|
||||
Stripe.publishableKey = AK.publishableKey;
|
||||
|
||||
// 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) {
|
||||
addError(
|
||||
s,
|
||||
stack.toString(),
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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.appTheme,
|
||||
|
||||
// --- [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()),
|
||||
],
|
||||
);
|
||||
Future<void> main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
try {
|
||||
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
|
||||
} catch (_) {
|
||||
// لا نُسقط الإقلاع لو تعذّر Firebase
|
||||
}
|
||||
await setupDi();
|
||||
runApp(const TripzApp());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user