diff --git a/lib/app.dart b/lib/app.dart index 284429d..4089e0f 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -294,6 +294,126 @@ class _AuthGateState extends State { }*/ @override + Widget build(BuildContext context) { + 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) { + return FutureBuilder( + future: _tryBiometric(), + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return const SplashScreen(); + } + + if (snapshot.data == true) { + return const NavigationScaffold(); // Authenticated + } + + // ❌ Biometric failed → Show MPIN screen + return MPinScreen( + mode: MPinMode.enter, + onCompleted: (_) { + Navigator.of(context).pushReplacement( + MaterialPageRoute( + builder: (_) => const NavigationScaffold(), + ), + ); + }, + ); + }, + ); + } else { + return MPinScreen( + mode: MPinMode.enter, + onCompleted: (_) { + Navigator.of(context).pushReplacement( + MaterialPageRoute( + builder: (_) => const NavigationScaffold(), + ), + ); + }, + ); + } + } else { + // No MPIN set → show MPIN set screen + biometric dialog + return MPinScreen( + mode: MPinMode.set, + onCompleted: (_) async { + final storage = getIt(); + final localAuth = LocalAuthentication(); + + final optIn = await showDialog( + context: context, + barrierDismissible: false, + builder: (ctx) => AlertDialog( + title: + Text(AppLocalizations.of(context).enableFingerprintLogin), + content: + Text(AppLocalizations.of(context).enableFingerprintMessage), + actions: [ + TextButton( + onPressed: () => Navigator.of(ctx).pop(false), + child: Text(AppLocalizations.of(context).no), + ), + TextButton( + onPressed: () => Navigator.of(ctx).pop(true), + child: Text(AppLocalizations.of(context).yes), + ), + ], + ), + ); + + if (optIn == true) { + final canCheck = await localAuth.canCheckBiometrics; + bool didAuth = false; + + if (canCheck) { + didAuth = await localAuth.authenticate( + localizedReason: + AppLocalizations.of(context).authenticateToEnable, + options: const AuthenticationOptions( + stickyAuth: true, + biometricOnly: true, + ), + ); + await storage.write( + 'biometric_enabled', didAuth ? 'true' : 'false'); + } else { + await storage.write('biometric_enabled', 'false'); + } + } + + Navigator.of(context).pushReplacement( + MaterialPageRoute( + builder: (_) => const NavigationScaffold(), + ), + ); + }, + ); + } + } + + // ✅ Step 3: If not logged in, show login screen + return const LoginScreen(); + } +} + +/*@override Widget build(BuildContext context) { if (_checking) { return const SplashScreen(); @@ -409,7 +529,7 @@ class _AuthGateState extends State { } return const LoginScreen(); } -} +}*/ class NavigationScaffold extends StatefulWidget { const NavigationScaffold({super.key}); diff --git a/lib/features/auth/screens/welcome_screen.dart b/lib/features/auth/screens/welcome_screen.dart index 3183b7c..12afb69 100644 --- a/lib/features/auth/screens/welcome_screen.dart +++ b/lib/features/auth/screens/welcome_screen.dart @@ -43,18 +43,18 @@ class _WelcomeScreenState extends State { children: [ Text( AppLocalizations.of(context).kconnect, - style: TextStyle( + style: const TextStyle( fontSize: 36, fontWeight: FontWeight.bold, color: Colors.white, letterSpacing: 1.5, ), ), - SizedBox(height: 12), + const SizedBox(height: 12), Text( AppLocalizations.of(context).kccBankFull, textAlign: TextAlign.center, - style: TextStyle( + style: const TextStyle( fontSize: 18, color: Colors.white, letterSpacing: 1.2, diff --git a/lib/features/dashboard/screens/dashboard_screen.dart b/lib/features/dashboard/screens/dashboard_screen.dart index 703ddb0..fac3aec 100644 --- a/lib/features/dashboard/screens/dashboard_screen.dart +++ b/lib/features/dashboard/screens/dashboard_screen.dart @@ -480,19 +480,13 @@ class _DashboardScreenState extends State { context, MaterialPageRoute( builder: (context) => - const FundTransferBeneficiaryScreen(), - ), - ); - }, - disable: true, - ), - _buildQuickLink( - Symbols.server_person, - AppLocalizations.of(context).accountInfo, - () { - Navigator.push( - context, - MaterialPageRoute( + const FundTransferBeneficiaryScreen())); + }, disable: true), + _buildQuickLink(Symbols.server_person, + AppLocalizations.of(context).accountInfo, () { + Navigator.push( + context, + MaterialPageRoute( builder: (context) => AccountInfoScreen( users: users, selectedIndex: selectedAccountIndex, @@ -509,48 +503,31 @@ class _DashboardScreenState extends State { context, MaterialPageRoute( builder: (context) => AccountStatementScreen( - accountNo: - users[selectedAccountIndex].accountNo!, - ), - ), - ); - }, - ), - _buildQuickLink( - Symbols.checkbook, - AppLocalizations.of(context).handleCheque, - () {}, - disable: true, - ), - _buildQuickLink( - Icons.group, - AppLocalizations.of(context).manageBeneficiary, - () { - Navigator.push( - context, - MaterialPageRoute( + accountNo: users[selectedAccountIndex] + .accountNo!, + ))); + }), + _buildQuickLink(Symbols.checkbook, + AppLocalizations.of(context).handleCheque, () {}, + disable: true), + _buildQuickLink(Icons.group, + AppLocalizations.of(context).manageBeneficiary, () { + Navigator.push( + context, + MaterialPageRoute( builder: (context) => - const ManageBeneficiariesScreen(), - ), - ); - }, - disable: true, - ), - _buildQuickLink( - Symbols.support_agent, - AppLocalizations.of(context).contactUs, - () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => const EnquiryScreen(), - ), - ); - }, - ), - ], - ), - const SizedBox(height: 5), + const ManageBeneficiariesScreen())); + }, disable: true), + _buildQuickLink(Symbols.support_agent, + AppLocalizations.of(context).contactUs, () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => const EnquiryScreen())); + }), + ], + ), + const SizedBox(height: 5), // Recent Transactions Text(