mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-27 17:44:55 +00:00
- Add method to get token and validate in AuthCubit - Update AuthState with loading, success, and error states for token - Use BlocBuilder in SplashView for token validation and navigation This commit refactors the code in AuthCubit to include a method to get the token and validate it. It also updates the AuthState with loading, success, and error states for token handling. In SplashView, BlocBuilder is now used to handle token validation and navigation based on the token status.
63 lines
2.0 KiB
Dart
63 lines
2.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
import 'package:syncrow_app/features/auth/bloc/auth_cubit.dart';
|
|
import 'package:syncrow_app/generated/assets.dart';
|
|
import 'package:syncrow_app/navigation/routing_constants.dart';
|
|
|
|
class SplashView extends StatelessWidget {
|
|
const SplashView({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return BlocBuilder<AuthCubit, AuthState>(
|
|
builder: (context, state) {
|
|
if (state is AuthTokenSuccess) {
|
|
Future.delayed(const Duration(seconds: 1), () {
|
|
Navigator.pushReplacementNamed(context, Routes.homeRoute);
|
|
});
|
|
} else {
|
|
Future.delayed(const Duration(seconds: 1), () {
|
|
Navigator.pushReplacementNamed(context, Routes.authLogin);
|
|
});
|
|
}
|
|
|
|
return Scaffold(
|
|
body: Stack(
|
|
alignment: Alignment.center,
|
|
children: [
|
|
Container(
|
|
width: MediaQuery.sizeOf(context).width,
|
|
height: MediaQuery.sizeOf(context).height,
|
|
decoration: const BoxDecoration(
|
|
image: DecorationImage(
|
|
image: AssetImage(
|
|
Assets.imagesBackground,
|
|
),
|
|
fit: BoxFit.cover,
|
|
),
|
|
),
|
|
),
|
|
Container(
|
|
width: MediaQuery.sizeOf(context).width,
|
|
height: MediaQuery.sizeOf(context).height,
|
|
decoration: const BoxDecoration(
|
|
image: DecorationImage(
|
|
image: AssetImage(Assets.imagesVector),
|
|
fit: BoxFit.cover,
|
|
opacity: 0.9,
|
|
),
|
|
),
|
|
),
|
|
SvgPicture.asset(
|
|
Assets.imagesLogo,
|
|
width: 240,
|
|
)
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|