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() {
|
||||
super.initState();
|
||||
loadPreferences();
|
||||
Future.delayed(const Duration(seconds: 2), () {
|
||||
Future.delayed(const Duration(seconds: 3), () {
|
||||
setState(() {
|
||||
showSplash = false;
|
||||
});
|
||||
@@ -67,7 +67,6 @@ class _KMobileState extends State<KMobile> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Set status bar color and brightness
|
||||
SystemChrome.setSystemUIOverlayStyle(
|
||||
const SystemUiOverlayStyle(
|
||||
statusBarColor: Colors.transparent,
|
||||
@@ -119,7 +118,6 @@ class AuthGate extends StatefulWidget {
|
||||
class _AuthGateState extends State<AuthGate> {
|
||||
bool _checking = true;
|
||||
bool _isLoggedIn = false;
|
||||
bool _showWelcome = true;
|
||||
bool _hasMPin = false;
|
||||
bool _biometricEnabled = false;
|
||||
bool _biometricTried = false;
|
||||
@@ -175,18 +173,7 @@ class _AuthGateState extends State<AuthGate> {
|
||||
if (_checking) {
|
||||
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 (_hasMPin) {
|
||||
if (_biometricEnabled) {
|
||||
@@ -201,7 +188,6 @@ class _AuthGateState extends State<AuthGate> {
|
||||
return const NavigationScaffold(); // Authenticated
|
||||
}
|
||||
|
||||
// ❌ Biometric failed → Show MPIN screen
|
||||
return MPinScreen(
|
||||
mode: MPinMode.enter,
|
||||
onCompleted: (_) {
|
||||
@@ -227,7 +213,6 @@ class _AuthGateState extends State<AuthGate> {
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// No MPIN set → show MPIN set screen + biometric dialog
|
||||
return MPinScreen(
|
||||
mode: MPinMode.set,
|
||||
onCompleted: (_) async {
|
||||
@@ -289,8 +274,6 @@ class _AuthGateState extends State<AuthGate> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ✅ Step 3: If not logged in, show login screen
|
||||
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
|
||||
class BiometricPromptScreen extends StatelessWidget {
|
||||
final VoidCallback onCompleted;
|
||||
@@ -466,6 +426,9 @@ class BiometricPromptScreen extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
);
|
||||
if (!context.mounted) {
|
||||
return;
|
||||
}
|
||||
if (result == true) {
|
||||
await _handleBiometric(context);
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user