auth state

This commit is contained in:
efrilm
2025-10-24 02:02:00 +07:00
parent ca5d2a58e7
commit 59062f9af1
7 changed files with 930 additions and 9 deletions
+25 -9
View File
@@ -1,6 +1,8 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../../application/auth/auth_bloc.dart';
import '../../components/assets/assets.gen.dart';
import '../../router/app_router.gr.dart';
@@ -15,7 +17,11 @@ class SplashPage extends StatefulWidget {
class _SplashPageState extends State<SplashPage> {
_startDelay() => Future.delayed(const Duration(seconds: 2), _goNext);
_goNext() => context.router.replace(const LoginRoute());
_goNext() {
if (mounted) {
context.read<AuthBloc>().add(const AuthEvent.fetchCurrentUser());
}
}
@override
void initState() {
@@ -25,14 +31,24 @@ class _SplashPageState extends State<SplashPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Padding(
padding: const EdgeInsets.all(20),
child: Assets.images.logo.image(
width: 100,
height: 100,
fit: BoxFit.contain,
return BlocListener<AuthBloc, AuthState>(
listenWhen: (previous, current) => previous.status != current.status,
listener: (context, state) {
if (state.isAuthenticated) {
context.router.replace(const MainRoute());
} else {
context.router.replace(const LoginRoute());
}
},
child: Scaffold(
body: Center(
child: Padding(
padding: const EdgeInsets.all(20),
child: Assets.images.logo.image(
width: 100,
height: 100,
fit: BoxFit.contain,
),
),
),
),