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.

88 lines
2.6KB

  1. import 'package:farm_tpf/presentation/screens/login/view/login_page.dart';
  2. import 'package:farm_tpf/presentation/screens/splash/view/splash_page.dart';
  3. import 'package:farm_tpf/presentation/screens/tabbar/tabbar.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 'package:get/get.dart';
  8. import 'package:google_fonts/google_fonts.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: AppColors.DEFAULT,
  46. accentColor: AppColors.DEFAULT,
  47. hoverColor: AppColors.GREEN,
  48. textTheme: GoogleFonts.sairaTextTheme(
  49. Theme.of(context).textTheme,
  50. ),
  51. ),
  52. navigatorKey: _navigatorKey,
  53. builder: (context, child) {
  54. return BlocListener<AuthenticationBloc, AuthenticationState>(
  55. listener: (context, state) {
  56. switch (state.status) {
  57. case AuthenticationStatus.authenticated:
  58. _navigator.pushAndRemoveUntil<void>(
  59. TabbarScreen.route(),
  60. (route) => false,
  61. );
  62. break;
  63. case AuthenticationStatus.unauthenticated:
  64. _navigator.pushAndRemoveUntil<void>(
  65. LoginPage.route(),
  66. (route) => false,
  67. );
  68. break;
  69. default:
  70. break;
  71. }
  72. },
  73. child: child,
  74. );
  75. },
  76. onGenerateRoute: (_) => SplashPage.route(),
  77. );
  78. }
  79. }