|
|
import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:sonnat/core/language/language_cubit.dart'; import 'package:sonnat/core/language/translator.dart'; import 'package:sonnat/core/theme/cubit/theme_cubit.dart'; import 'package:sonnat/core/utils/app_utils.dart'; import 'package:sonnat/core/utils/base_cubit_type.dart'; import 'package:sonnat/core/utils/initializer.dart'; import 'package:sonnat/features/splash/cubit/splash_cubit.dart'; import 'package:sonnat/features/splash/screen/splash_screen.dart';
void main() async { WidgetsFlutterBinding.ensureInitialized(); await Initializer.instance.initialHive(); runApp(const MyApp()); }
class MyApp extends StatelessWidget { const MyApp({super.key});
@override Widget build(BuildContext context) { SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]); SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []); return MultiBlocProvider( providers: [ BlocProvider(create: (context) => LanguageCubit()), BlocProvider(create: (context) => ThemeCubit()), ], child: const MyHomePage(), ); } }
class MyHomePage extends StatefulWidget { const MyHomePage({super.key});
@override State<MyHomePage> createState() => _MyHomePageState(); }
class _MyHomePageState extends State<MyHomePage> { @override Widget build(BuildContext context) { return BlocBuilder<LanguageCubit, BaseCubitType<LanguageState>>( builder: (context, state) { if (state.eventName == LanguageState.notSet || state.eventName == LanguageState.loaded) { Initializer.instance.setAppDirection( state.data == CurrentLanguage.fa || state.data == CurrentLanguage.ar ? 'rtl' : 'ltr', ); return MaterialApp( builder: (context, child) { Widget error = const Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Text( 'خطا در نمابش اطلاعات', style: TextStyle( color: Colors.black, fontWeight: FontWeight.w700, fontSize: 18, ), textAlign: TextAlign.center, ), ], ), ); if (child is Scaffold || child is Navigator) { error = Scaffold( body: SafeArea( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ error, const Icon( Icons.error_outline_rounded, size: 130, color: Colors.red, ), ], ), ), ); } ErrorWidget.builder = (errorDetails) => error; return ScrollConfiguration( behavior: DisableScrollEffect().copyWith(scrollbars: false), child: Directionality( textDirection: Initializer.instance.getTextDirection(), child: child!, ), ); }, theme: Utils.instance.getAppTheme(context, state.data.value), debugShowCheckedModeBanner: false, supportedLocales: Translator.supportedLocales(), initialRoute: '/', routes: { '/': (context) => BlocProvider( create: (context) => SplashCubit(), child: const SplashScreen(), ), }, ); } return const SizedBox(); }, ); } }
|