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.

92 lines
2.8KB

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