Deploy: 2026-05-24 23:27:32
This commit is contained in:
86
mobile/lib/main.dart
Normal file
86
mobile/lib/main.dart
Normal file
@@ -0,0 +1,86 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'features/auth/data/auth_repository.dart';
|
||||
import 'features/auth/presentation/cubit/auth_cubit.dart';
|
||||
import 'features/auth/presentation/cubit/auth_state.dart';
|
||||
import 'features/auth/presentation/screens/login_screen.dart';
|
||||
import 'features/dashboard/presentation/screens/dashboard_screen.dart';
|
||||
|
||||
void main() {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
// English: Instantiate repositories to supply to Cubits.
|
||||
// Arabic: إنشاء مثيلات المستودعات لتزويد الكيوبيتس بها.
|
||||
final authRepository = AuthRepository();
|
||||
|
||||
runApp(
|
||||
// English: Provide AuthCubit globally so it is accessible on all screens.
|
||||
// Arabic: توفير الكيوبيت لمصادقة المستخدمين عالمياً ليكون متاحاً في جميع الشاشات.
|
||||
BlocProvider<AuthCubit>(
|
||||
create: (context) => AuthCubit(authRepository)..checkAuthStatus(),
|
||||
child: const NabehApp(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class NabehApp extends StatelessWidget {
|
||||
const NabehApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'نبيه',
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: ThemeData(
|
||||
brightness: Brightness.dark,
|
||||
primarySwatch: Colors.deepPurple,
|
||||
fontFamily: 'Outfit',
|
||||
),
|
||||
// English: Dynamically route home screen based on active authentication state.
|
||||
// Arabic: توجيه الشاشة الرئيسية ديناميكيًا بناءً على حالة المصادقة النشطة.
|
||||
home: BlocBuilder<AuthCubit, AuthState>(
|
||||
builder: (context, state) {
|
||||
if (state is Authenticated) {
|
||||
// English: Navigate to dashboard screen on success.
|
||||
// Arabic: الانتقال إلى شاشة لوحة التحكم عند النجاح.
|
||||
return DashboardScreen(user: state.user);
|
||||
} else if (state is Unauthenticated || state is AuthFailure) {
|
||||
// English: Navigate to login screen on unauthenticated state.
|
||||
// Arabic: الانتقال إلى شاشة تسجيل الدخول عند عدم المصادقة.
|
||||
return const LoginScreen();
|
||||
} else {
|
||||
// English: Show splash loader during initial authentication check.
|
||||
// Arabic: عرض شاشة تحميل أولية أثناء التحقق من المصادقة لأول مرة.
|
||||
return const SplashScreen();
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// English: Splash Screen displayed during initialization status check.
|
||||
// Arabic: شاشة البداية المعروضة أثناء التحقق من حالة التهيئة.
|
||||
class SplashScreen extends StatelessWidget {
|
||||
const SplashScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Scaffold(
|
||||
backgroundColor: Color(0xFF0F0C20),
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
CircularProgressIndicator(color: Colors.purpleAccent),
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
'جاري تهيئة النظام...',
|
||||
style: TextStyle(color: Colors.white70, fontSize: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user