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.

89 lines
2.7KB

  1. import 'package:farm_tpf/presentation/screens/login/view/login_page.dart';
  2. import 'package:farm_tpf/presentation/screens/slide_menu/navigation_home_screen.dart';
  3. import 'package:farm_tpf/presentation/screens/splash/view/splash_page.dart';
  4. import 'package:farm_tpf/presentation/screens/tabbar/tabbar.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 'package:google_fonts/google_fonts.dart';
  10. import 'authentication/bloc/authentication_bloc.dart';
  11. import 'data/repository/authentication_repository.dart';
  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. authenticationRepository: 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. break;
  64. case AuthenticationStatus.unauthenticated:
  65. _navigator.pushAndRemoveUntil<void>(
  66. LoginPage.route(),
  67. (route) => false,
  68. );
  69. break;
  70. default:
  71. break;
  72. }
  73. },
  74. child: child,
  75. );
  76. },
  77. onGenerateRoute: (_) => SplashPage.route(),
  78. );
  79. }
  80. }