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.

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