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.

107 lines
3.5KB

  1. import 'package:farm_tpf/presentation/screens/splash/view/splash_page.dart';
  2. import 'package:farm_tpf/presentation/screens/tabbar/tabbar.dart';
  3. import 'package:farm_tpf/utils/const_color.dart';
  4. import 'package:farm_tpf/utils/const_enum.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:flutter_bloc/flutter_bloc.dart';
  7. import 'package:flutter_screenutil/flutter_screenutil.dart';
  8. import 'package:get/get.dart';
  9. import 'authentication/bloc/authentication_bloc.dart';
  10. import 'data/repository/authentication_repository.dart';
  11. import 'presentation/screens/login/login_page.dart';
  12. import 'routes/routes.dart';
  13. import 'services/firebase_notification_service.dart';
  14. final GlobalKey<NavigatorState> globalNavigator = GlobalKey<NavigatorState>();
  15. class App extends StatelessWidget {
  16. const App({
  17. Key? key,
  18. required this.authenticationRepository,
  19. }) : assert(authenticationRepository != null),
  20. super(key: key);
  21. final AuthenticationRepository authenticationRepository;
  22. @override
  23. Widget build(BuildContext context) {
  24. return RepositoryProvider.value(
  25. value: authenticationRepository,
  26. child: BlocProvider(
  27. create: (_) => AuthenticationBloc(
  28. repository: authenticationRepository,
  29. ),
  30. child: AppView(),
  31. ),
  32. );
  33. }
  34. }
  35. class AppView extends StatefulWidget {
  36. @override
  37. _AppViewState createState() => _AppViewState();
  38. }
  39. class _AppViewState extends State<AppView> {
  40. // final _navigatorKey = GlobalKey<NavigatorState>();
  41. NavigatorState? get _navigator => globalNavigator.currentState;
  42. @override
  43. Widget build(BuildContext context) {
  44. return ScreenUtilInit(
  45. designSize: const Size(375, 812),
  46. minTextAdapt: true,
  47. splitScreenMode: true,
  48. builder: (BuildContext context, Widget? child) {
  49. return GetMaterialApp(
  50. debugShowCheckedModeBanner: false,
  51. theme: ThemeData(
  52. backgroundColor: Colors.white,
  53. brightness: Brightness.light,
  54. primaryColor: AppColors.DEFAULT,
  55. hoverColor: AppColors.GREEN,
  56. // textTheme: GoogleFonts.sairaTextTheme(
  57. // Theme.of(context).textTheme,
  58. // ),
  59. ),
  60. navigatorKey: globalNavigator,
  61. builder: (context, child) {
  62. return BlocListener<AuthenticationBloc, AuthenticationState>(
  63. listener: (context, state) {
  64. switch (state.status) {
  65. case AuthenticationStatus.authenticated:
  66. FirebaseNotificationService.initService();
  67. _navigator!.pushAndRemoveUntil<void>(
  68. Routes.dashboard(),
  69. (route) => false,
  70. );
  71. // Get.offAll(() => TabbarScreen());
  72. break;
  73. case AuthenticationStatus.unauthenticated:
  74. FirebaseNotificationService.initService();
  75. _navigator!.pushAndRemoveUntil<void>(
  76. Routes.login(),
  77. (route) => false,
  78. );
  79. // Get.offAll(() => const LoginPage());
  80. break;
  81. default:
  82. _navigator!.pushAndRemoveUntil<void>(
  83. Routes.login(),
  84. (route) => false,
  85. );
  86. break;
  87. }
  88. },
  89. child: child,
  90. );
  91. },
  92. onGenerateRoute: (_) => SplashPage.route(),
  93. );
  94. },
  95. );
  96. }
  97. }