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.
 
 
 
 
 
 

116 rivejä
3.8 KiB

  1. import 'package:firebase_core/firebase_core.dart';
  2. import 'package:firebase_messaging/firebase_messaging.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_localizations/flutter_localizations.dart';
  5. import 'package:hive_flutter/hive_flutter.dart';
  6. import 'package:provider/provider.dart';
  7. import 'package:qadirneyriz/config/config.dart';
  8. import 'package:qadirneyriz/firebase_options.dart';
  9. import 'package:qadirneyriz/global/global_state/global_state.dart';
  10. import 'package:qadirneyriz/router/router.dart';
  11. import 'package:flutter_gen/gen_l10n/app_localizations.dart';
  12. import 'package:qadirneyriz/screens/auth/state/state.dart';
  13. import 'package:qadirneyriz/screens/home/state.dart';
  14. import 'package:qadirneyriz/screens/meeting/state.dart';
  15. import 'package:qadirneyriz/screens/private_meeting/state.dart';
  16. import 'package:qadirneyriz/screens/report/state.dart';
  17. import 'package:qadirneyriz/setting/setting.dart';
  18. final FirebaseMessaging messaging = FirebaseMessaging.instance;
  19. Future<void> initializeApp() async {
  20. await Hive.initFlutter();
  21. await Firebase.initializeApp(
  22. options: DefaultFirebaseOptions.currentPlatform,
  23. );
  24. await setting.userLocalDb.openBox();
  25. }
  26. void main() async {
  27. WidgetsFlutterBinding.ensureInitialized();
  28. await initializeApp(); // Initialize Firebase and other services
  29. runApp(
  30. MultiProvider(
  31. providers: [
  32. ChangeNotifierProvider(create: (_) => GlobalState()),
  33. ChangeNotifierProvider(create: (_) => AuthState()),
  34. ChangeNotifierProvider(create: (_) => HomeState()),
  35. ChangeNotifierProvider(create: (_) => MeetingsState()),
  36. ChangeNotifierProvider(create: (_) => PrivateMeetingsState()),
  37. ChangeNotifierProvider(create: (_) => ReportState()),
  38. ],
  39. child: const MyApp(),
  40. ),
  41. );
  42. }
  43. class MyApp extends StatefulWidget {
  44. const MyApp({super.key});
  45. @override
  46. State<MyApp> createState() => FiltersItemInPrivateMeetingsReport();
  47. }
  48. class FiltersItemInPrivateMeetingsReport extends State<MyApp> {
  49. late AuthState state;
  50. String language = setting.userLocalDb.getUser().language;
  51. @override
  52. void initState() {
  53. super.initState();
  54. Future.delayed(Duration.zero, () async {
  55. state = Provider.of<AuthState>(context, listen: false);
  56. setState(() {
  57. language = state.language;
  58. });
  59. });
  60. }
  61. @override
  62. Widget build(BuildContext context) {
  63. return Consumer<AuthState>(
  64. builder: (context, value, child) {
  65. return GestureDetector(
  66. behavior: HitTestBehavior.opaque,
  67. onTap: () {
  68. FocusScopeNode currentFocus = FocusScope.of(context);
  69. if (!currentFocus.hasPrimaryFocus &&
  70. currentFocus.focusedChild != null) {
  71. FocusManager.instance.primaryFocus?.unfocus();
  72. }
  73. },
  74. child: MaterialApp.router(
  75. theme: ThemeData(
  76. colorScheme: ColorScheme.light(primary: config.ui.mainGreen),
  77. buttonTheme: ButtonThemeData(
  78. colorScheme: ColorScheme.light(primary: Colors.green),
  79. ),
  80. useMaterial3: true,
  81. fontFamily: 'Font',
  82. scaffoldBackgroundColor: Colors.white,
  83. ),
  84. debugShowCheckedModeBanner: false,
  85. routerDelegate: router.routerDelegate,
  86. routeInformationParser: router.routeInformationParser,
  87. routeInformationProvider: router.routeInformationProvider,
  88. localizationsDelegates: const [
  89. AppLocalizations.delegate,
  90. GlobalMaterialLocalizations.delegate,
  91. GlobalWidgetsLocalizations.delegate,
  92. GlobalCupertinoLocalizations.delegate,
  93. ],
  94. locale: Locale(value.language),
  95. supportedLocales: const [
  96. Locale('en'),
  97. Locale('fa'),
  98. ],
  99. ),
  100. );
  101. },
  102. );
  103. }
  104. }