93 lines
2.7 KiB
Dart
93 lines
2.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'core/config/app_config.dart';
|
|
import 'core/localization/app_strings.dart';
|
|
import 'core/theme/app_theme.dart';
|
|
import 'logic/cubits/auth_cubit.dart';
|
|
import 'logic/cubits/dashboard_cubits.dart';
|
|
import 'logic/cubits/curriculum_cubit.dart';
|
|
import 'logic/cubits/video_playback_cubit.dart';
|
|
import 'presentation/screens/auth/auth_screen.dart';
|
|
import 'presentation/screens/home/unified_home_screen.dart';
|
|
|
|
void main() {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
runApp(const SaqelAppRoot());
|
|
}
|
|
|
|
class SaqelAppRoot extends StatefulWidget {
|
|
const SaqelAppRoot({super.key});
|
|
|
|
@override
|
|
State<SaqelAppRoot> createState() => _SaqelAppRootState();
|
|
}
|
|
|
|
class _SaqelAppRootState extends State<SaqelAppRoot> {
|
|
final ThemeMode _themeMode = ThemeMode.dark;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MultiBlocProvider(
|
|
providers: [
|
|
BlocProvider<AuthCubit>(
|
|
create: (context) => AuthCubit()..checkSession(),
|
|
),
|
|
BlocProvider<StudentCubit>(
|
|
create: (context) => StudentCubit(),
|
|
),
|
|
BlocProvider<GuardianCubit>(
|
|
create: (context) => GuardianCubit(),
|
|
),
|
|
BlocProvider<CurriculumCubit>(
|
|
create: (context) => CurriculumCubit(),
|
|
),
|
|
BlocProvider<VideoPlaybackCubit>(
|
|
create: (context) => VideoPlaybackCubit(),
|
|
),
|
|
],
|
|
child: MaterialApp(
|
|
title: AppConfig.appNameAr,
|
|
debugShowCheckedModeBanner: false,
|
|
theme: AppTheme.lightTheme,
|
|
darkTheme: AppTheme.darkTheme,
|
|
themeMode: _themeMode,
|
|
builder: (context, child) {
|
|
// RTL / LTR Directionality Control
|
|
return Directionality(
|
|
textDirection: AppStrings.isArabic ? TextDirection.rtl : TextDirection.ltr,
|
|
child: child!,
|
|
);
|
|
},
|
|
home: const AuthGate(),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Global Auth Gate: Auto-Directs to Unified Dashboard if Logged In, or AuthScreen
|
|
class AuthGate extends StatelessWidget {
|
|
const AuthGate({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return BlocBuilder<AuthCubit, AuthState>(
|
|
builder: (context, state) {
|
|
if (state is Authenticated) {
|
|
return UnifiedHomeScreen(
|
|
user: state.user,
|
|
activeRole: state.activeRole,
|
|
);
|
|
} else if (state is AuthLoading) {
|
|
return const Scaffold(
|
|
body: Center(
|
|
child: CircularProgressIndicator(),
|
|
),
|
|
);
|
|
}
|
|
// Default to AuthScreen for unauthenticated or OTP states
|
|
return const AuthScreen();
|
|
},
|
|
);
|
|
}
|
|
}
|