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.

102 lines
3.3KB

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