|
- import 'package:farm_tpf/presentation/screens/login/view/login_page.dart';
- import 'package:farm_tpf/presentation/screens/slide_menu/navigation_home_screen.dart';
- import 'package:farm_tpf/presentation/screens/splash/view/splash_page.dart';
- import 'package:farm_tpf/utils/const_color.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_bloc/flutter_bloc.dart';
- import 'package:get/get.dart';
-
- import 'authentication/bloc/authentication_bloc.dart';
- import 'data/repository/authentication_repository.dart';
-
- class App extends StatelessWidget {
- const App({
- Key key,
- @required this.authenticationRepository,
- }) : assert(authenticationRepository != null),
- super(key: key);
-
- final AuthenticationRepository authenticationRepository;
-
- @override
- Widget build(BuildContext context) {
- return RepositoryProvider.value(
- value: authenticationRepository,
- child: BlocProvider(
- create: (_) => AuthenticationBloc(
- authenticationRepository: authenticationRepository,
- ),
- child: AppView(),
- ),
- );
- }
- }
-
- class AppView extends StatefulWidget {
- @override
- _AppViewState createState() => _AppViewState();
- }
-
- class _AppViewState extends State<AppView> {
- final _navigatorKey = GlobalKey<NavigatorState>();
-
- NavigatorState get _navigator => _navigatorKey.currentState;
-
- @override
- Widget build(BuildContext context) {
- return GetMaterialApp(
- debugShowCheckedModeBanner: false,
- theme: ThemeData(
- backgroundColor: Colors.white,
- brightness: Brightness.light,
- primaryColor: COLOR_CONST.DEFAULT,
- accentColor: COLOR_CONST.DEFAULT,
- hoverColor: COLOR_CONST.GREEN,
- fontFamily: 'Roboto',
- ),
- navigatorKey: _navigatorKey,
- builder: (context, child) {
- return BlocListener<AuthenticationBloc, AuthenticationState>(
- listener: (context, state) {
- switch (state.status) {
- case AuthenticationStatus.authenticated:
- _navigator.pushAndRemoveUntil<void>(
- NavigationHomeScreen.route(),
- (route) => false,
- );
- break;
- case AuthenticationStatus.unauthenticated:
- _navigator.pushAndRemoveUntil<void>(
- LoginPage.route(),
- (route) => false,
- );
- break;
- default:
- break;
- }
- },
- child: child,
- );
- },
- onGenerateRoute: (_) => SplashPage.route(),
- );
- }
- }
|