Sonnat Project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
3.9 KiB

2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
2 years ago
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/services.dart';
  3. import 'package:flutter_bloc/flutter_bloc.dart';
  4. import 'package:sonnat/core/language/language_cubit.dart';
  5. import 'package:sonnat/core/language/translator.dart';
  6. import 'package:sonnat/core/theme/cubit/theme_cubit.dart';
  7. import 'package:sonnat/core/utils/app_utils.dart';
  8. import 'package:sonnat/core/utils/base_cubit_type.dart';
  9. import 'package:sonnat/core/utils/initializer.dart';
  10. import 'package:sonnat/features/splash/cubit/splash_cubit.dart';
  11. import 'package:sonnat/features/splash/screen/splash_screen.dart';
  12. void main() async {
  13. WidgetsFlutterBinding.ensureInitialized();
  14. await Initializer.instance.initialHive();
  15. runApp(const MyApp());
  16. }
  17. class MyApp extends StatelessWidget {
  18. const MyApp({super.key});
  19. @override
  20. Widget build(BuildContext context) {
  21. SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
  22. SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []);
  23. return MultiBlocProvider(
  24. providers: [
  25. BlocProvider(create: (context) => LanguageCubit()),
  26. BlocProvider(create: (context) => ThemeCubit()),
  27. ],
  28. child: const MyHomePage(),
  29. );
  30. }
  31. }
  32. class MyHomePage extends StatefulWidget {
  33. const MyHomePage({super.key});
  34. @override
  35. State<MyHomePage> createState() => _MyHomePageState();
  36. }
  37. class _MyHomePageState extends State<MyHomePage> {
  38. @override
  39. Widget build(BuildContext context) {
  40. return BlocBuilder<LanguageCubit, BaseCubitType<LanguageState>>(
  41. builder: (context, state) {
  42. if (state.eventName == LanguageState.notSet || state.eventName == LanguageState.loaded) {
  43. Initializer.instance.setAppDirection(
  44. state.data == CurrentLanguage.fa || state.data == CurrentLanguage.ar ? 'rtl' : 'ltr',
  45. );
  46. return MaterialApp(
  47. builder: (context, child) {
  48. Widget error = const Center(
  49. child: Column(
  50. mainAxisAlignment: MainAxisAlignment.center,
  51. children: [
  52. Text(
  53. 'خطا در نمابش اطلاعات',
  54. style: TextStyle(
  55. color: Colors.black,
  56. fontWeight: FontWeight.w700,
  57. fontSize: 18,
  58. ),
  59. textAlign: TextAlign.center,
  60. ),
  61. ],
  62. ),
  63. );
  64. if (child is Scaffold || child is Navigator) {
  65. error = Scaffold(
  66. body: SafeArea(
  67. child: Column(
  68. mainAxisAlignment: MainAxisAlignment.center,
  69. children: [
  70. error,
  71. const Icon(
  72. Icons.error_outline_rounded,
  73. size: 130,
  74. color: Colors.red,
  75. ),
  76. ],
  77. ),
  78. ),
  79. );
  80. }
  81. ErrorWidget.builder = (errorDetails) => error;
  82. return ScrollConfiguration(
  83. behavior: DisableScrollEffect().copyWith(scrollbars: false),
  84. child: Directionality(
  85. textDirection: Initializer.instance.getTextDirection(),
  86. child: child!,
  87. ),
  88. );
  89. },
  90. theme: Utils.instance.getAppTheme(context, state.data.value),
  91. debugShowCheckedModeBanner: false,
  92. supportedLocales: Translator.supportedLocales(),
  93. initialRoute: '/',
  94. routes: {
  95. '/': (context) => BlocProvider(
  96. create: (context) => SplashCubit(),
  97. child: const SplashScreen(),
  98. ),
  99. },
  100. );
  101. }
  102. return const SizedBox();
  103. },
  104. );
  105. }
  106. }