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.

100 lines
3.2KB

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