removed some unnecessary code and add some async guards
This commit is contained in:
45
lib/app.dart
45
lib/app.dart
@@ -40,7 +40,7 @@ class _KMobileState extends State<KMobile> {
|
|||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
loadPreferences();
|
loadPreferences();
|
||||||
Future.delayed(const Duration(seconds: 2), () {
|
Future.delayed(const Duration(seconds: 3), () {
|
||||||
setState(() {
|
setState(() {
|
||||||
showSplash = false;
|
showSplash = false;
|
||||||
});
|
});
|
||||||
@@ -67,7 +67,6 @@ class _KMobileState extends State<KMobile> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// Set status bar color and brightness
|
|
||||||
SystemChrome.setSystemUIOverlayStyle(
|
SystemChrome.setSystemUIOverlayStyle(
|
||||||
const SystemUiOverlayStyle(
|
const SystemUiOverlayStyle(
|
||||||
statusBarColor: Colors.transparent,
|
statusBarColor: Colors.transparent,
|
||||||
@@ -119,7 +118,6 @@ class AuthGate extends StatefulWidget {
|
|||||||
class _AuthGateState extends State<AuthGate> {
|
class _AuthGateState extends State<AuthGate> {
|
||||||
bool _checking = true;
|
bool _checking = true;
|
||||||
bool _isLoggedIn = false;
|
bool _isLoggedIn = false;
|
||||||
bool _showWelcome = true;
|
|
||||||
bool _hasMPin = false;
|
bool _hasMPin = false;
|
||||||
bool _biometricEnabled = false;
|
bool _biometricEnabled = false;
|
||||||
bool _biometricTried = false;
|
bool _biometricTried = false;
|
||||||
@@ -175,18 +173,7 @@ class _AuthGateState extends State<AuthGate> {
|
|||||||
if (_checking) {
|
if (_checking) {
|
||||||
return const SplashScreen();
|
return const SplashScreen();
|
||||||
}
|
}
|
||||||
// ✅ Step 1: Show welcome screen first, only once
|
|
||||||
if (_showWelcome) {
|
|
||||||
return WelcomeScreen(
|
|
||||||
onContinue: () {
|
|
||||||
setState(() {
|
|
||||||
_showWelcome = false;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ✅ Step 2: Check login status
|
|
||||||
if (_isLoggedIn) {
|
if (_isLoggedIn) {
|
||||||
if (_hasMPin) {
|
if (_hasMPin) {
|
||||||
if (_biometricEnabled) {
|
if (_biometricEnabled) {
|
||||||
@@ -201,7 +188,6 @@ class _AuthGateState extends State<AuthGate> {
|
|||||||
return const NavigationScaffold(); // Authenticated
|
return const NavigationScaffold(); // Authenticated
|
||||||
}
|
}
|
||||||
|
|
||||||
// ❌ Biometric failed → Show MPIN screen
|
|
||||||
return MPinScreen(
|
return MPinScreen(
|
||||||
mode: MPinMode.enter,
|
mode: MPinMode.enter,
|
||||||
onCompleted: (_) {
|
onCompleted: (_) {
|
||||||
@@ -227,7 +213,6 @@ class _AuthGateState extends State<AuthGate> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// No MPIN set → show MPIN set screen + biometric dialog
|
|
||||||
return MPinScreen(
|
return MPinScreen(
|
||||||
mode: MPinMode.set,
|
mode: MPinMode.set,
|
||||||
onCompleted: (_) async {
|
onCompleted: (_) async {
|
||||||
@@ -289,8 +274,6 @@ class _AuthGateState extends State<AuthGate> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ✅ Step 3: If not logged in, show login screen
|
|
||||||
return const LoginScreen();
|
return const LoginScreen();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -382,29 +365,6 @@ class _NavigationScaffoldState extends State<NavigationScaffold> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class SplashScreen extends StatelessWidget {
|
|
||||||
const SplashScreen({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
body: Center(
|
|
||||||
child: Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
const CircularProgressIndicator(),
|
|
||||||
const SizedBox(height: 20),
|
|
||||||
Text(
|
|
||||||
AppLocalizations.of(context).loading,
|
|
||||||
style: Theme.of(context).textTheme.headlineMedium,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add this widget at the end of the file
|
// Add this widget at the end of the file
|
||||||
class BiometricPromptScreen extends StatelessWidget {
|
class BiometricPromptScreen extends StatelessWidget {
|
||||||
final VoidCallback onCompleted;
|
final VoidCallback onCompleted;
|
||||||
@@ -466,6 +426,9 @@ class BiometricPromptScreen extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
if (!context.mounted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (result == true) {
|
if (result == true) {
|
||||||
await _handleBiometric(context);
|
await _handleBiometric(context);
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user