Shared Preferences implementation
This commit is contained in:
84
lib/app.dart
84
lib/app.dart
@@ -16,6 +16,7 @@ import 'features/service/screens/service_screen.dart';
|
||||
import 'features/dashboard/screens/dashboard_screen.dart';
|
||||
import 'features/auth/screens/mpin_screen.dart';
|
||||
import 'package:local_auth/local_auth.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class KMobile extends StatefulWidget {
|
||||
const KMobile({super.key});
|
||||
@@ -24,18 +25,19 @@ class KMobile extends StatefulWidget {
|
||||
State<KMobile> createState() => _KMobileState();
|
||||
|
||||
static void setLocale(BuildContext context, Locale newLocale) {
|
||||
final _KMobileState? state = context
|
||||
.findAncestorStateOfType<_KMobileState>();
|
||||
final _KMobileState? state = context.findAncestorStateOfType<_KMobileState>();
|
||||
state?.setLocale(newLocale);
|
||||
}
|
||||
}
|
||||
|
||||
class _KMobileState extends State<KMobile> {
|
||||
bool _showSplash = false;
|
||||
Locale? _locale;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadLocale();
|
||||
// Simulate a splash screen delay
|
||||
Future.delayed(const Duration(seconds: 2), () {
|
||||
setState(() {
|
||||
@@ -44,8 +46,17 @@ class _KMobileState extends State<KMobile> {
|
||||
});
|
||||
}
|
||||
|
||||
Locale? _locale;
|
||||
Future<void> _loadLocale() async{
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final String? langCode = prefs.getString('locale');
|
||||
if (langCode != null) {
|
||||
setState(() {
|
||||
_locale = Locale(langCode);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setLocale(Locale locale) {
|
||||
setState(() {
|
||||
_locale = locale;
|
||||
@@ -101,38 +112,43 @@ class _KMobileState extends State<KMobile> {
|
||||
}
|
||||
*/
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Set status bar color
|
||||
SystemChrome.setSystemUIOverlayStyle(
|
||||
const SystemUiOverlayStyle(
|
||||
statusBarColor: Colors.transparent,
|
||||
statusBarIconBrightness: Brightness.dark,
|
||||
),
|
||||
);
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Set status bar color
|
||||
SystemChrome.setSystemUIOverlayStyle(
|
||||
const SystemUiOverlayStyle(
|
||||
statusBarColor: Colors.transparent,
|
||||
statusBarIconBrightness: Brightness.dark,
|
||||
),
|
||||
);
|
||||
|
||||
return MultiBlocProvider(
|
||||
providers: [BlocProvider<AuthCubit>(create: (_) => getIt<AuthCubit>())],
|
||||
child: MaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
locale: _locale, // Use your existing locale variable
|
||||
supportedLocales: const [Locale('en'), Locale('hi')],
|
||||
localizationsDelegates: const [
|
||||
AppLocalizations.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
title: 'kMobile',
|
||||
theme: AppThemes.lightTheme,
|
||||
// darkTheme: AppThemes.darkTheme,
|
||||
themeMode: ThemeMode.system, // Use system theme by default
|
||||
onGenerateRoute: AppRoutes.generateRoute,
|
||||
initialRoute: AppRoutes.splash,
|
||||
home: _showSplash ? const SplashScreen() : const AuthGate(),
|
||||
),
|
||||
);
|
||||
}
|
||||
return MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider<AuthCubit>(create: (_) => getIt<AuthCubit>()),
|
||||
],
|
||||
child: MaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
locale: _locale, // Dynamic locale
|
||||
supportedLocales: const [
|
||||
Locale('en'),
|
||||
Locale('hi'),
|
||||
],
|
||||
localizationsDelegates: const [
|
||||
AppLocalizations.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
title: 'kMobile',
|
||||
theme: AppThemes.lightTheme,
|
||||
// darkTheme: AppThemes.darkTheme,
|
||||
themeMode: ThemeMode.system,
|
||||
onGenerateRoute: AppRoutes.generateRoute,
|
||||
initialRoute: AppRoutes.splash,
|
||||
home: _showSplash ? const SplashScreen() : const AuthGate(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class AuthGate extends StatefulWidget {
|
||||
|
@@ -116,7 +116,7 @@ class AppThemes {
|
||||
foregroundColor: Color(0xFF212121),
|
||||
centerTitle: true,
|
||||
),
|
||||
cardTheme: CardThemeData(
|
||||
cardTheme: CardTheme(
|
||||
//Earlier CardThemeData
|
||||
elevation: 2,
|
||||
shape: RoundedRectangleBorder(
|
||||
@@ -200,7 +200,7 @@ class AppThemes {
|
||||
foregroundColor: Colors.white,
|
||||
centerTitle: true,
|
||||
),
|
||||
cardTheme: CardThemeData(
|
||||
cardTheme: CardTheme(
|
||||
//Earlier was CardThemeData
|
||||
elevation: 2,
|
||||
shape: RoundedRectangleBorder(
|
||||
|
@@ -1,8 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../l10n/app_localizations.dart';
|
||||
import 'package:kmobile/app.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class LanguageDialog extends StatelessWidget {
|
||||
/*class LanguageDialog extends StatelessWidget {
|
||||
const LanguageDialog({super.key});
|
||||
|
||||
String getLocaleName(AppLocalizations localizations, String code) {
|
||||
@@ -47,3 +48,37 @@ class LanguageDialog extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
class LanguageDialog extends StatelessWidget {
|
||||
const LanguageDialog({Key? key}) : super(key: key);
|
||||
|
||||
Future<void> _setLocale(BuildContext context, String langCode) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString('locale', langCode); // Save selected language
|
||||
KMobile.setLocale(context, Locale(langCode)); // Update locale in app
|
||||
Navigator.of(context).pop(); // Close the dialog
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text(AppLocalizations.of(context).selectLanguage),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.language),
|
||||
title: const Text('English'),
|
||||
onTap: () => _setLocale(context, 'en'),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.language),
|
||||
title: const Text('हिन्दी'),
|
||||
onTap: () => _setLocale(context, 'hi'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@@ -218,6 +218,6 @@
|
||||
"enterMPIN": "अपना mPIN दर्ज करें",
|
||||
"setMPIN": "अपना mPIN सेट करें",
|
||||
"confirmMPIN": "अपना mPIN की पुष्टि करें",
|
||||
"kconnect": "केकनेक्ट",
|
||||
"kconnect": "के-कनेक्ट",
|
||||
"kccBankFull": "कांगड़ा सेंट्रल को-ऑपरेटिव बैंक"
|
||||
}
|
||||
|
@@ -62,8 +62,7 @@ import 'app_localizations_hi.dart';
|
||||
/// be consistent with the languages listed in the AppLocalizations.supportedLocales
|
||||
/// property.
|
||||
abstract class AppLocalizations {
|
||||
AppLocalizations(String locale)
|
||||
: localeName = intl.Intl.canonicalizedLocale(locale.toString());
|
||||
AppLocalizations(String locale) : localeName = intl.Intl.canonicalizedLocale(locale.toString());
|
||||
|
||||
final String localeName;
|
||||
|
||||
@@ -71,8 +70,7 @@ abstract class AppLocalizations {
|
||||
return Localizations.of<AppLocalizations>(context, AppLocalizations)!;
|
||||
}
|
||||
|
||||
static const LocalizationsDelegate<AppLocalizations> delegate =
|
||||
_AppLocalizationsDelegate();
|
||||
static const LocalizationsDelegate<AppLocalizations> delegate = _AppLocalizationsDelegate();
|
||||
|
||||
/// A list of this localizations delegate along with the default localizations
|
||||
/// delegates.
|
||||
@@ -84,8 +82,7 @@ abstract class AppLocalizations {
|
||||
/// Additional delegates can be added by appending to this list in
|
||||
/// MaterialApp. This list does not have to be used at all if a custom list
|
||||
/// of delegates is preferred or required.
|
||||
static const List<LocalizationsDelegate<dynamic>> localizationsDelegates =
|
||||
<LocalizationsDelegate<dynamic>>[
|
||||
static const List<LocalizationsDelegate<dynamic>> localizationsDelegates = <LocalizationsDelegate<dynamic>>[
|
||||
delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
@@ -1347,8 +1344,7 @@ abstract class AppLocalizations {
|
||||
String get kccBankFull;
|
||||
}
|
||||
|
||||
class _AppLocalizationsDelegate
|
||||
extends LocalizationsDelegate<AppLocalizations> {
|
||||
class _AppLocalizationsDelegate extends LocalizationsDelegate<AppLocalizations> {
|
||||
const _AppLocalizationsDelegate();
|
||||
|
||||
@override
|
||||
@@ -1357,25 +1353,25 @@ class _AppLocalizationsDelegate
|
||||
}
|
||||
|
||||
@override
|
||||
bool isSupported(Locale locale) =>
|
||||
<String>['en', 'hi'].contains(locale.languageCode);
|
||||
bool isSupported(Locale locale) => <String>['en', 'hi'].contains(locale.languageCode);
|
||||
|
||||
@override
|
||||
bool shouldReload(_AppLocalizationsDelegate old) => false;
|
||||
}
|
||||
|
||||
AppLocalizations lookupAppLocalizations(Locale locale) {
|
||||
|
||||
|
||||
// Lookup logic when only language code is specified.
|
||||
switch (locale.languageCode) {
|
||||
case 'en':
|
||||
return AppLocalizationsEn();
|
||||
case 'hi':
|
||||
return AppLocalizationsHi();
|
||||
case 'en': return AppLocalizationsEn();
|
||||
case 'hi': return AppLocalizationsHi();
|
||||
}
|
||||
|
||||
throw FlutterError(
|
||||
'AppLocalizations.delegate failed to load unsupported locale "$locale". This is likely '
|
||||
'an issue with the localizations generation tool. Please file an issue '
|
||||
'on GitHub with a reproducible sample app and the gen-l10n configuration '
|
||||
'that was used.');
|
||||
'AppLocalizations.delegate failed to load unsupported locale "$locale". This is likely '
|
||||
'an issue with the localizations generation tool. Please file an issue '
|
||||
'on GitHub with a reproducible sample app and the gen-l10n configuration '
|
||||
'that was used.'
|
||||
);
|
||||
}
|
||||
|
@@ -1,5 +1,3 @@
|
||||
// ignore: unused_import
|
||||
import 'package:intl/intl.dart' as intl;
|
||||
import 'app_localizations.dart';
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
@@ -488,8 +486,7 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
String get otpVerification => 'OTP Verification';
|
||||
|
||||
@override
|
||||
String get otpSentMessage =>
|
||||
'Enter the 4-digit OTP sent to your mobile number';
|
||||
String get otpSentMessage => 'Enter the 4-digit OTP sent to your mobile number';
|
||||
|
||||
@override
|
||||
String get verifyOtp => 'Verify OTP';
|
||||
@@ -507,15 +504,13 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
String get tpinRequired => 'TPIN Required';
|
||||
|
||||
@override
|
||||
String get tpinRequiredMessage =>
|
||||
'You need to set your TPIN to continue with secure transactions';
|
||||
String get tpinRequiredMessage => 'You need to set your TPIN to continue with secure transactions';
|
||||
|
||||
@override
|
||||
String get setTpinTitle => 'Set TPIN';
|
||||
|
||||
@override
|
||||
String get tpinInfo =>
|
||||
'Your TPIN is a 6-digit code used to authorize transactions. Keep it safe and do not share it with anyone.';
|
||||
String get tpinInfo => 'Your TPIN is a 6-digit code used to authorize transactions. Keep it safe and do not share it with anyone.';
|
||||
|
||||
@override
|
||||
String get tpinFailed => 'Failed to set TPIN. Please try again.';
|
||||
@@ -569,8 +564,7 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
String get enableFingerprintLogin => 'Enable Fingerprint Login?';
|
||||
|
||||
@override
|
||||
String get enableFingerprintMessage =>
|
||||
'Would you like to enable fingerprint authentication for faster login?';
|
||||
String get enableFingerprintMessage => 'Would you like to enable fingerprint authentication for faster login?';
|
||||
|
||||
@override
|
||||
String get no => 'No';
|
||||
@@ -591,8 +585,7 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
String get loading => 'Loading......';
|
||||
|
||||
@override
|
||||
String get enableFingerprintQuick =>
|
||||
'Enable fingerprint authentication for quick login?';
|
||||
String get enableFingerprintQuick => 'Enable fingerprint authentication for quick login?';
|
||||
|
||||
@override
|
||||
String get kccb => 'KCCB';
|
||||
|
@@ -1,5 +1,3 @@
|
||||
// ignore: unused_import
|
||||
import 'package:intl/intl.dart' as intl;
|
||||
import 'app_localizations.dart';
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
@@ -54,8 +52,7 @@ class AppLocalizationsHi extends AppLocalizations {
|
||||
String get enableBiometric => 'बायोमेट्रिक प्रमाणीकरण सक्षम करें';
|
||||
|
||||
@override
|
||||
String get useBiometricPrompt =>
|
||||
'तेज़ लॉगिन के लिए फिंगरप्रिंट/फेस आईडी का उपयोग करें?';
|
||||
String get useBiometricPrompt => 'तेज़ लॉगिन के लिए फिंगरप्रिंट/फेस आईडी का उपयोग करें?';
|
||||
|
||||
@override
|
||||
String get later => 'बाद में';
|
||||
@@ -489,8 +486,7 @@ class AppLocalizationsHi extends AppLocalizations {
|
||||
String get otpVerification => 'ओटीपी सत्यापन';
|
||||
|
||||
@override
|
||||
String get otpSentMessage =>
|
||||
'अपने मोबाइल नंबर पर भेजा गया 4-अंकों का ओटीपी दर्ज करें';
|
||||
String get otpSentMessage => 'अपने मोबाइल नंबर पर भेजा गया 4-अंकों का ओटीपी दर्ज करें';
|
||||
|
||||
@override
|
||||
String get verifyOtp => 'ओटीपी सत्यापित करें';
|
||||
@@ -508,15 +504,13 @@ class AppLocalizationsHi extends AppLocalizations {
|
||||
String get tpinRequired => 'टी-पिन आवश्यक है';
|
||||
|
||||
@override
|
||||
String get tpinRequiredMessage =>
|
||||
'सुरक्षित लेनदेन के लिए टी-पिन सेट करना आवश्यक है';
|
||||
String get tpinRequiredMessage => 'सुरक्षित लेनदेन के लिए टी-पिन सेट करना आवश्यक है';
|
||||
|
||||
@override
|
||||
String get setTpinTitle => 'टी-पिन सेट करें';
|
||||
|
||||
@override
|
||||
String get tpinInfo =>
|
||||
'आपका टी-पिन 6 अंकों का कोड है जिसका उपयोग लेन-देन को प्रमाणित करने के लिए किया जाता है। इसे सुरक्षित रखें और किसी से साझा न करें।';
|
||||
String get tpinInfo => 'आपका टी-पिन 6 अंकों का कोड है जिसका उपयोग लेन-देन को प्रमाणित करने के लिए किया जाता है। इसे सुरक्षित रखें और किसी से साझा न करें।';
|
||||
|
||||
@override
|
||||
String get tpinFailed => 'टी-पिन सेट करने में विफल। कृपया पुनः प्रयास करें।';
|
||||
@@ -570,8 +564,7 @@ class AppLocalizationsHi extends AppLocalizations {
|
||||
String get enableFingerprintLogin => 'फिंगरप्रिंट लॉगिन सक्षम करें?';
|
||||
|
||||
@override
|
||||
String get enableFingerprintMessage =>
|
||||
'क्या आप तेज लॉगिन के लिए फिंगरप्रिंट प्रमाणीकरण सक्षम करना चाहेंगे?';
|
||||
String get enableFingerprintMessage => 'क्या आप तेज लॉगिन के लिए फिंगरप्रिंट प्रमाणीकरण सक्षम करना चाहेंगे?';
|
||||
|
||||
@override
|
||||
String get no => 'नहीं';
|
||||
@@ -580,8 +573,7 @@ class AppLocalizationsHi extends AppLocalizations {
|
||||
String get yes => 'हाँ';
|
||||
|
||||
@override
|
||||
String get authenticateToEnable =>
|
||||
'फिंगरप्रिंट लॉगिन सक्षम करने के लिए प्रमाणीकरण करें';
|
||||
String get authenticateToEnable => 'फिंगरप्रिंट लॉगिन सक्षम करने के लिए प्रमाणीकरण करें';
|
||||
|
||||
@override
|
||||
String get exitApp => 'ऐप बंद करें';
|
||||
@@ -593,8 +585,7 @@ class AppLocalizationsHi extends AppLocalizations {
|
||||
String get loading => 'लोड हो रहा है......';
|
||||
|
||||
@override
|
||||
String get enableFingerprintQuick =>
|
||||
'तेज़ लॉगिन के लिए फिंगरप्रिंट प्रमाणीकरण सक्षम करें?';
|
||||
String get enableFingerprintQuick => 'तेज़ लॉगिन के लिए फिंगरप्रिंट प्रमाणीकरण सक्षम करें?';
|
||||
|
||||
@override
|
||||
String get kccb => 'केसीसीबी';
|
||||
@@ -636,7 +627,7 @@ class AppLocalizationsHi extends AppLocalizations {
|
||||
String get confirmMPIN => 'अपना mPIN की पुष्टि करें';
|
||||
|
||||
@override
|
||||
String get kconnect => 'केकनेक्ट';
|
||||
String get kconnect => 'के-कनेक्ट';
|
||||
|
||||
@override
|
||||
String get kccBankFull => 'कांगड़ा सेंट्रल को-ऑपरेटिव बैंक';
|
||||
|
Reference in New Issue
Block a user