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.

84 lines
2.5KB

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