feat: skip main page if authenticatd already

This commit is contained in:
sBubshait 2025-07-21 09:53:30 +03:00
parent 622db644fa
commit 0c7298e626

View File

@ -4,6 +4,7 @@ import 'firebase_options.dart';
import 'screens/home_screen.dart';
import 'services/notification_service.dart';
import 'services/auth_service.dart';
import 'services/user_service.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
@ -18,12 +19,95 @@ class MyApp extends StatelessWidget {
return MaterialApp(
title: 'Wesal',
theme: ThemeData(primarySwatch: Colors.blue, fontFamily: 'Roboto'),
home: LandingPage(),
home: SplashScreen(),
debugShowCheckedModeBanner: false,
);
}
}
class SplashScreen extends StatefulWidget {
@override
_SplashScreenState createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
@override
void initState() {
super.initState();
_checkAuthenticationStatus();
}
Future<void> _checkAuthenticationStatus() async {
await Future.delayed(Duration(milliseconds: 500));
final isLoggedIn = await AuthService.isLoggedIn();
if (isLoggedIn) {
final userResult = await UserService.getCurrentUser();
if (userResult['success'] == true) {
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (context) => HomeScreen()),
);
} else {
await AuthService.logout();
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (context) => LandingPage()),
);
}
} else {
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (context) => LandingPage()),
);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color(0xFF32B0A5),
Color(0xFF4600B9),
],
stops: [0.0, 0.5],
),
),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'وصال',
style: TextStyle(
fontSize: 160,
fontWeight: FontWeight.w200,
fontFamily: 'Blaka',
color: Colors.white,
shadows: [
Shadow(
offset: Offset(2, 2),
blurRadius: 4,
color: Colors.black.withOpacity(0.3),
),
],
),
),
SizedBox(height: 40),
CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
),
],
),
),
),
);
}
}
class LandingPage extends StatefulWidget {
@override
_LandingPageState createState() => _LandingPageState();
@ -251,6 +335,8 @@ class _SignInPageState extends State<SignInPage> {
});
if (result['success'] == true) {
final userResult = await UserService.getCurrentUser(forceRefresh: true);
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (context) => HomeScreen()),
);