feat: add splash,home,login page
This commit is contained in:
86
lib/page/splash_page.dart
Normal file
86
lib/page/splash_page.dart
Normal file
@@ -0,0 +1,86 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class SplashScreen extends StatefulWidget {
|
||||
const SplashScreen({super.key});
|
||||
|
||||
@override
|
||||
State<SplashScreen> createState() => _SplashScreenState();
|
||||
}
|
||||
|
||||
class _SplashScreenState extends State<SplashScreen> with WidgetsBindingObserver {
|
||||
bool _hasNavigated = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
_navigateToNextPage();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
super.didChangeAppLifecycleState(state);
|
||||
if (state == AppLifecycleState.resumed) {
|
||||
if (!_hasNavigated && mounted) {
|
||||
_navigateToNextPage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _navigateToNextPage() async {
|
||||
if (_hasNavigated) return;
|
||||
|
||||
await Future.delayed(const Duration(seconds: 2));
|
||||
|
||||
if (mounted && !_hasNavigated) {
|
||||
_hasNavigated = true;
|
||||
final bool isLoggedIn = false;
|
||||
|
||||
if (isLoggedIn) {
|
||||
Get.offAllNamed('/home');
|
||||
} else {
|
||||
Get.offAllNamed('/login');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoPageScaffold(
|
||||
backgroundColor: CupertinoColors.systemBlue,
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(
|
||||
CupertinoIcons.person_3,
|
||||
size: 100,
|
||||
color: CupertinoColors.white,
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
const Text(
|
||||
'Family Care',
|
||||
style: TextStyle(
|
||||
fontSize: 32,
|
||||
color: CupertinoColors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const CupertinoActivityIndicator(
|
||||
radius: 12,
|
||||
color: CupertinoColors.white,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user