feat: implement core architecture, design system, localization, and trip features for both driver and rider apps.
This commit is contained in:
+77
-26
@@ -1,42 +1,93 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'core/config.dart';
|
||||
import 'package:driver/core/l10n/app_localizations.dart';
|
||||
import 'core/di.dart';
|
||||
import 'core/router.dart';
|
||||
import 'core/theme.dart';
|
||||
import 'core/design/theme.dart';
|
||||
import 'features/auth/cubit/auth_cubit.dart';
|
||||
import 'features/auth/data/auth_repository.dart';
|
||||
import 'features/settings/cubit/settings_cubit.dart';
|
||||
import 'features/auth/cubit/auth_state.dart';
|
||||
import 'features/home/cubit/driver_cubit.dart';
|
||||
import 'features/offers/bloc/offers_bloc.dart';
|
||||
import 'features/trip/bloc/driver_trip_bloc.dart';
|
||||
import 'features/trip/data/fcm_service.dart';
|
||||
|
||||
class TripzDriverApp extends StatelessWidget {
|
||||
const TripzDriverApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (_) => AuthCubit(getIt<AuthRepository>())..checkAuth(),
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
final router = buildRouter(context.read<AuthCubit>());
|
||||
return MaterialApp.router(
|
||||
title: AppConfig.appName,
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: buildTheme(),
|
||||
locale: const Locale('ar'),
|
||||
supportedLocales: const [Locale('ar'), Locale('en')],
|
||||
localizationsDelegates: const [
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
builder: (context, child) => Directionality(
|
||||
textDirection: TextDirection.rtl,
|
||||
child: child!,
|
||||
),
|
||||
routerConfig: router,
|
||||
);
|
||||
},
|
||||
return MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider(
|
||||
create: (_) => SettingsCubit(),
|
||||
),
|
||||
BlocProvider(
|
||||
create: (_) => AuthCubit(getIt<AuthRepository>())..checkAuth(),
|
||||
),
|
||||
// Blocs for Phase 3 — provided from getIt (lazy singletons).
|
||||
// They persist across navigation and are disposed manually at logout.
|
||||
BlocProvider.value(value: getIt<DriverCubit>()..loadProfile()),
|
||||
BlocProvider.value(
|
||||
value: getIt<OffersBloc>()..add(const OffersStarted()),
|
||||
),
|
||||
BlocProvider.value(
|
||||
value: getIt<DriverTripBloc>()..add(const DriverTripCheckActive()),
|
||||
),
|
||||
],
|
||||
child: _AppListener(
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
final settings = context.watch<SettingsCubit>();
|
||||
final auth = context.read<AuthCubit>();
|
||||
final router = buildRouter(auth);
|
||||
|
||||
return MaterialApp.router(
|
||||
title: 'Tripz Driver',
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: buildTheme(
|
||||
brightness: Brightness.light,
|
||||
locale: settings.state.locale,
|
||||
),
|
||||
darkTheme: buildTheme(
|
||||
brightness: Brightness.dark,
|
||||
locale: settings.state.locale,
|
||||
),
|
||||
themeMode: settings.state.themeMode,
|
||||
locale: settings.state.locale,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
routerConfig: router,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// يستمع لتغيير حالة المصادقة ويُهيّئ FCM بعد تسجيل الدخول.
|
||||
class _AppListener extends StatefulWidget {
|
||||
final Widget child;
|
||||
const _AppListener({required this.child});
|
||||
|
||||
@override
|
||||
State<_AppListener> createState() => _AppListenerState();
|
||||
}
|
||||
|
||||
class _AppListenerState extends State<_AppListener> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final auth = context.read<AuthCubit>();
|
||||
auth.stream.listen((state) {
|
||||
if (state.status == AuthStatus.authenticated) {
|
||||
getIt<DriverFcmService>().init();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => widget.child;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user