main.dart 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // ignore_for_file: unused_field, use_build_context_synchronously
  2. import 'package:animated_splash_screen/animated_splash_screen.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_localizations/flutter_localizations.dart';
  5. import 'package:gozap_oe/views/dashboard/dashboard_view.dart';
  6. import 'package:gozap_package/components/DB/db.dart';
  7. import 'package:gozap_package/components/common.dart';
  8. import 'package:gozap_package/components/localization/app_translations_delegate.dart';
  9. import 'package:gozap_package/components/localization/application.dart';
  10. import 'package:gozap_package/components/themes/themes.dart';
  11. import 'package:gozap_package/controllers/extentions/trycatch.dart';
  12. import 'package:gozap_package/gozap_package.dart';
  13. import 'package:gozap_package/models/common.dart';
  14. import 'package:gozap_package/models/user/user_model.dart';
  15. import 'package:gozap_package/views/log_in/log_in_view.dart';
  16. import 'package:provider/provider.dart';
  17. import 'package:toast/toast.dart';
  18. void main() {
  19. runApp(MultiProvider(providers: [
  20. ChangeNotifierProvider(create: (_) => LocalDB()),
  21. ChangeNotifierProvider(create: (_) => userChangeNotifier()),
  22. ChangeNotifierProvider(create: (_) => commonChangeNotifier()),
  23. ], child: const MyApp()));
  24. }
  25. class MyApp extends StatefulWidget {
  26. const MyApp({super.key});
  27. @override
  28. State<MyApp> createState() => _MyAppState();
  29. }
  30. class _MyAppState extends State<MyApp> {
  31. late AppTranslationsDelegate _newLocaleDelegate;
  32. UserModule? user;
  33. @override
  34. void initState() {
  35. _newLocaleDelegate = const AppTranslationsDelegate(newLocale: null);
  36. application.onLocaleChanged = onLocaleChange;
  37. super.initState();
  38. checkUser.callAndAbsorbError();
  39. }
  40. checkUser() async {
  41. await Provider.of<userChangeNotifier>(context, listen: false).get(context);
  42. setState(() {
  43. user = Provider.of<userChangeNotifier>(context, listen: false).user;
  44. });
  45. Provider.of<commonChangeNotifier>(context,listen: false).set(context, "https://api.gofuel.in/");
  46. }
  47. void onLocaleChange(Locale locale) {
  48. setState(() {
  49. _newLocaleDelegate = AppTranslationsDelegate(newLocale: locale);
  50. });
  51. }
  52. // This widget is the root of your application.
  53. @override
  54. Widget build(BuildContext context) {
  55. ToastContext().init(context);
  56. return MaterialApp(
  57. title: 'GoZAP OE',
  58. theme: ThemeData(
  59. fontFamily: 'Eras',
  60. primarySwatch: buildMaterialColor(AppTheme.primaryColor)
  61. ),
  62. localizationsDelegates: const [
  63. AppTranslationsDelegate(),
  64. //provides localised strings
  65. GlobalMaterialLocalizations.delegate,
  66. //provides RTL support
  67. GlobalWidgetsLocalizations.delegate,
  68. ],
  69. supportedLocales: application.supportedLocales(),
  70. home: AnimatedSplashScreen(
  71. duration: 3000,
  72. splashIconSize: 300.0,
  73. splash: Container(
  74. child: Common.goFuelLogoWidget(context),
  75. ),
  76. nextScreen: user != null
  77. ? const DashboardView()
  78. : LogInView(
  79. nextScreen: const DashboardView(),
  80. ),
  81. backgroundColor: AppTheme.secondaryColor,
  82. splashTransition: SplashTransition.fadeTransition,
  83. ),
  84. );
  85. }
  86. }