2025-10-23 22:16:53 +07:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
2025-10-24 02:02:00 +07:00
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2025-10-23 22:16:53 +07:00
|
|
|
|
2025-10-24 02:02:00 +07:00
|
|
|
import '../../../application/auth/auth_bloc.dart';
|
2025-10-24 01:16:50 +07:00
|
|
|
import '../../components/assets/assets.gen.dart';
|
|
|
|
|
import '../../router/app_router.gr.dart';
|
|
|
|
|
|
2025-10-23 22:16:53 +07:00
|
|
|
@RoutePage()
|
|
|
|
|
class SplashPage extends StatefulWidget {
|
|
|
|
|
const SplashPage({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<SplashPage> createState() => _SplashPageState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _SplashPageState extends State<SplashPage> {
|
2025-10-24 01:16:50 +07:00
|
|
|
_startDelay() => Future.delayed(const Duration(seconds: 2), _goNext);
|
|
|
|
|
|
2025-10-24 02:02:00 +07:00
|
|
|
_goNext() {
|
|
|
|
|
if (mounted) {
|
|
|
|
|
context.read<AuthBloc>().add(const AuthEvent.fetchCurrentUser());
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-10-24 01:16:50 +07:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
_startDelay();
|
|
|
|
|
super.initState();
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-23 22:16:53 +07:00
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2025-10-24 02:02:00 +07:00
|
|
|
return BlocListener<AuthBloc, AuthState>(
|
|
|
|
|
listenWhen: (previous, current) => previous.status != current.status,
|
|
|
|
|
listener: (context, state) {
|
|
|
|
|
if (state.isAuthenticated) {
|
2025-10-24 20:06:42 +07:00
|
|
|
context.router.replace(const SyncRoute());
|
2025-10-24 02:02:00 +07:00
|
|
|
} 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,
|
|
|
|
|
),
|
2025-10-24 01:16:50 +07:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
2025-10-23 22:16:53 +07:00
|
|
|
}
|
|
|
|
|
}
|