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.

86 lines
2.6KB

  1. import 'package:farm_tpf/presentation/screens/home/view/home_page.dart';
  2. import 'package:farm_tpf/presentation/screens/login/view/login_page.dart';
  3. import 'package:farm_tpf/presentation/screens/slide_menu/navigation_home_screen.dart';
  4. import 'package:farm_tpf/presentation/screens/splash/view/splash_page.dart';
  5. import 'package:farm_tpf/utils/const_color.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:flutter_bloc/flutter_bloc.dart';
  8. import 'package:get/get.dart';
  9. import 'authentication/bloc/authentication_bloc.dart';
  10. import 'data/repository/authentication_repository.dart';
  11. class App extends StatelessWidget {
  12. const App({
  13. Key key,
  14. @required this.authenticationRepository,
  15. }) : assert(authenticationRepository != null),
  16. super(key: key);
  17. final AuthenticationRepository authenticationRepository;
  18. @override
  19. Widget build(BuildContext context) {
  20. return RepositoryProvider.value(
  21. value: authenticationRepository,
  22. child: BlocProvider(
  23. create: (_) => AuthenticationBloc(
  24. authenticationRepository: authenticationRepository,
  25. ),
  26. child: AppView(),
  27. ),
  28. );
  29. }
  30. }
  31. class AppView extends StatefulWidget {
  32. @override
  33. _AppViewState createState() => _AppViewState();
  34. }
  35. class _AppViewState extends State<AppView> {
  36. final _navigatorKey = GlobalKey<NavigatorState>();
  37. NavigatorState get _navigator => _navigatorKey.currentState;
  38. @override
  39. Widget build(BuildContext context) {
  40. return GetMaterialApp(
  41. debugShowCheckedModeBanner: false,
  42. theme: ThemeData(
  43. backgroundColor: Colors.white,
  44. brightness: Brightness.light,
  45. primaryColor: COLOR_CONST.DEFAULT,
  46. accentColor: COLOR_CONST.DEFAULT,
  47. hoverColor: COLOR_CONST.GREEN,
  48. fontFamily: 'Roboto',
  49. ),
  50. navigatorKey: _navigatorKey,
  51. builder: (context, child) {
  52. return BlocListener<AuthenticationBloc, AuthenticationState>(
  53. listener: (context, state) {
  54. switch (state.status) {
  55. case AuthenticationStatus.authenticated:
  56. _navigator.pushAndRemoveUntil<void>(
  57. NavigationHomeScreen.route(),
  58. (route) => false,
  59. );
  60. break;
  61. case AuthenticationStatus.unauthenticated:
  62. _navigator.pushAndRemoveUntil<void>(
  63. LoginPage.route(),
  64. (route) => false,
  65. );
  66. break;
  67. default:
  68. break;
  69. }
  70. },
  71. child: child,
  72. );
  73. },
  74. onGenerateRoute: (_) => SplashPage.route(),
  75. );
  76. }
  77. }