diff --git a/lib/main.dart b/lib/main.dart index fdc23fa..b7b4dd0 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -18,6 +18,7 @@ import 'package:zenith_monitor/modules/map/screen/map_screen.dart'; import 'package:zenith_monitor/modules/signup/screen/sign_up_screen.dart'; import 'package:zenith_monitor/utils/ui/animations/zenith_progress_indicator.dart'; import 'package:zenith_monitor/modules/login/screen/login_screen.dart'; +import 'package:firebase_auth/firebase_auth.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); @@ -42,17 +43,22 @@ class Application extends StatelessWidget { final Future _initialization = Firebase.initializeApp(); @override Widget build(BuildContext context) { - UsbManager usbManager = UsbManager(); - FirestoreServices fireServices = FirestoreServices(); + // UsbManager usbManager = UsbManager(); + // FirestoreServices fireServices = FirestoreServices(); return MultiBlocProvider( providers: [ BlocProvider(create: (context) => LoginBloc(auth: GoogleAuth())), + // BlocProvider( + // create: (context) => + // DataBloc(usbManager: usbManager, fireServices: fireServices)), + // BlocProvider( + // create: (context) => MapDataBloc( + // usbManager: usbManager, fireServices: fireServices)), BlocProvider( create: (context) => - DataBloc(usbManager: usbManager, fireServices: fireServices)), - BlocProvider( - create: (context) => MapDataBloc( - usbManager: usbManager, fireServices: fireServices)), + TerminalBloc(dataBloc: BlocProvider.of(context))), + + BlocProvider(create: (context) => LoginBloc(auth: GoogleAuth())), BlocProvider( create: (context) => TerminalBloc(dataBloc: BlocProvider.of(context))), @@ -65,6 +71,8 @@ class Application extends StatelessWidget { } if (snapshot.connectionState == ConnectionState.done) { + final User? currentUser = FirebaseAuth.instance.currentUser; + return MaterialApp( showPerformanceOverlay: false, // shows fps debugShowCheckedModeBanner: false, @@ -74,7 +82,8 @@ class Application extends StatelessWidget { backgroundColor: Colors.black.withOpacity(0)), primaryColor: Colors.black, ), - initialRoute: '/login', + initialRoute: currentUser != null ? '/home' : '/login', + // initialRoute: '/login', routes: { '/login': (context) => const LoginScreen(), '/signup': (context) => const SignUpScreen(), diff --git a/lib/modules/login/bloc/login_bloc.dart b/lib/modules/login/bloc/login_bloc.dart index 9b54350..6d6c18b 100644 --- a/lib/modules/login/bloc/login_bloc.dart +++ b/lib/modules/login/bloc/login_bloc.dart @@ -34,11 +34,12 @@ class LoginBloc extends Bloc { Future _onSignOut(SignOutEvent event, Emitter emit) async { await _auth.signOut(); - Navigator.pushAndRemoveUntil( - // ignore: use_build_context_synchronously - event.context, - MaterialPageRoute(builder: (BuildContext context) => const LoginScreen()), - ModalRoute.withName('/login'), - ); + emit(SignOutSuccess()); + // Navigator.pushAndRemoveUntil( + // // ignore: use_build_context_synchronously + // event.context, + // MaterialPageRoute(builder: (BuildContext context) => const LoginScreen()), + // ModalRoute.withName('/login'), + // ); } } diff --git a/lib/modules/login/bloc/login_state.dart b/lib/modules/login/bloc/login_state.dart index fe9d271..7fd28c8 100644 --- a/lib/modules/login/bloc/login_state.dart +++ b/lib/modules/login/bloc/login_state.dart @@ -19,3 +19,7 @@ class LoadingState extends LoginState {} class LoginSuccess extends LoginState { LoginSuccess(LocalUser newUser) : super(user: newUser); } + +class SignOutSuccess extends LoginState {} + +class CheckSessionEvent extends LoginEvent {} diff --git a/lib/widgets/login.dart b/lib/widgets/login.dart index 6bc2764..39b631d 100644 --- a/lib/widgets/login.dart +++ b/lib/widgets/login.dart @@ -43,6 +43,9 @@ class LoginWidgetState extends State { if (state is LoginSuccess) { Navigator.popAndPushNamed(context, '/home'); } + if (state is SignOutSuccess) { + Navigator.popAndPushNamed(context, '/login'); + } }, builder: (context, state) { if (state is LoadingState) {