Compare commits
219 Commits
language-t
...
new-ui
| Author | SHA1 | Date | |
|---|---|---|---|
| 715162b713 | |||
| 8149ef2a5b | |||
| 1a2dea611b | |||
| 72a2c56392 | |||
| aef82237ac | |||
| 974f42bf95 | |||
| 4a8c69bb1e | |||
| 86aaaa1f6d | |||
| 6796793aac | |||
| fbf6df7181 | |||
| c7111d518a | |||
| 5d307607fd | |||
| 992092052a | |||
| 64fedabd89 | |||
| 4fc6f54fcd | |||
| 8c7e94759a | |||
| 8aa5b170ca | |||
| 04a1ce26ec | |||
| b19bc2e222 | |||
| b9147b30d5 | |||
| 3358ec7669 | |||
| 18db360a45 | |||
| b7fe6a9d18 | |||
| adb9a5330b | |||
| 0075abc906 | |||
| 353ec63916 | |||
| 71b52cfb43 | |||
| c1df43e9b6 | |||
| f0d5233afc | |||
| 4fe6af4098 | |||
| fda5d075ff | |||
| 71e0521dec | |||
| f6e851a9ee | |||
| 547f534037 | |||
| 66b2e71140 | |||
| 43d92d799b | |||
| 3135116f26 | |||
| 39165d631e | |||
|
|
ef481ec879 | ||
|
|
36702b198f | ||
|
|
f0718e9d68 | ||
|
|
d2cce89efb | ||
| 8cfca113bf | |||
| d6f61ebb31 | |||
| 078e715d20 | |||
| 5c8df8ace3 | |||
| 3e88aad43f | |||
| 5b7f3f0096 | |||
| b5b6c6ed49 | |||
| c26cc507a1 | |||
| 87fd36b748 | |||
| 3417c4b0e5 | |||
| 151140d563 | |||
| a8ee7833be | |||
| f73faaa635 | |||
| 5ac977e903 | |||
| f15b8ac3f7 | |||
| 8f8fdb70e6 | |||
| d86ff2c427 | |||
| 527111c1de | |||
| dfbdb3238d | |||
| 3d13edf676 | |||
| 32e8b85cee | |||
| 58e53d0aeb | |||
| 06ef2ab36b | |||
| 0362bf2013 | |||
| 73b96b82f7 | |||
| c78a90dbfe | |||
| df025babd5 | |||
| 4d19bf6146 | |||
| d36cad31c1 | |||
| 39e7a02ca5 | |||
| 0c7470d74b | |||
| 32463680e8 | |||
| 00cb98ae83 | |||
| 18844495c2 | |||
| 3f7869677c | |||
| 0e4072fe8f | |||
| b5acae85d5 | |||
| cc7c7a8042 | |||
| 475f30a4bb | |||
| b00bc6c8c0 | |||
| c47862bd60 | |||
| 8ef4f1327f | |||
| 87e00d540f | |||
| 44a6307995 | |||
| f6b24e4c6f | |||
| 9cf4c44bb0 | |||
| b3b51d423d | |||
| b1f4d380c6 | |||
| 17ebf8626a | |||
| e466dff424 | |||
| 8f2b981b5b | |||
| ba1ef0ed24 | |||
| d2044d49b5 | |||
| db39cfbcc9 | |||
| bf23627e0a | |||
| eba38c2e42 | |||
|
|
d4bba6dc49 | ||
| b56bf0d7df | |||
| 82e057d804 | |||
| 0f205873a9 | |||
| 191610c9b2 | |||
| b03e917d78 | |||
|
|
188fbe9bb1 | ||
|
|
817f3d75f5 | ||
|
|
c42b973bee | ||
|
|
def009003c | ||
| 52e9f59e6f | |||
| e4e104837b | |||
| dd7b7a6f4c | |||
| c322d1d2fd | |||
| b3fb387bdd | |||
|
|
b62b8a157d | ||
| c729b775c9 | |||
| 465065db57 | |||
| 0a6dde9ead | |||
| b513664a47 | |||
| d8d87e8da4 | |||
| 1204507375 | |||
| be9a6fc93f | |||
| b8337d1152 | |||
| d3792a1a06 | |||
| 845ce1fe78 | |||
| 45dbf8464a | |||
|
|
a1ea60841e | ||
|
|
2abc315af9 | ||
|
|
a44ac67842 | ||
|
|
1b684af3a8 | ||
|
|
aa5a7877e4 | ||
|
|
d6a99ea295 | ||
|
|
cf8964ca36 | ||
|
|
c489bf3895 | ||
|
|
ba819f51d7 | ||
|
|
48f169d10c | ||
|
|
64e80148a3 | ||
|
|
85f58c1e25 | ||
|
|
3b9b1e507c | ||
| 57439f2acb | |||
| 52534f9210 | |||
| d9f78629d2 | |||
| 3e3465d5e8 | |||
| be76465774 | |||
| de596aa138 | |||
| 720c6ec03a | |||
| d081a5433c | |||
| 90f4a6bb81 | |||
|
|
f71c8d646b | ||
|
|
6a8f091ac5 | ||
|
|
596f0a96eb | ||
|
|
768d312066 | ||
|
|
4277ca9169 | ||
|
|
53caa5b7ae | ||
|
|
bfa0721e79 | ||
|
|
75bcce8201 | ||
|
|
99f4b1b735 | ||
|
|
6ebc96d153 | ||
|
|
6496aa95c0 | ||
|
|
e91efafa0e | ||
|
|
61a6e356d9 | ||
|
|
a48781ad1b | ||
|
|
d425af184e | ||
|
|
bc2c460f96 | ||
|
|
ef3556f207 | ||
|
|
6724d8bed0 | ||
|
|
83ed973b44 | ||
|
|
f7dd31fb93 | ||
|
|
9c60dc1c1c | ||
|
|
c369ad415d | ||
|
|
f934f0bff6 | ||
|
|
da0287ef38 | ||
|
|
f65507a706 | ||
| 9f6b35d3eb | |||
| a33b4bc1e1 | |||
| 0d629226a8 | |||
| 6d502a0c81 | |||
| 96d1e37c42 | |||
| b0610ad84d | |||
| ceb29ee7fe | |||
| 57cb93c124 | |||
| 0ac9a1f319 | |||
| d3ad68b25c | |||
|
|
eb0e1c120e | ||
| a64e68d642 | |||
| 80faa06272 | |||
| 0bab68a2e6 | |||
|
|
351ee84414 | ||
|
|
f77549310a | ||
| 4b28a113d4 | |||
| bf35ec61d5 | |||
| 180d3a3a60 | |||
|
|
737ce6cce6 | ||
|
|
e75f48aed5 | ||
|
|
5ee88403dd | ||
|
|
7fe8e8f084 | ||
|
|
59eb509dda | ||
|
|
5f41c6e7f4 | ||
|
|
36474786c1 | ||
|
|
df51c4f30b | ||
|
|
cf8588b336 | ||
| 04c992c934 | |||
| fc76528206 | |||
| 7527db3d2f | |||
| 19d3487552 | |||
|
|
60a5703c35 | ||
| 09618db28e | |||
| 712553e49f | |||
| 842eef2cc7 | |||
|
|
e6ea764785 | ||
| e2a809d363 | |||
| f48bfabb4a | |||
| 76d5874e19 | |||
| 913e31a6ab | |||
| 7f5258b5b7 | |||
|
|
82951b7919 | ||
| 8ae26e2f18 | |||
| e7bbab13ba | |||
| 72862492c0 | |||
|
|
f91d0f739b |
8
.gitignore
vendored
@@ -41,3 +41,11 @@ app.*.map.json
|
||||
/android/app/debug
|
||||
/android/app/profile
|
||||
/android/app/release
|
||||
lib/l10n/app_localizations.dart
|
||||
lib/l10n/app_localizations_en.dart
|
||||
lib/l10n/app_localizations_hi.dart
|
||||
|
||||
# Keystore files
|
||||
android/key.properties
|
||||
android/*.jks
|
||||
android/*.keystore
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
|
||||
# The following line activates a set of recommended lints for Flutter apps,
|
||||
# packages, and plugins designed to encourage good coding practices.
|
||||
analyzer:
|
||||
errors:
|
||||
dead_code: ignore
|
||||
non_constant_identifier_names: ignore
|
||||
include: package:flutter_lints/flutter.yaml
|
||||
|
||||
linter:
|
||||
|
||||
@@ -22,12 +22,19 @@ if (flutterVersionName == null) {
|
||||
flutterVersionName = '1.0'
|
||||
}
|
||||
|
||||
def keystoreProperties = new Properties()
|
||||
def keystorePropertiesFile = rootProject.file('key.properties')
|
||||
if (keystorePropertiesFile.exists()) {
|
||||
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
|
||||
}
|
||||
|
||||
android {
|
||||
namespace "com.example.kmobile"
|
||||
compileSdk flutter.compileSdkVersion
|
||||
ndkVersion flutter.ndkVersion
|
||||
ndkVersion "27.0.12077973"
|
||||
|
||||
compileOptions {
|
||||
coreLibraryDesugaringEnabled true
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
@@ -45,17 +52,27 @@ android {
|
||||
applicationId "com.example.kmobile"
|
||||
// You can update the following values to match your application needs.
|
||||
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
|
||||
minSdkVersion flutter.minSdkVersion
|
||||
minSdkVersion 29
|
||||
targetSdkVersion flutter.targetSdkVersion
|
||||
versionCode flutterVersionCode.toInteger()
|
||||
versionName flutterVersionName
|
||||
}
|
||||
|
||||
signingConfigs {
|
||||
release {
|
||||
keyAlias keystoreProperties['keyAlias']
|
||||
keyPassword keystoreProperties['keyPassword']
|
||||
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
|
||||
storePassword keystoreProperties['storePassword']
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
// TODO: Add your own signing config for the release build.
|
||||
// Signing with the debug keys for now, so `flutter run --release` works.
|
||||
signingConfig signingConfigs.debug
|
||||
signingConfig signingConfigs.release
|
||||
minifyEnabled true
|
||||
shrinkResources true
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,4 +81,6 @@ flutter {
|
||||
source '../..'
|
||||
}
|
||||
|
||||
dependencies {}
|
||||
dependencies {
|
||||
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.5'
|
||||
}
|
||||
|
||||
21
android/app/proguard-rules.pro
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
-keep class io.flutter.app.** { *; }
|
||||
-keep class io.flutter.plugin.** { *; }
|
||||
-keep class io.flutter.util.** { *; }
|
||||
-keep class io.flutter.view.** { *; }
|
||||
-keep class io.flutter.embedding.** { *; }
|
||||
-keep class io.flutter.embedding.engine.plugins.** { *; }
|
||||
-keep class com.google.firebase.** { *; }
|
||||
-keep class com.google.android.gms.** { *; }
|
||||
# Please add these rules to your existing keep rules in order to suppress warnings.
|
||||
# This is generated automatically by the Android Gradle plugin.
|
||||
-dontwarn com.google.android.play.core.splitcompat.SplitCompatApplication
|
||||
-dontwarn com.google.android.play.core.splitinstall.SplitInstallException
|
||||
-dontwarn com.google.android.play.core.splitinstall.SplitInstallManager
|
||||
-dontwarn com.google.android.play.core.splitinstall.SplitInstallManagerFactory
|
||||
-dontwarn com.google.android.play.core.splitinstall.SplitInstallRequest$Builder
|
||||
-dontwarn com.google.android.play.core.splitinstall.SplitInstallRequest
|
||||
-dontwarn com.google.android.play.core.splitinstall.SplitInstallSessionState
|
||||
-dontwarn com.google.android.play.core.splitinstall.SplitInstallStateUpdatedListener
|
||||
-dontwarn com.google.android.play.core.tasks.OnFailureListener
|
||||
-dontwarn com.google.android.play.core.tasks.OnSuccessListener
|
||||
-dontwarn com.google.android.play.core.tasks.Task
|
||||
@@ -2,10 +2,13 @@
|
||||
<uses-permission android:name="android.permission.USE_BIOMETRIC"/>
|
||||
<uses-permission android:name="android.permission.USE_FINGERPRINT"/>
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.SEND_SMS"/>
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
|
||||
<application
|
||||
android:label="kmobile"
|
||||
android:name="${applicationName}"
|
||||
android:usesCleartextTraffic="true"
|
||||
android:allowBackup="false"
|
||||
android:icon="@mipmap/ic_launcher">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
@@ -39,6 +42,20 @@
|
||||
https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.
|
||||
|
||||
In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
|
||||
<queries>
|
||||
<intent>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<data android:scheme="https" />
|
||||
</intent>
|
||||
<intent>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<data android:scheme="http" />
|
||||
</intent>
|
||||
<intent>
|
||||
<action android:name="android.intent.action.SENDTO" />
|
||||
<data android:scheme="mailto" />
|
||||
</intent>
|
||||
</queries>
|
||||
<queries>
|
||||
<intent>
|
||||
<action android:name="android.intent.action.PROCESS_TEXT"/>
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
package com.example.kmobile
|
||||
|
||||
import io.flutter.embedding.android.FlutterFragmentActivity
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
import android.view.WindowManager.LayoutParams
|
||||
import android.os.Bundle
|
||||
|
||||
class MainActivity: FlutterFragmentActivity()
|
||||
class MainActivity: FlutterFragmentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
window.addFlags(LayoutParams.FLAG_SECURE)
|
||||
}
|
||||
}
|
||||
BIN
android/app/src/main/res/drawable/notification_icon.png
Normal file
|
After Width: | Height: | Size: 90 KiB |
|
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 7.1 KiB |
|
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 3.9 KiB |
|
Before Width: | Height: | Size: 7.2 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 26 KiB |
663
android/build/reports/problems/problems-report.html
Normal file
BIN
assets/images/BankofBaroda_logo.png
Normal file
|
After Width: | Height: | Size: 5.3 KiB |
BIN
assets/images/axisbank_logo.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
assets/images/boi_logo.png
Normal file
|
After Width: | Height: | Size: 7.4 KiB |
BIN
assets/images/canaraBank_logo.png
Normal file
|
After Width: | Height: | Size: 4.9 KiB |
BIN
assets/images/hdfc_logo.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
assets/images/icici_logo.png
Normal file
|
After Width: | Height: | Size: 77 KiB |
BIN
assets/images/ipos_logo.png
Normal file
|
After Width: | Height: | Size: 5.8 KiB |
BIN
assets/images/kotak_logo.png
Normal file
|
After Width: | Height: | Size: 5.0 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 90 KiB |
BIN
assets/images/logo_2.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
assets/images/pnb_logo.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
assets/images/profile.png
Normal file
|
After Width: | Height: | Size: 3.3 KiB |
BIN
assets/images/profile.svg
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
assets/images/sbi_logo.png
Normal file
|
After Width: | Height: | Size: 6.5 KiB |
BIN
assets/images/uco_logo.png
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
assets/images/yes_bank_logo.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
flutter_01.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
@@ -427,7 +427,7 @@
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
|
||||
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = AppIcon;
|
||||
CLANG_ANALYZER_NONNULL = YES;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
@@ -484,7 +484,7 @@
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
|
||||
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = AppIcon;
|
||||
CLANG_ANALYZER_NONNULL = YES;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
|
||||
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 316 KiB |
|
Before Width: | Height: | Size: 295 B After Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 406 B After Width: | Height: | Size: 2.9 KiB |
|
Before Width: | Height: | Size: 450 B After Width: | Height: | Size: 5.4 KiB |
|
Before Width: | Height: | Size: 282 B After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 462 B After Width: | Height: | Size: 5.2 KiB |
|
Before Width: | Height: | Size: 704 B After Width: | Height: | Size: 9.3 KiB |
|
Before Width: | Height: | Size: 406 B After Width: | Height: | Size: 2.9 KiB |
|
Before Width: | Height: | Size: 586 B After Width: | Height: | Size: 8.1 KiB |
|
Before Width: | Height: | Size: 862 B After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 4.1 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 5.1 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 862 B After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 7.1 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 762 B After Width: | Height: | Size: 7.8 KiB |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 21 KiB |
@@ -47,5 +47,19 @@
|
||||
<true/>
|
||||
<key>NSFaceIDUsageDescription</key>
|
||||
<string>We use Face ID to secure your data.</string>
|
||||
<key>LSApplicationQueriesSchemes</key>
|
||||
<array>
|
||||
<string>https</string>
|
||||
<string>http</string>
|
||||
</array>
|
||||
<key>NSCameraUsageDescription</key>
|
||||
<string>This app needs camera access to scan QR codes and take pictures.</string>
|
||||
<key>NSPhotoLibraryUsageDescription</key>
|
||||
<string>This app needs photo library access to save and share images.</string>
|
||||
<key>NSContactsUsageDescription</key>
|
||||
<string>This app needs contacts access to easily send money to your contacts.</string>
|
||||
<key>NSMicrophoneUsageDescription</key>
|
||||
<string>This app needs microphone access for voice commands.</string>
|
||||
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// ignore_for_file: unused_local_variable
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import '../../data/repositories/auth_repository.dart';
|
||||
|
||||
|
||||
@@ -4,18 +4,52 @@ import '../../features/auth/models/auth_token.dart';
|
||||
import '../../features/auth/models/auth_credentials.dart';
|
||||
import '../../core/errors/exceptions.dart';
|
||||
|
||||
|
||||
class AuthService {
|
||||
final Dio _dio;
|
||||
AuthService(this._dio);
|
||||
|
||||
Future<void> simVerify(String uuid, String cifNo) async {
|
||||
try {
|
||||
final response = await _dio.post('/api/sim-details-verify', data: {
|
||||
'uuid': uuid,
|
||||
'cifNo': cifNo,
|
||||
});
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final String message = response.data.toString().toUpperCase();
|
||||
|
||||
if (message.contains("VERIFIED")) {
|
||||
return; // Success
|
||||
} else {
|
||||
throw AuthException(message); // Throw message received
|
||||
}
|
||||
} else {
|
||||
throw AuthException('Verification Failed');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
if (kDebugMode) {
|
||||
print(e.toString());
|
||||
}
|
||||
|
||||
if (e.response?.statusCode == 401) {
|
||||
throw AuthException(
|
||||
e.response?.data['error'] ?? 'SOMETHING WENT WRONG');
|
||||
}
|
||||
|
||||
throw NetworkException('Network error during verification');
|
||||
} catch (e) {
|
||||
throw UnexpectedException(
|
||||
'Unexpected error during verification: ${e.toString()}');
|
||||
}
|
||||
}
|
||||
|
||||
Future<AuthToken> login(AuthCredentials credentials) async {
|
||||
try {
|
||||
final response = await _dio.post(
|
||||
'/api/auth/login',
|
||||
data: credentials.toJson(),
|
||||
);
|
||||
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return AuthToken.fromJson(response.data);
|
||||
} else {
|
||||
@@ -26,11 +60,13 @@ class AuthService {
|
||||
print(e.toString());
|
||||
}
|
||||
if (e.response?.statusCode == 401) {
|
||||
throw AuthException('Invalid credentials');
|
||||
throw AuthException(
|
||||
e.response?.data['error'] ?? 'SOMETHING WENT WRONG');
|
||||
}
|
||||
throw NetworkException('Network error during login');
|
||||
} catch (e) {
|
||||
throw UnexpectedException('Unexpected error during login: ${e.toString()}');
|
||||
throw UnexpectedException(
|
||||
'Unexpected error during login: ${e.toString()}');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +76,7 @@ class AuthService {
|
||||
'/auth/refresh',
|
||||
data: {'refresh_token': refreshToken},
|
||||
);
|
||||
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return AuthToken.fromJson(response.data);
|
||||
} else {
|
||||
@@ -54,7 +90,7 @@ class AuthService {
|
||||
Future<bool> checkTpin() async {
|
||||
try {
|
||||
final response = await _dio.get('/api/auth/tpin');
|
||||
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return response.data['tpinSet'] as bool;
|
||||
} else {
|
||||
@@ -66,7 +102,8 @@ class AuthService {
|
||||
}
|
||||
throw NetworkException('Network error during TPIN check');
|
||||
} catch (e) {
|
||||
throw UnexpectedException('Unexpected error during TPIN check: ${e.toString()}');
|
||||
throw UnexpectedException(
|
||||
'Unexpected error during TPIN check: ${e.toString()}');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +113,7 @@ class AuthService {
|
||||
'/api/auth/tpin',
|
||||
data: {'tpin': tpin},
|
||||
);
|
||||
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw AuthException('Failed to set TPIN');
|
||||
}
|
||||
@@ -86,8 +123,76 @@ class AuthService {
|
||||
}
|
||||
throw NetworkException('Network error during TPIN setup');
|
||||
} catch (e) {
|
||||
throw UnexpectedException('Unexpected error during TPIN setup: ${e.toString()}');
|
||||
throw UnexpectedException(
|
||||
'Unexpected error during TPIN setup: ${e.toString()}');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Future<void> sendOtpForSettingPassword(String customerNo) async {
|
||||
try {
|
||||
final response =
|
||||
await _dio.get('/api/otp/send/set-password', queryParameters: {
|
||||
'customerNo': customerNo,
|
||||
});
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception(response.data['error'] ?? 'Failed to send OTP');
|
||||
}
|
||||
return;
|
||||
} on DioException catch (e) {
|
||||
throw Exception('Network error: ${e.message}');
|
||||
} catch (e) {
|
||||
throw Exception('Unexpected error: ${e.toString()}');
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> verifyOtpForSettingPassword(
|
||||
String customerNo, String otp) async {
|
||||
try {
|
||||
final response = await _dio.get(
|
||||
'/api/otp/verify/set-password',
|
||||
queryParameters: {'customerNo': customerNo, 'otp': otp},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return response.data['token'];
|
||||
} else {
|
||||
throw Exception(response.data['error'] ?? 'Failed to verify OTP');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
throw Exception('Network error: ${e.message}');
|
||||
} catch (e) {
|
||||
throw Exception('Unexpected error: ${e.toString()}');
|
||||
}
|
||||
}
|
||||
|
||||
Future changePassword(String newPassword, String token) async {
|
||||
final response = await _dio.post(
|
||||
'/api/auth/login_password',
|
||||
data: {'login_password': newPassword},
|
||||
options: Options(headers: {'Authorization': 'Bearer $token'}),
|
||||
);
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('Error setting password');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Future setTncflag() async {
|
||||
try {
|
||||
final response = await _dio.post(
|
||||
'/api/auth/tnc',
|
||||
data: {"flag": 'Y'},
|
||||
);
|
||||
if (response.statusCode != 200) {
|
||||
throw AuthException('Failed to proceed with T&C');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
if (kDebugMode) {
|
||||
print(e.toString());
|
||||
}
|
||||
throw NetworkException('Network error during T&C Setup');
|
||||
} catch (e) {
|
||||
throw UnexpectedException('Unexpected error: ${e.toString()}');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import 'dart:developer';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:kmobile/core/errors/exceptions.dart';
|
||||
import 'package:kmobile/data/models/ifsc.dart';
|
||||
import 'package:kmobile/data/models/beneficiary.dart';
|
||||
|
||||
@@ -9,14 +11,16 @@ class BeneficiaryService {
|
||||
|
||||
Future<String> validateBeneficiaryWithinBank(String accountNumber) async {
|
||||
try {
|
||||
final response = await _dio.get('/api/beneficiary/validate/within-bank', queryParameters: {
|
||||
final response = await _dio
|
||||
.get('/api/beneficiary/validate/within-bank', queryParameters: {
|
||||
'accountNumber': accountNumber,
|
||||
});
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return response.data['name'];
|
||||
} else {
|
||||
throw Exception(response.data['error'] ?? 'Failed to validate beneficiary');
|
||||
throw Exception(
|
||||
response.data['error'] ?? 'Failed to validate beneficiary');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
throw Exception('Network error: ${e.message}');
|
||||
@@ -24,156 +28,102 @@ class BeneficiaryService {
|
||||
throw Exception('Unexpected error: ${e.toString()}');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Future<ifsc?> validateIFSC(String ifscCode) async {
|
||||
try {
|
||||
final response = await _dio.get('/api/beneficiary/ifsc-details', queryParameters: {
|
||||
"ifscCode": ifscCode
|
||||
}
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return ifsc.fromJson(response.data);
|
||||
Future<Ifsc> validateIFSC(String ifscCode) async {
|
||||
try {
|
||||
final response = await _dio.get('/api/beneficiary/ifsc-details',
|
||||
queryParameters: {"ifscCode": ifscCode});
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return Ifsc.fromJson(response.data);
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
if (e.response?.statusCode == 404) {
|
||||
throw Exception('INVALID IFSC CODE');
|
||||
} else if (e.response?.statusCode == 401) {
|
||||
throw Exception('INVALID IFSC CODE');
|
||||
}
|
||||
} catch (e) {
|
||||
throw UnexpectedException(
|
||||
'Unexpected error during login: ${e.toString()}');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
if (e.response?.statusCode == 404) {
|
||||
print('Invalid IFSC code.');
|
||||
} else {
|
||||
print('API error: ${e.message}');
|
||||
}
|
||||
} catch (e) {
|
||||
print('Unexpected error: $e');
|
||||
return Ifsc.fromJson({});
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
///Step 1: Validate beneficiary (returns refNo)
|
||||
Future<String?> validateBeneficiary({
|
||||
Future<String> validateBeneficiary({
|
||||
required String accountNo,
|
||||
required String ifscCode,
|
||||
required String remitterName,
|
||||
}) async {
|
||||
|
||||
try {
|
||||
final response = await _dio.post(
|
||||
'/api/beneficiary/validate/outside_bank',
|
||||
queryParameters: {
|
||||
'accountNo': accountNo,
|
||||
'ifscCode': ifscCode,
|
||||
'remitterName': remitterName,
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return response.data['refNo'];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (e) {
|
||||
print("Error validating beneficiary: $e");
|
||||
return null;
|
||||
log('inside validate beneficiary service');
|
||||
final response = await _dio.get(
|
||||
'/api/beneficiary/validate/outside-bank',
|
||||
queryParameters: {
|
||||
'accountNo': accountNo,
|
||||
'ifscCode': ifscCode,
|
||||
'remitterName': remitterName,
|
||||
},
|
||||
options: Options(
|
||||
sendTimeout: const Duration(seconds: 60),
|
||||
receiveTimeout: const Duration(seconds: 60),
|
||||
),
|
||||
);
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception("Invalid Beneficiary Details");
|
||||
}
|
||||
return response.data['name'];
|
||||
}
|
||||
|
||||
/// Step 2: Check validation status (returns Beneficiary name if success)
|
||||
Future<String?> checkValidationStatus(String refNo) async {
|
||||
// Beneficiary Validate And ADD
|
||||
Future<bool> sendForValidation(Beneficiary beneficiary) async {
|
||||
try {
|
||||
final response = await _dio.get(
|
||||
'/api/beneficiary/check',
|
||||
queryParameters: {
|
||||
'refNo': refNo,
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200 && response.data != null) {
|
||||
return Beneficiary.fromJson(response.data).name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (e) {
|
||||
print("Error checking validation status: $e");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Send Data for Validation
|
||||
Future<void> sendForValidation(Beneficiary beneficiary) async {
|
||||
try {
|
||||
print(beneficiary.toJson());
|
||||
final response = await _dio.post(
|
||||
'/api/beneficiary/add',
|
||||
'/api/beneficiary',
|
||||
data: beneficiary.toJson(),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
print("SENT FOR VALIDATION");
|
||||
return true;
|
||||
} else {
|
||||
print("VALIDATION REQUEST FAILED: ${response.statusCode}");
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
print("ERROR IN SENDING REQUEST: $e");
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
// Poll to check if beneficiary is found
|
||||
Future<bool> checkIfFound(String accountNo) async {
|
||||
const int timeoutInSeconds = 30;
|
||||
const int intervalInSeconds = 2;
|
||||
const int maxTries = timeoutInSeconds ~/ intervalInSeconds;
|
||||
|
||||
int attempts = 0;
|
||||
|
||||
while (attempts < maxTries) {
|
||||
try {
|
||||
final response = await _dio.get(
|
||||
'/api/beneficiary/check?',
|
||||
queryParameters: {
|
||||
'accountNo': accountNo
|
||||
}
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
print("FOUND");
|
||||
return true;
|
||||
} else if (response.statusCode == 404) {
|
||||
print("NOT FOUND");
|
||||
}
|
||||
} catch (e) {
|
||||
print("ERROR DURING STATUS: $e");
|
||||
}
|
||||
attempts++;
|
||||
}
|
||||
|
||||
print("Beneficiary not found within timeout.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<List<Beneficiary>> fetchBeneficiaryList() async{
|
||||
Future<List<Beneficiary>> fetchBeneficiaryList() async {
|
||||
try {
|
||||
final response = await _dio.get(
|
||||
"/api/beneficiary/get",
|
||||
options: Options(
|
||||
"/api/beneficiary",
|
||||
options: Options(
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return Beneficiary.listFromJson(response.data);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return Beneficiary.listFromJson(response.data);
|
||||
} else {
|
||||
throw Exception("Failed to fetch beneficiaries");
|
||||
}
|
||||
} catch (e) {
|
||||
print("Error fetching beneficiaries: $e");
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Future<void> deleteBeneficiary(String accountNo) async {
|
||||
try {
|
||||
final response = await _dio.delete('/api/beneficiary/$accountNo');
|
||||
|
||||
if (response.statusCode != 204) {
|
||||
throw Exception('Failed to delete beneficiary');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
throw Exception('Network error: ${e.message}');
|
||||
} catch (e) {
|
||||
throw Exception('Unexpected error: ${e.toString()}');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
136
lib/api/services/branch_service.dart
Normal file
@@ -0,0 +1,136 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
class Branch {
|
||||
final String branch_code;
|
||||
final String branch_name;
|
||||
final String zone;
|
||||
final String tehsil;
|
||||
final String block;
|
||||
final String block_code;
|
||||
final String distt_name;
|
||||
final String distt_code_slbc;
|
||||
final String date_of_opening;
|
||||
final String rbi_code_1;
|
||||
final String rbi_code_2;
|
||||
final String telephone_no;
|
||||
final String type_of_branch;
|
||||
final String rtgs_acct_no;
|
||||
final String br_lattitude;
|
||||
final String br_longitude;
|
||||
final String pincode;
|
||||
final String post_office;
|
||||
|
||||
Branch({
|
||||
required this.branch_code,
|
||||
required this.branch_name,
|
||||
required this.zone,
|
||||
required this.tehsil,
|
||||
required this.block,
|
||||
required this.block_code,
|
||||
required this.distt_name,
|
||||
required this.distt_code_slbc,
|
||||
required this.date_of_opening,
|
||||
required this.rbi_code_1,
|
||||
required this.rbi_code_2,
|
||||
required this.telephone_no,
|
||||
required this.type_of_branch,
|
||||
required this.rtgs_acct_no,
|
||||
required this.br_lattitude,
|
||||
required this.br_longitude,
|
||||
required this.pincode,
|
||||
required this.post_office,
|
||||
});
|
||||
|
||||
factory Branch.fromJson(Map<String, dynamic> json) {
|
||||
return Branch(
|
||||
branch_code: json['branch_code'] ?? json['branch_code'] ?? '',
|
||||
branch_name: json['branch_name'] ?? json['branch_name'] ?? '',
|
||||
zone: json['zone'] ?? json['zone'] ?? '',
|
||||
tehsil: json['tehsil'] ?? json['tehsil'] ?? '',
|
||||
block: json['block'] ?? json['block'] ?? '',
|
||||
block_code: json['block_code'] ?? json['block_code'] ?? '',
|
||||
distt_name: json['distt_name'] ?? json['distt_name'] ?? '',
|
||||
distt_code_slbc: json['distt_code_slbc'] ?? json['distt_code_slbc'] ?? '',
|
||||
date_of_opening: json['date_of_opening'] ?? json['date_of_opening'] ?? '',
|
||||
rbi_code_1: json['rbi_code_1'] ?? json['rbi_code_1'] ?? '',
|
||||
rbi_code_2: json['rbi_code_2'] ?? json['rbi_code_2'] ?? '',
|
||||
telephone_no: json['telephone_no'] ?? json['telephone_no'] ?? '',
|
||||
type_of_branch: json['type_of_branch'] ?? json['type_of_branch'] ?? '',
|
||||
rtgs_acct_no: json['rtgs_acct_no'] ?? json['rtgs_acct_no'] ?? '',
|
||||
br_lattitude: json['br_lattitude'] ?? json['br_lattitude'] ?? '',
|
||||
br_longitude: json['br_longitude'] ?? json['br_longitude'] ?? '',
|
||||
pincode: json['pincode'] ?? json['pincode'] ?? '',
|
||||
post_office: json['post_office'] ?? json['post_office'] ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
static List<Branch> listFromJson(List<dynamic> jsonList) {
|
||||
final beneficiaryList =
|
||||
jsonList.map((beneficiary) => Branch.fromJson(beneficiary)).toList();
|
||||
return beneficiaryList;
|
||||
}
|
||||
}
|
||||
|
||||
class Atm {
|
||||
final String name;
|
||||
|
||||
Atm({required this.name});
|
||||
|
||||
factory Atm.fromJson(Map<String, dynamic> json) {
|
||||
return Atm(
|
||||
name: json['name'] ?? '', // Assuming the API returns a 'name' field
|
||||
);
|
||||
}
|
||||
|
||||
static List<Atm> listFromJson(List<dynamic> jsonList) {
|
||||
return jsonList.map((atm) => Atm.fromJson(atm)).toList();
|
||||
}
|
||||
}
|
||||
|
||||
class BranchService {
|
||||
final Dio _dio;
|
||||
BranchService(this._dio);
|
||||
|
||||
Future<List<Branch>> fetchBranchList() async {
|
||||
try {
|
||||
final response = await _dio.get(
|
||||
"/api/branch",
|
||||
options: Options(
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return Branch.listFromJson(response.data);
|
||||
} else {
|
||||
throw Exception("Failed to fetch beneficiaries");
|
||||
}
|
||||
} catch (e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<Atm>> fetchAtmList() async {
|
||||
try {
|
||||
final response = await _dio.get(
|
||||
"/api/atm",
|
||||
options: Options(
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
),
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
return Atm.listFromJson(response.data);
|
||||
} else {
|
||||
throw Exception("Failed to fetch ATM list: ${response.statusCode}");
|
||||
}
|
||||
} catch (e) {
|
||||
// You might want to log the error here for debugging
|
||||
print("Error fetching ATM list: $e");
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
87
lib/api/services/change_password_service.dart
Normal file
@@ -0,0 +1,87 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
class ChangePasswordService {
|
||||
final Dio _dio;
|
||||
|
||||
ChangePasswordService(this._dio);
|
||||
|
||||
Future getOtp({
|
||||
required String mobileNumber,
|
||||
}) async {
|
||||
final response = await _dio.post(
|
||||
'/api/otp/send',
|
||||
data: {'mobileNumber': mobileNumber, 'type': "CHANGE_LPWORD"},
|
||||
);
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception("Invalid Mobile Number/Type");
|
||||
}
|
||||
print(response.toString());
|
||||
return response.toString();
|
||||
}
|
||||
|
||||
Future getOtpTpin({
|
||||
required String mobileNumber,
|
||||
}) async {
|
||||
final response = await _dio.post(
|
||||
'/api/otp/send',
|
||||
data: {'mobileNumber': mobileNumber, 'type': "CHANGE_TPIN"},
|
||||
);
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception("Invalid Mobile Number/Type");
|
||||
}
|
||||
print(response.toString());
|
||||
return response.toString();
|
||||
}
|
||||
|
||||
Future validateOtp({
|
||||
required String otp,
|
||||
required String mobileNumber,
|
||||
}) async {
|
||||
final response = await _dio.post(
|
||||
'/api/otp/verify?mobileNumber=$mobileNumber',
|
||||
data: {
|
||||
'otp': otp,
|
||||
},
|
||||
);
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception("Wrong OTP");
|
||||
}
|
||||
return response.toString();
|
||||
}
|
||||
|
||||
Future validateChangePwd({
|
||||
required String OldLPsw,
|
||||
required String newLPsw,
|
||||
required String confirmLPsw,
|
||||
}) async {
|
||||
final response = await _dio.post(
|
||||
'/api/auth/change/login_password',
|
||||
data: {
|
||||
'OldLPsw': OldLPsw,
|
||||
'newLPsw': newLPsw,
|
||||
'confirmLPsw': confirmLPsw,
|
||||
},
|
||||
);
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception("Wrong OTP");
|
||||
}
|
||||
return response.toString();
|
||||
}
|
||||
|
||||
Future validateChangeTpin({
|
||||
required String oldTpin,
|
||||
required String newTpin,
|
||||
}) async {
|
||||
final response = await _dio.post(
|
||||
'/api/auth/change/tpin',
|
||||
data: {
|
||||
'oldTpin': oldTpin,
|
||||
'newTpin': newTpin,
|
||||
},
|
||||
);
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception("Wrong OTP");
|
||||
}
|
||||
return response.toString();
|
||||
}
|
||||
}
|
||||
31
lib/api/services/imps_service.dart
Normal file
@@ -0,0 +1,31 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:kmobile/data/models/imps_response.dart';
|
||||
import 'package:kmobile/data/models/imps_transaction.dart';
|
||||
|
||||
class ImpsService {
|
||||
final Dio _dio;
|
||||
|
||||
ImpsService(this._dio);
|
||||
|
||||
Future<ImpsResponse> processImpsTransaction(
|
||||
ImpsTransaction transaction) async {
|
||||
try {
|
||||
await Future.delayed(const Duration(seconds: 3));
|
||||
final response = await _dio.post(
|
||||
'/api/payment/imps',
|
||||
data: transaction.toJson(),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return ImpsResponse.fromJson(response.data);
|
||||
} else {
|
||||
throw Exception(
|
||||
'IMPS transaction failed with status code: ${response.statusCode}');
|
||||
}
|
||||
} on DioException {
|
||||
rethrow;
|
||||
} catch (e) {
|
||||
throw Exception('An unexpected error occurred: ${e.toString()}');
|
||||
}
|
||||
}
|
||||
}
|
||||
87
lib/api/services/limit_service.dart
Normal file
@@ -0,0 +1,87 @@
|
||||
// ignore_for_file: collection_methods_unrelated_type
|
||||
import 'dart:developer';
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
class Limit {
|
||||
final double dailyLimit;
|
||||
final double usedLimit;
|
||||
|
||||
Limit({
|
||||
required this.dailyLimit,
|
||||
required this.usedLimit,
|
||||
});
|
||||
|
||||
factory Limit.fromJson(Map<String, dynamic> json) {
|
||||
return Limit(
|
||||
dailyLimit: (json['dailyLimit'] as num).toDouble(),
|
||||
usedLimit: (json['usedLimit'] as num).toDouble(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class LimitService {
|
||||
final Dio _dio;
|
||||
LimitService(this._dio);
|
||||
|
||||
Future<Limit> getLimit() async {
|
||||
try {
|
||||
final response = await _dio.get('/api/customer/daily-limit');
|
||||
if (response.statusCode == 200) {
|
||||
log('Response: ${response.data}');
|
||||
return Limit.fromJson(response.data);
|
||||
} else {
|
||||
throw Exception('Failed to load');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
throw Exception('Network error: ${e.message}');
|
||||
} catch (e) {
|
||||
throw Exception('Unexpected error: ${e.toString()}');
|
||||
}
|
||||
}
|
||||
|
||||
void editLimit(double newLimit) async {
|
||||
try {
|
||||
final response = await _dio.post('/api/customer/daily-limit',
|
||||
data: '{"amount": $newLimit}');
|
||||
if (response.statusCode == 200) {
|
||||
log('Response: ${response.data}');
|
||||
} else {
|
||||
throw Exception('Failed to load');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
throw Exception('Network error: ${e.message}');
|
||||
} catch (e) {
|
||||
throw Exception('Unexpected error: ${e.toString()}');
|
||||
}
|
||||
}
|
||||
|
||||
Future getOtpTLimit({
|
||||
required String mobileNumber,
|
||||
}) async {
|
||||
final response = await _dio.post(
|
||||
'/api/otp/send',
|
||||
data: {'mobileNumber': mobileNumber, 'type': "TLIMIT"},
|
||||
);
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception("Invalid Mobile Number/Type");
|
||||
}
|
||||
print(response.toString());
|
||||
return response.toString();
|
||||
}
|
||||
|
||||
Future validateOtp({
|
||||
required String otp,
|
||||
required String mobileNumber,
|
||||
}) async {
|
||||
final response = await _dio.post(
|
||||
'/api/otp/verify?mobileNumber=$mobileNumber',
|
||||
data: {
|
||||
'otp': otp,
|
||||
},
|
||||
);
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception("Wrong OTP");
|
||||
}
|
||||
return response.toString();
|
||||
}
|
||||
}
|
||||
34
lib/api/services/neft_service.dart
Normal file
@@ -0,0 +1,34 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:kmobile/data/models/neft_response.dart';
|
||||
import 'package:kmobile/data/models/neft_transaction.dart';
|
||||
|
||||
class NeftService {
|
||||
final Dio _dio;
|
||||
|
||||
NeftService(this._dio);
|
||||
|
||||
Future<NeftResponse> processNeftTransaction(
|
||||
NeftTransaction transaction) async {
|
||||
try {
|
||||
await Future.delayed(const Duration(seconds: 3));
|
||||
final response = await _dio.post(
|
||||
'/api/payment/neft',
|
||||
data: transaction.toJson(),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return NeftResponse.fromJson(response.data);
|
||||
} else {
|
||||
throw Exception(
|
||||
'NEFT transaction failed with status code: ${response.statusCode}');
|
||||
}
|
||||
} on DioException {
|
||||
log('DioException Occured');
|
||||
rethrow;
|
||||
} catch (e) {
|
||||
throw Exception('An unexpected error occurred: ${e.toString()}');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:kmobile/data/models/payment_response.dart';
|
||||
import 'package:kmobile/data/models/transfer.dart';
|
||||
@@ -11,7 +10,7 @@ class PaymentService {
|
||||
Future<PaymentResponse> processQuickPayWithinBank(Transfer transfer) async {
|
||||
try {
|
||||
await Future.delayed(const Duration(seconds: 3)); // Simulate delay
|
||||
|
||||
|
||||
await _dio.post('/api/payment/transfer', data: transfer.toJson());
|
||||
|
||||
return PaymentResponse(
|
||||
|
||||
31
lib/api/services/rtgs_service.dart
Normal file
@@ -0,0 +1,31 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:kmobile/data/models/rtgs_response.dart';
|
||||
import 'package:kmobile/data/models/rtgs_transaction.dart';
|
||||
|
||||
class RtgsService {
|
||||
final Dio _dio;
|
||||
|
||||
RtgsService(this._dio);
|
||||
|
||||
Future<RtgsResponse> processRtgsTransaction(
|
||||
RtgsTransaction transaction) async {
|
||||
try {
|
||||
await Future.delayed(const Duration(seconds: 3));
|
||||
final response = await _dio.post(
|
||||
'/api/payment/rtgs',
|
||||
data: transaction.toJson(),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return RtgsResponse.fromJson(response.data);
|
||||
} else {
|
||||
throw Exception(
|
||||
'RTGS transaction failed with status code: ${response.statusCode}');
|
||||
}
|
||||
} on DioException {
|
||||
rethrow;
|
||||
} catch (e) {
|
||||
throw Exception('An unexpected error occurred: ${e.toString()}');
|
||||
}
|
||||
}
|
||||
}
|
||||
102
lib/api/services/send_sms_service.dart
Normal file
@@ -0,0 +1,102 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:send_message/send_message.dart' show sendSMS;
|
||||
import 'package:simcards/sim_card.dart';
|
||||
import 'package:simcards/simcards.dart';
|
||||
|
||||
// This enum provides detailed status back to the UI layer.
|
||||
enum PermissionStatusResult { granted, denied, permanentlyDenied, restricted }
|
||||
|
||||
class SmsService {
|
||||
final Simcards _simcards = Simcards();
|
||||
|
||||
/// Handles the requesting of SMS and Phone permissions.
|
||||
/// Returns a detailed status: granted, denied, or permanentlyDenied.
|
||||
Future<PermissionStatusResult> handleSmsPermission() async {
|
||||
var smsStatus = await Permission.sms.status;
|
||||
var phoneStatus = await Permission.phone.status;
|
||||
|
||||
// Check initial status
|
||||
if (smsStatus.isGranted && phoneStatus.isGranted) {
|
||||
return PermissionStatusResult.granted;
|
||||
}
|
||||
if (smsStatus.isPermanentlyDenied || phoneStatus.isPermanentlyDenied) {
|
||||
return PermissionStatusResult.permanentlyDenied;
|
||||
}
|
||||
if (smsStatus.isRestricted || phoneStatus.isRestricted) {
|
||||
return PermissionStatusResult.restricted;
|
||||
}
|
||||
|
||||
// Request permissions if not granted
|
||||
print("Requesting SMS and Phone permissions...");
|
||||
await [Permission.phone, Permission.sms].request();
|
||||
|
||||
// Re-check status after request
|
||||
smsStatus = await Permission.sms.status;
|
||||
phoneStatus = await Permission.phone.status;
|
||||
|
||||
if (smsStatus.isGranted && phoneStatus.isGranted) {
|
||||
return PermissionStatusResult.granted;
|
||||
}
|
||||
if (smsStatus.isPermanentlyDenied || phoneStatus.isPermanentlyDenied) {
|
||||
return PermissionStatusResult.permanentlyDenied;
|
||||
}
|
||||
if (smsStatus.isRestricted || phoneStatus.isRestricted) {
|
||||
return PermissionStatusResult.restricted;
|
||||
}
|
||||
|
||||
// If none of the above, it's denied
|
||||
return PermissionStatusResult.denied;
|
||||
}
|
||||
|
||||
/// Tries to send a single verification SMS.
|
||||
/// This should only be called AFTER permissions have been granted.
|
||||
Future<bool> sendVerificationSms({
|
||||
required BuildContext context,
|
||||
required String destinationNumber,
|
||||
required String message,
|
||||
}) async {
|
||||
try {
|
||||
List<SimCard> simCardList = await _simcards.getSimCards();
|
||||
if (simCardList.isEmpty) {
|
||||
print("No SIM card detected.");
|
||||
return false;
|
||||
}
|
||||
return await _sendSms(destinationNumber, message, simCardList.first);
|
||||
} catch (e) {
|
||||
print("An error occurred in the SMS process: $e");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Private function to perform the SMS sending action.
|
||||
Future<bool> _sendSms(
|
||||
String destinationNumber, String message, SimCard selectedSim) async {
|
||||
if (Platform.isAndroid) {
|
||||
try {
|
||||
String smsMessage = message;
|
||||
String result = await sendSMS(
|
||||
message: smsMessage,
|
||||
recipients: [destinationNumber],
|
||||
sendDirect: true,
|
||||
);
|
||||
print("Background SMS send attempt result: $result");
|
||||
|
||||
if (result.toLowerCase().contains('sent')) {
|
||||
print("Success: SMS appears to have been sent.");
|
||||
return true;
|
||||
} else {
|
||||
print("Failure: SMS was not sent. Result: $result");
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
print("Error attempting to send SMS directly: $e");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
print("SMS sending is only supported on Android.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ class UserService {
|
||||
|
||||
Future<List<User>> getUserDetails() async {
|
||||
try {
|
||||
final response = await _dio.get('/api/customer/details');
|
||||
final response = await _dio.get('/api/customer');
|
||||
if (response.statusCode == 200) {
|
||||
log('Response: ${response.data}');
|
||||
return (response.data as List)
|
||||
@@ -28,4 +28,4 @@ class UserService {
|
||||
throw Exception('Unexpected error: ${e.toString()}');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
281
lib/app.dart
@@ -2,6 +2,8 @@ import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:kmobile/features/auth/controllers/theme_mode_cubit.dart';
|
||||
import 'package:kmobile/features/auth/controllers/theme_mode_state.dart';
|
||||
import 'package:kmobile/security/secure_storage.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import './l10n/app_localizations.dart';
|
||||
@@ -10,14 +12,15 @@ import 'package:kmobile/features/auth/controllers/theme_state.dart';
|
||||
import 'config/routes.dart';
|
||||
import 'di/injection.dart';
|
||||
import 'features/auth/controllers/auth_cubit.dart';
|
||||
import 'features/card/screens/card_management_screen.dart';
|
||||
import 'features/auth/screens/welcome_screen.dart';
|
||||
import 'features/accounts/screens/account_statement_screen.dart';
|
||||
import 'package:kmobile/features/auth/controllers/auth_state.dart';
|
||||
import 'features/auth/screens/login_screen.dart';
|
||||
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';
|
||||
import 'dart:async';
|
||||
|
||||
class KMobile extends StatefulWidget {
|
||||
const KMobile({super.key});
|
||||
@@ -26,38 +29,58 @@ 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 = true;
|
||||
class _KMobileState extends State<KMobile> with WidgetsBindingObserver {
|
||||
Timer? _backgroundTimer;
|
||||
Locale? _locale;
|
||||
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
loadPreferences();
|
||||
Future.delayed(const Duration(seconds: 2), () {
|
||||
setState(() {
|
||||
showSplash = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
_backgroundTimer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
super.didChangeAppLifecycleState(state);
|
||||
switch (state) {
|
||||
case AppLifecycleState.resumed:
|
||||
_backgroundTimer?.cancel();
|
||||
break;
|
||||
case AppLifecycleState.paused:
|
||||
_backgroundTimer = Timer(const Duration(minutes: 2), () {
|
||||
if (Platform.isAndroid) {
|
||||
SystemNavigator.pop();
|
||||
}
|
||||
exit(0);
|
||||
});
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> loadPreferences() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
|
||||
// Load Locale
|
||||
final String? langCode = prefs.getString('locale');
|
||||
if (langCode != null) {
|
||||
setState(() {
|
||||
_locale = Locale(langCode);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void setLocale(Locale locale) {
|
||||
@@ -66,57 +89,59 @@ class _KMobileState extends State<KMobile> {
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Set status bar color and brightness
|
||||
SystemChrome.setSystemUIOverlayStyle(
|
||||
const SystemUiOverlayStyle(
|
||||
statusBarColor: Colors.transparent,
|
||||
statusBarIconBrightness: Brightness.dark,
|
||||
),
|
||||
);
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
SystemChrome.setSystemUIOverlayStyle(
|
||||
const SystemUiOverlayStyle(
|
||||
statusBarColor: Colors.transparent,
|
||||
statusBarIconBrightness: Brightness.dark,
|
||||
),
|
||||
);
|
||||
|
||||
return MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider<AuthCubit>(create: (_) => getIt<AuthCubit>()),
|
||||
BlocProvider<ThemeCubit>(create: (_) => getIt<ThemeCubit>()),
|
||||
],
|
||||
child: BlocBuilder<ThemeCubit, ThemeState>(
|
||||
builder: (context, themeState) {
|
||||
print('global theme state changed');
|
||||
print(themeState);
|
||||
return MaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
locale: _locale ?? const Locale('en'),
|
||||
supportedLocales: const [
|
||||
Locale('en'),
|
||||
Locale('hi'),
|
||||
],
|
||||
localizationsDelegates: const [
|
||||
AppLocalizations.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
title: 'kMobile',
|
||||
//theme: AppThemes.getLightTheme(themeState.themeType),
|
||||
theme: themeState.getThemeData(),
|
||||
// darkTheme: AppThemes.getDarkTheme(themeState.themeType),
|
||||
themeMode: ThemeMode.system,
|
||||
onGenerateRoute: AppRoutes.generateRoute,
|
||||
initialRoute: AppRoutes.splash,
|
||||
home: showSplash ? const SplashScreen() : const AuthGate(),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
return MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider<AuthCubit>(create: (_) => getIt<AuthCubit>()),
|
||||
BlocProvider<ThemeCubit>(create: (_) => ThemeCubit()),
|
||||
BlocProvider<ThemeModeCubit>(create: (_) => ThemeModeCubit()),
|
||||
],
|
||||
child: BlocBuilder<ThemeCubit, ThemeState>(
|
||||
builder: (context, themeState) {
|
||||
return BlocBuilder<ThemeModeCubit, ThemeModeState>(
|
||||
builder: (context, modeState) {
|
||||
return MaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
locale: _locale ?? const Locale('en'),
|
||||
supportedLocales: const [
|
||||
Locale('en'),
|
||||
Locale('hi'),
|
||||
],
|
||||
localizationsDelegates: const [
|
||||
AppLocalizations.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
title: 'kMobile',
|
||||
theme: themeState.getLightThemeData(),
|
||||
darkTheme: themeState.getDarkThemeData(),
|
||||
themeMode: context.watch<ThemeModeCubit>().state.mode,
|
||||
navigatorObservers: [
|
||||
getIt<RouteObserver<ModalRoute<void>>>(),
|
||||
],
|
||||
onGenerateRoute: AppRoutes.generateRoute,
|
||||
initialRoute: AppRoutes.splash,
|
||||
home: const AuthGate(),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
class AuthGate extends StatefulWidget {
|
||||
const AuthGate({super.key});
|
||||
|
||||
@override
|
||||
State<AuthGate> createState() => _AuthGateState();
|
||||
}
|
||||
@@ -124,7 +149,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;
|
||||
@@ -142,8 +166,7 @@ class _AuthGateState extends State<AuthGate> {
|
||||
final mpin = await storage.read('mpin');
|
||||
final biometric = await storage.read('biometric_enabled');
|
||||
setState(() {
|
||||
_isLoggedIn =
|
||||
accessToken != null &&
|
||||
_isLoggedIn = accessToken != null &&
|
||||
accessTokenExpiry != null &&
|
||||
DateTime.parse(accessTokenExpiry).isAfter(DateTime.now());
|
||||
_hasMPin = mpin != null;
|
||||
@@ -158,9 +181,13 @@ class _AuthGateState extends State<AuthGate> {
|
||||
final localAuth = LocalAuthentication();
|
||||
final canCheck = await localAuth.canCheckBiometrics;
|
||||
if (!canCheck) return false;
|
||||
String localizedReason = "";
|
||||
if (mounted) {
|
||||
localizedReason = AppLocalizations.of(context).authenticateToAccess;
|
||||
}
|
||||
try {
|
||||
final didAuth = await localAuth.authenticate(
|
||||
localizedReason: AppLocalizations.of(context).authenticateToAccess,
|
||||
localizedReason: localizedReason,
|
||||
options: const AuthenticationOptions(
|
||||
stickyAuth: true,
|
||||
biometricOnly: true,
|
||||
@@ -172,24 +199,11 @@ class _AuthGateState extends State<AuthGate> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_checking) {
|
||||
return const SplashScreen();
|
||||
return const LoginScreen();
|
||||
}
|
||||
// ✅ 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) {
|
||||
@@ -197,14 +211,11 @@ class _AuthGateState extends State<AuthGate> {
|
||||
future: _tryBiometric(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const SplashScreen();
|
||||
return const LoginScreen();
|
||||
}
|
||||
|
||||
if (snapshot.data == true) {
|
||||
return const NavigationScaffold(); // Authenticated
|
||||
return const NavigationScaffold();
|
||||
}
|
||||
|
||||
// ❌ Biometric failed → Show MPIN screen
|
||||
return MPinScreen(
|
||||
mode: MPinMode.enter,
|
||||
onCompleted: (_) {
|
||||
@@ -230,13 +241,11 @@ class _AuthGateState extends State<AuthGate> {
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// No MPIN set → show MPIN set screen + biometric dialog
|
||||
return MPinScreen(
|
||||
mode: MPinMode.set,
|
||||
onCompleted: (_) async {
|
||||
final storage = getIt<SecureStorage>();
|
||||
final localAuth = LocalAuthentication();
|
||||
|
||||
final optIn = await showDialog<bool>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
@@ -257,15 +266,16 @@ class _AuthGateState extends State<AuthGate> {
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (optIn == true) {
|
||||
final canCheck = await localAuth.canCheckBiometrics;
|
||||
bool didAuth = false;
|
||||
|
||||
String authEnable = "";
|
||||
if (context.mounted) {
|
||||
authEnable = AppLocalizations.of(context).authenticateToEnable;
|
||||
}
|
||||
if (canCheck) {
|
||||
didAuth = await localAuth.authenticate(
|
||||
localizedReason:
|
||||
AppLocalizations.of(context).authenticateToEnable,
|
||||
localizedReason: authEnable,
|
||||
options: const AuthenticationOptions(
|
||||
stickyAuth: true,
|
||||
biometricOnly: true,
|
||||
@@ -277,25 +287,23 @@ class _AuthGateState extends State<AuthGate> {
|
||||
await storage.write('biometric_enabled', 'false');
|
||||
}
|
||||
}
|
||||
|
||||
Navigator.of(context).pushReplacement(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => const NavigationScaffold(),
|
||||
),
|
||||
);
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).pushReplacement(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => const NavigationScaffold(),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ✅ Step 3: If not logged in, show login screen
|
||||
return const LoginScreen();
|
||||
}
|
||||
}
|
||||
|
||||
class NavigationScaffold extends StatefulWidget {
|
||||
const NavigationScaffold({super.key});
|
||||
|
||||
@override
|
||||
State<NavigationScaffold> createState() => _NavigationScaffoldState();
|
||||
}
|
||||
@@ -303,20 +311,26 @@ class NavigationScaffold extends StatefulWidget {
|
||||
class _NavigationScaffoldState extends State<NavigationScaffold> {
|
||||
final PageController _pageController = PageController();
|
||||
int _selectedIndex = 0;
|
||||
|
||||
final List<Widget> _pages = [
|
||||
const DashboardScreen(),
|
||||
const CardManagementScreen(),
|
||||
BlocBuilder<AuthCubit, AuthState>(
|
||||
builder: (context, state) {
|
||||
if (state is Authenticated) {
|
||||
if (state.users.isNotEmpty) {
|
||||
return AccountStatementScreen(
|
||||
users: state.users,
|
||||
selectedIndex: 0,
|
||||
);
|
||||
} else {
|
||||
return const Center(child: Text("No accounts found."));
|
||||
}
|
||||
}
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
},
|
||||
),
|
||||
const ServiceScreen(),
|
||||
];
|
||||
|
||||
void _onItemTapped(int index) {
|
||||
setState(() {
|
||||
_selectedIndex = index;
|
||||
});
|
||||
_pageController.jumpToPage(index);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PopScope(
|
||||
@@ -357,18 +371,23 @@ class _NavigationScaffoldState extends State<NavigationScaffold> {
|
||||
bottomNavigationBar: BottomNavigationBar(
|
||||
currentIndex: _selectedIndex,
|
||||
type: BottomNavigationBarType.fixed,
|
||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor, // Light blue background
|
||||
selectedItemColor: Theme.of(context).primaryColor,
|
||||
unselectedItemColor: Colors.black54,
|
||||
onTap: _onItemTapped,
|
||||
backgroundColor: const Color(0XFF1E58AD),
|
||||
selectedItemColor: Theme.of(context).colorScheme.onPrimary,
|
||||
unselectedItemColor: Theme.of(context).colorScheme.onSecondary,
|
||||
onTap: (index) {
|
||||
setState(() {
|
||||
_selectedIndex = index;
|
||||
});
|
||||
_pageController.jumpToPage(index);
|
||||
},
|
||||
items: [
|
||||
BottomNavigationBarItem(
|
||||
icon: const Icon(Icons.home_filled),
|
||||
label: AppLocalizations.of(context).home,
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: const Icon(Icons.credit_card),
|
||||
label: AppLocalizations.of(context).card,
|
||||
icon: const Icon(Icons.swap_vert_sharp),
|
||||
label: AppLocalizations.of(context).transactions,
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: const Icon(Icons.miscellaneous_services),
|
||||
@@ -381,34 +400,9 @@ 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;
|
||||
const BiometricPromptScreen({super.key, required this.onCompleted});
|
||||
|
||||
Future<void> _handleBiometric(BuildContext context) async {
|
||||
final localAuth = LocalAuthentication();
|
||||
final canCheck = await localAuth.canCheckBiometrics;
|
||||
@@ -416,8 +410,12 @@ class BiometricPromptScreen extends StatelessWidget {
|
||||
onCompleted();
|
||||
return;
|
||||
}
|
||||
String localizedReason = "";
|
||||
if (context.mounted) {
|
||||
localizedReason = AppLocalizations.of(context).enableFingerprintQuick;
|
||||
}
|
||||
final didAuth = await localAuth.authenticate(
|
||||
localizedReason: AppLocalizations.of(context).enableFingerprintQuick,
|
||||
localizedReason: localizedReason,
|
||||
options: const AuthenticationOptions(
|
||||
stickyAuth: true,
|
||||
biometricOnly: true,
|
||||
@@ -435,7 +433,7 @@ class BiometricPromptScreen extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Future.microtask(() => _showDialog(context));
|
||||
return const SplashScreen();
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
Future<void> _showDialog(BuildContext context) async {
|
||||
@@ -461,6 +459,9 @@ class BiometricPromptScreen extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
);
|
||||
if (!context.mounted) {
|
||||
return;
|
||||
}
|
||||
if (result == true) {
|
||||
await _handleBiometric(context);
|
||||
} else {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:kmobile/features/auth/screens/mpin_screen.dart';
|
||||
import 'package:kmobile/features/auth/screens/splash_screen.dart';
|
||||
import '../app.dart';
|
||||
import '../features/auth/screens/login_screen.dart';
|
||||
// import '../features/auth/screens/forgot_password_screen.dart';
|
||||
@@ -9,11 +10,12 @@ import '../features/dashboard/screens/dashboard_screen.dart';
|
||||
// import '../features/transactions/screens/transactions_screen.dart';
|
||||
// import '../features/payments/screens/payments_screen.dart';
|
||||
// import '../features/settings/screens/settings_screen.dart';
|
||||
import 'package:kmobile/features/auth/screens/tnc_required_screen.dart';
|
||||
|
||||
class AppRoutes {
|
||||
// Private constructor to prevent instantiation
|
||||
AppRoutes._();
|
||||
|
||||
|
||||
// Route names
|
||||
static const String splash = '/';
|
||||
static const String login = '/login';
|
||||
@@ -25,7 +27,7 @@ class AppRoutes {
|
||||
static const String accounts = '/accounts';
|
||||
static const String transactions = '/transactions';
|
||||
static const String payments = '/payments';
|
||||
|
||||
|
||||
// Route generator
|
||||
static Route<dynamic> generateRoute(RouteSettings settings) {
|
||||
switch (settings.name) {
|
||||
@@ -33,15 +35,20 @@ class AppRoutes {
|
||||
return MaterialPageRoute(builder: (_) => const SplashScreen());
|
||||
case login:
|
||||
return MaterialPageRoute(builder: (_) => const LoginScreen());
|
||||
|
||||
case TncRequiredScreen.routeName: // Renamed class
|
||||
return MaterialPageRoute(
|
||||
builder: (_) => const TncRequiredScreen()); // Renamed class
|
||||
case mPin:
|
||||
return MaterialPageRoute(builder: (_) => const MPinScreen(mode: MPinMode.enter,));
|
||||
return MaterialPageRoute(
|
||||
builder: (_) => const MPinScreen(
|
||||
mode: MPinMode.enter,
|
||||
));
|
||||
|
||||
case register:
|
||||
// Placeholder - create the RegisterScreen class and uncomment
|
||||
// return MaterialPageRoute(builder: (_) => const RegisterScreen());
|
||||
return _errorRoute();
|
||||
|
||||
|
||||
case forgotPassword:
|
||||
// Placeholder - create the ForgotPasswordScreen class and uncomment
|
||||
// return MaterialPageRoute(builder: (_) => const ForgotPasswordScreen());
|
||||
@@ -49,31 +56,30 @@ class AppRoutes {
|
||||
|
||||
case navigationScaffold:
|
||||
return MaterialPageRoute(builder: (_) => const NavigationScaffold());
|
||||
|
||||
|
||||
case dashboard:
|
||||
return MaterialPageRoute(builder: (_) => const DashboardScreen());
|
||||
|
||||
|
||||
case accounts:
|
||||
// Placeholder - create the AccountsScreen class and uncomment
|
||||
// return MaterialPageRoute(builder: (_) => const AccountsScreen());
|
||||
return _errorRoute();
|
||||
|
||||
|
||||
case transactions:
|
||||
// Placeholder - create the TransactionsScreen class and uncomment
|
||||
// return MaterialPageRoute(builder: (_) => const TransactionsScreen());
|
||||
return _errorRoute();
|
||||
|
||||
|
||||
case payments:
|
||||
// Placeholder - create the PaymentsScreen class and uncomment
|
||||
// return MaterialPageRoute(builder: (_) => const PaymentsScreen());
|
||||
return _errorRoute();
|
||||
|
||||
|
||||
|
||||
default:
|
||||
return _errorRoute();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Error route
|
||||
static Route<dynamic> _errorRoute() {
|
||||
return MaterialPageRoute(builder: (_) {
|
||||
@@ -87,4 +93,4 @@ class AppRoutes {
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
enum ThemeType {
|
||||
violet,
|
||||
green,
|
||||
orange,
|
||||
blue,
|
||||
}
|
||||
violet,
|
||||
green,
|
||||
orange,
|
||||
blue,
|
||||
yellow,
|
||||
}
|
||||
|
||||
@@ -1,32 +1,72 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'theme_type.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
|
||||
class AppThemes {
|
||||
static ThemeData getLightTheme(ThemeType type) {
|
||||
switch (type) {
|
||||
case ThemeType.green:
|
||||
return ThemeData(primarySwatch: Colors.green);
|
||||
case ThemeType.orange:
|
||||
return ThemeData(primarySwatch: Colors.orange);
|
||||
case ThemeType.blue:
|
||||
return ThemeData(primarySwatch: Colors.blue);
|
||||
case ThemeType.violet:
|
||||
default:
|
||||
return ThemeData(primarySwatch: Colors.deepPurple);
|
||||
}
|
||||
}
|
||||
final Color seedColor = _getSeedColor(type);
|
||||
final colorScheme = ColorScheme.fromSeed(
|
||||
seedColor: seedColor,
|
||||
brightness: Brightness.light,
|
||||
);
|
||||
return ThemeData.from(
|
||||
colorScheme: colorScheme,
|
||||
useMaterial3: true,
|
||||
textTheme: GoogleFonts.rubikTextTheme(),
|
||||
).copyWith(
|
||||
appBarTheme: AppBarTheme(
|
||||
backgroundColor: const Color(0xFF01A04C),
|
||||
titleTextStyle: TextStyle(
|
||||
color: colorScheme.onPrimary,
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 20,
|
||||
),
|
||||
iconTheme: IconThemeData(color: colorScheme.onPrimary),
|
||||
actionsIconTheme: IconThemeData(color: colorScheme.onPrimary),
|
||||
));
|
||||
}
|
||||
|
||||
static ThemeData getDarkTheme(ThemeType type) {
|
||||
final Color seedColor = _getSeedColor(type);
|
||||
log(seedColor.toString());
|
||||
final colorScheme = ColorScheme.fromSeed(
|
||||
seedColor: seedColor,
|
||||
brightness: Brightness.dark,
|
||||
);
|
||||
|
||||
return ThemeData.from(
|
||||
colorScheme: colorScheme,
|
||||
useMaterial3: true,
|
||||
textTheme: GoogleFonts.rubikTextTheme(
|
||||
ThemeData(brightness: Brightness.dark).textTheme,
|
||||
),
|
||||
).copyWith(
|
||||
appBarTheme: AppBarTheme(
|
||||
backgroundColor: const Color(0xFF01A04C),
|
||||
titleTextStyle: TextStyle(
|
||||
color: colorScheme.onPrimary,
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 20,
|
||||
),
|
||||
iconTheme: IconThemeData(color: colorScheme.onPrimary),
|
||||
actionsIconTheme: IconThemeData(color: colorScheme.onPrimary),
|
||||
));
|
||||
}
|
||||
|
||||
static Color _getSeedColor(ThemeType type) {
|
||||
switch (type) {
|
||||
case ThemeType.green:
|
||||
return ThemeData.dark().copyWith(primaryColor: Colors.green);
|
||||
return Colors.green;
|
||||
case ThemeType.orange:
|
||||
return ThemeData.dark().copyWith(primaryColor: Colors.orange);
|
||||
return Colors.orange;
|
||||
case ThemeType.blue:
|
||||
return ThemeData.dark().copyWith(primaryColor: Colors.blue);
|
||||
return Colors.blue;
|
||||
case ThemeType.violet:
|
||||
default:
|
||||
return ThemeData.dark().copyWith(primaryColor: Colors.deepPurple);
|
||||
return Colors.deepPurple;
|
||||
case ThemeType.yellow:
|
||||
return Colors.yellow;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
class AppException implements Exception {
|
||||
final String message;
|
||||
|
||||
|
||||
AppException(this.message);
|
||||
|
||||
|
||||
@override
|
||||
String toString() => message;
|
||||
}
|
||||
@@ -11,7 +11,7 @@ class NetworkException extends AppException {
|
||||
NetworkException(super.message);
|
||||
}
|
||||
|
||||
class AuthException implements Exception{
|
||||
class AuthException implements Exception {
|
||||
final String message;
|
||||
AuthException(this.message);
|
||||
|
||||
@@ -21,4 +21,4 @@ class AuthException implements Exception{
|
||||
|
||||
class UnexpectedException extends AppException {
|
||||
UnexpectedException(super.message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,47 +1,61 @@
|
||||
|
||||
|
||||
// ignore_for_file: non_constant_identifier_names
|
||||
|
||||
class Beneficiary {
|
||||
final String accountNo;
|
||||
final String accountType;
|
||||
final String name;
|
||||
final DateTime? createdAt;
|
||||
final String ifscCode;
|
||||
final String? bankName;
|
||||
final String? branchName;
|
||||
final String? tpin;
|
||||
|
||||
Beneficiary({
|
||||
required this.accountNo,
|
||||
required this.accountType,
|
||||
required this.name,
|
||||
this.createdAt,
|
||||
required this.ifscCode,
|
||||
this.bankName,
|
||||
this.branchName,
|
||||
this.tpin,
|
||||
});
|
||||
|
||||
factory Beneficiary.fromJson(Map<String, dynamic> json) {
|
||||
return Beneficiary(
|
||||
accountNo: json['accountNo'] ?? '',
|
||||
accountType: json['accountType'] ?? '',
|
||||
accountNo: json['account_no'] ?? json['accountNo'] ?? '',
|
||||
accountType: json['account_type'] ?? json['accountType'] ?? '',
|
||||
createdAt: json['createdAt'] == null
|
||||
? null
|
||||
: DateTime.tryParse(json['createdAt']),
|
||||
name: json['name'] ?? '',
|
||||
ifscCode: json['ifscCode'] ?? '',
|
||||
bankName: json['bankName'] ?? '',
|
||||
branchName: json['branchName'] ?? '',
|
||||
ifscCode: json['ifsc_code'] ?? json['ifscCode'] ?? '',
|
||||
bankName: json['bank_name'] ?? json['bankName'] ?? '',
|
||||
branchName: json['branch_name'] ?? json['branchName'] ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
final Map<String, dynamic> json = {
|
||||
'accountNo': accountNo,
|
||||
'accountType': accountType,
|
||||
'name': name,
|
||||
'ifscCode' : ifscCode,
|
||||
'ifscCode': ifscCode,
|
||||
};
|
||||
if (bankName != null && bankName!.isNotEmpty) {
|
||||
json['bankName'] = bankName;
|
||||
}
|
||||
if (branchName != null && branchName!.isNotEmpty) {
|
||||
json['branchName'] = branchName;
|
||||
}
|
||||
if (tpin != null && tpin!.isNotEmpty) {
|
||||
json['tpin'] = tpin;
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
static List<Beneficiary> listFromJson(List<dynamic> jsonList) {
|
||||
final beneficiaryList = jsonList.map((beneficiary) => Beneficiary.fromJson(beneficiary)).toList();
|
||||
print(beneficiaryList);
|
||||
final beneficiaryList = jsonList
|
||||
.map((beneficiary) => Beneficiary.fromJson(beneficiary))
|
||||
.toList();
|
||||
return beneficiaryList;
|
||||
}
|
||||
|
||||
@@ -49,4 +63,4 @@ class Beneficiary {
|
||||
String toString() {
|
||||
return 'Beneficiary(accountNo: $accountNo, accountType: $accountType, ifscCode: $ifscCode, name: $name)';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
class BeneficiaryRecieve {
|
||||
final String accountNo;
|
||||
final String accountType;
|
||||
final String name;
|
||||
final String ifscCode;
|
||||
final String bankName;
|
||||
final String branchName;
|
||||
|
||||
|
||||
BeneficiaryRecieve({
|
||||
required this.accountNo,
|
||||
required this.accountType,
|
||||
required this.name,
|
||||
required this.ifscCode,
|
||||
required this.bankName,
|
||||
required this.branchName,
|
||||
});
|
||||
|
||||
factory BeneficiaryRecieve.fromJson(Map<String, dynamic> json) {
|
||||
return BeneficiaryRecieve(
|
||||
accountNo: json['account_no'] ?? '',
|
||||
accountType: json['account_type'] ?? '',
|
||||
name: json['name'] ?? '',
|
||||
ifscCode: json['ifsc_code'] ?? '',
|
||||
bankName: json['bank_name'] ?? '',
|
||||
branchName: json['branch_name'] ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'account_no': accountNo,
|
||||
'account_type': accountType,
|
||||
'name': name,
|
||||
'ifsc_code' : ifscCode,
|
||||
'bank_name' : bankName,
|
||||
'branch_name' : branchName
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ListBeneficiary(accountNo: $accountNo, accountType: $accountType, ifscCode: $ifscCode, name: $name, bankName: $bankName, branchName: $branchName)';
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
class ifsc {
|
||||
class Ifsc {
|
||||
final String ifscCode;
|
||||
final String bankName;
|
||||
final String branchName;
|
||||
|
||||
ifsc({
|
||||
Ifsc({
|
||||
required this.ifscCode,
|
||||
required this.bankName,
|
||||
required this.branchName,
|
||||
});
|
||||
|
||||
factory ifsc.fromJson(Map<String, dynamic> json) {
|
||||
return ifsc(
|
||||
factory Ifsc.fromJson(Map<String, dynamic> json) {
|
||||
return Ifsc(
|
||||
ifscCode: json['ifsc_code'] ?? '',
|
||||
bankName: json['bank_name'] ?? '',
|
||||
branchName: json['branch_name'] ?? '',
|
||||
@@ -29,4 +29,4 @@ class ifsc {
|
||||
String toString() {
|
||||
return 'IFSC(ifscCode: $ifscCode, bankName: $bankName, branchName: $branchName)';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
16
lib/data/models/imps_response.dart
Normal file
@@ -0,0 +1,16 @@
|
||||
class ImpsResponse {
|
||||
final String message;
|
||||
final String utr;
|
||||
|
||||
ImpsResponse({
|
||||
required this.message,
|
||||
required this.utr,
|
||||
});
|
||||
|
||||
factory ImpsResponse.fromJson(Map<String, dynamic> json) {
|
||||
return ImpsResponse(
|
||||
message: json['message'] ?? '',
|
||||
utr: json['utr'] ?? '',
|
||||
);
|
||||
}
|
||||
}
|
||||
34
lib/data/models/imps_transaction.dart
Normal file
@@ -0,0 +1,34 @@
|
||||
class ImpsTransaction {
|
||||
final String fromAccount;
|
||||
final String toAccount;
|
||||
final String amount;
|
||||
final String ifscCode;
|
||||
final String? remitterName;
|
||||
final String beneficiaryName;
|
||||
final String tpin;
|
||||
final String? remarks;
|
||||
|
||||
ImpsTransaction({
|
||||
required this.fromAccount,
|
||||
required this.toAccount,
|
||||
required this.amount,
|
||||
required this.ifscCode,
|
||||
this.remitterName,
|
||||
required this.beneficiaryName,
|
||||
required this.tpin,
|
||||
this.remarks,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'fromAccount': fromAccount,
|
||||
'toAccount': toAccount,
|
||||
'amount': amount,
|
||||
'ifscCode': ifscCode,
|
||||
'remitterName': remitterName,
|
||||
'beneficiaryName': beneficiaryName,
|
||||
'tpin': tpin,
|
||||
'remarks': remarks,
|
||||
};
|
||||
}
|
||||
}
|
||||
16
lib/data/models/neft_response.dart
Normal file
@@ -0,0 +1,16 @@
|
||||
class NeftResponse {
|
||||
final String message;
|
||||
final String utr;
|
||||
|
||||
NeftResponse({
|
||||
required this.message,
|
||||
required this.utr,
|
||||
});
|
||||
|
||||
factory NeftResponse.fromJson(Map<String, dynamic> json) {
|
||||
return NeftResponse(
|
||||
message: json['message'] ?? '',
|
||||
utr: json['utr'] ?? '',
|
||||
);
|
||||
}
|
||||
}
|
||||
34
lib/data/models/neft_transaction.dart
Normal file
@@ -0,0 +1,34 @@
|
||||
class NeftTransaction {
|
||||
final String fromAccount;
|
||||
final String toAccount;
|
||||
final String amount;
|
||||
final String ifscCode;
|
||||
final String remitterName;
|
||||
final String beneficiaryName;
|
||||
final String tpin;
|
||||
final String? remarks;
|
||||
|
||||
NeftTransaction({
|
||||
required this.fromAccount,
|
||||
required this.toAccount,
|
||||
required this.amount,
|
||||
required this.ifscCode,
|
||||
required this.remitterName,
|
||||
required this.beneficiaryName,
|
||||
required this.tpin,
|
||||
this.remarks,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'fromAccount': fromAccount,
|
||||
'toAccount': toAccount,
|
||||
'amount': amount,
|
||||
'ifscCode': ifscCode,
|
||||
'remitterName': remitterName,
|
||||
'beneficiaryName': beneficiaryName,
|
||||
'tpin': tpin,
|
||||
'remarks': remarks,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ class PaymentResponse {
|
||||
final String? currency;
|
||||
final String? errorMessage;
|
||||
final String? errorCode;
|
||||
final String? utr;
|
||||
|
||||
PaymentResponse({
|
||||
required this.isSuccess,
|
||||
@@ -15,5 +16,6 @@ class PaymentResponse {
|
||||
this.currency,
|
||||
this.errorMessage,
|
||||
this.errorCode,
|
||||
this.utr,
|
||||
});
|
||||
}
|
||||
|
||||
16
lib/data/models/rtgs_response.dart
Normal file
@@ -0,0 +1,16 @@
|
||||
class RtgsResponse {
|
||||
final String message;
|
||||
final String utr;
|
||||
|
||||
RtgsResponse({
|
||||
required this.message,
|
||||
required this.utr,
|
||||
});
|
||||
|
||||
factory RtgsResponse.fromJson(Map<String, dynamic> json) {
|
||||
return RtgsResponse(
|
||||
message: json['message'] ?? '',
|
||||
utr: json['utr'] ?? '',
|
||||
);
|
||||
}
|
||||
}
|
||||
34
lib/data/models/rtgs_transaction.dart
Normal file
@@ -0,0 +1,34 @@
|
||||
class RtgsTransaction {
|
||||
final String fromAccount;
|
||||
final String toAccount;
|
||||
final String amount;
|
||||
final String ifscCode;
|
||||
final String remitterName;
|
||||
final String beneficiaryName;
|
||||
final String tpin;
|
||||
final String? remarks;
|
||||
|
||||
RtgsTransaction({
|
||||
required this.fromAccount,
|
||||
required this.toAccount,
|
||||
required this.amount,
|
||||
required this.ifscCode,
|
||||
required this.remitterName,
|
||||
required this.beneficiaryName,
|
||||
required this.tpin,
|
||||
this.remarks,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'fromAccount': fromAccount,
|
||||
'toAccount': toAccount,
|
||||
'amount': amount,
|
||||
'ifscCode': ifscCode,
|
||||
'remitterName': remitterName,
|
||||
'beneficiaryName': beneficiaryName,
|
||||
'tpin': tpin,
|
||||
'remarks': remarks,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,18 @@ class Transaction {
|
||||
final String? date;
|
||||
final String? amount;
|
||||
final String? type;
|
||||
final String? balance;
|
||||
final String? balanceType;
|
||||
|
||||
Transaction(
|
||||
{this.id,
|
||||
this.name,
|
||||
this.date,
|
||||
this.amount,
|
||||
this.type,
|
||||
this.balance,
|
||||
this.balanceType});
|
||||
|
||||
Transaction({this.id, this.name, this.date, this.amount, this.type});
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
@@ -13,16 +23,19 @@ class Transaction {
|
||||
'date': date,
|
||||
'amount': amount,
|
||||
'type': type,
|
||||
'balance': balance,
|
||||
'balanceType': balanceType
|
||||
};
|
||||
}
|
||||
|
||||
factory Transaction.fromJson(Map<String, dynamic> json) {
|
||||
return Transaction(
|
||||
id: json['id'] as String?,
|
||||
name: json['name'] as String?,
|
||||
date: json['date'] as String?,
|
||||
amount: json['amount'] as String?,
|
||||
type: json['type'] as String?,
|
||||
);
|
||||
id: json['id'] as String?,
|
||||
name: json['name'] as String?,
|
||||
date: json['date'] as String?,
|
||||
amount: json['amount'] as String?,
|
||||
type: json['type'] as String?,
|
||||
balance: json['balance'] as String?,
|
||||
balanceType: json['balanceType'] as String?);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ class Transfer {
|
||||
final String toAccountType;
|
||||
final String amount;
|
||||
String? tpin;
|
||||
String? remarks;
|
||||
|
||||
Transfer({
|
||||
required this.fromAccount,
|
||||
@@ -11,6 +12,7 @@ class Transfer {
|
||||
required this.toAccountType,
|
||||
required this.amount,
|
||||
this.tpin,
|
||||
this.remarks,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
@@ -20,6 +22,7 @@ class Transfer {
|
||||
'toAccountType': toAccountType,
|
||||
'amount': amount,
|
||||
'tpin': tpin,
|
||||
'remarks': remarks,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -32,7 +35,7 @@ class TransferResponse {
|
||||
TransferResponse({
|
||||
required this.status,
|
||||
required this.message,
|
||||
required this.error,
|
||||
required this.error,
|
||||
});
|
||||
|
||||
factory TransferResponse.fromJson(Map<String, dynamic> json) {
|
||||
@@ -42,4 +45,4 @@ class TransferResponse {
|
||||
error: json['error'] as String?,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,53 +10,77 @@ class AuthRepository {
|
||||
final AuthService _authService;
|
||||
final UserService _userService;
|
||||
final SecureStorage _secureStorage;
|
||||
|
||||
|
||||
static const _accessTokenKey = 'access_token';
|
||||
static const _tokenExpiryKey = 'token_expiry';
|
||||
static const _tncKey = 'tnc';
|
||||
|
||||
AuthRepository(this._authService, this._userService, this._secureStorage);
|
||||
|
||||
Future<List<User>> login(String customerNo, String password) async {
|
||||
Future<(List<User>, AuthToken)> login(
|
||||
String customerNo, String password) async {
|
||||
// Create credentials and call service
|
||||
final credentials = AuthCredentials(customerNo: customerNo, password: password);
|
||||
final credentials =
|
||||
AuthCredentials(customerNo: customerNo, password: password);
|
||||
final authToken = await _authService.login(credentials);
|
||||
|
||||
|
||||
// Save token securely
|
||||
await _saveAuthToken(authToken);
|
||||
|
||||
|
||||
// Get and save user profile
|
||||
final users = await _userService.getUserDetails();
|
||||
return users;
|
||||
return (users, authToken);
|
||||
}
|
||||
|
||||
|
||||
Future<bool> isLoggedIn() async {
|
||||
final token = await _getAuthToken();
|
||||
return token != null && !token.isExpired;
|
||||
}
|
||||
|
||||
|
||||
Future<String?> getAccessToken() async {
|
||||
final token = await _getAuthToken();
|
||||
if (token == null) return null;
|
||||
|
||||
|
||||
return token.accessToken;
|
||||
}
|
||||
|
||||
|
||||
// Private helper methods
|
||||
Future<void> _saveAuthToken(AuthToken token) async {
|
||||
await _secureStorage.write(_accessTokenKey, token.accessToken);
|
||||
await _secureStorage.write(_tokenExpiryKey, token.expiresAt.toIso8601String());
|
||||
await _secureStorage.write(
|
||||
_tokenExpiryKey, token.expiresAt.toIso8601String());
|
||||
await _secureStorage.write(_tncKey, token.tnc.toString());
|
||||
}
|
||||
|
||||
|
||||
Future<void> clearAuthTokens() async {
|
||||
await _secureStorage.deleteAll();
|
||||
}
|
||||
|
||||
Future<AuthToken?> _getAuthToken() async {
|
||||
final accessToken = await _secureStorage.read(_accessTokenKey);
|
||||
final expiryString = await _secureStorage.read(_tokenExpiryKey);
|
||||
final tncString = await _secureStorage.read(_tncKey);
|
||||
|
||||
if (accessToken != null && expiryString != null) {
|
||||
return AuthToken(
|
||||
final authToken = AuthToken(
|
||||
accessToken: accessToken,
|
||||
expiresAt: DateTime.parse(expiryString),
|
||||
tnc:
|
||||
tncString == 'true', // Parse 'true' string to true, otherwise false
|
||||
);
|
||||
return authToken;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> acceptTnc() async {
|
||||
// This method calls the setTncFlag function
|
||||
try {
|
||||
await _authService.setTncflag();
|
||||
} catch (e) {
|
||||
// Handle or rethrow the error as needed
|
||||
print('Error setting TNC flag: $e');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:kmobile/data/models/transaction.dart';
|
||||
|
||||
abstract class TransactionRepository {
|
||||
Future<List<Transaction>> fetchTransactions(String accountNo);
|
||||
Future<List<Transaction>> fetchTransactions(String accountNo,
|
||||
{DateTime? fromDate, DateTime? toDate});
|
||||
}
|
||||
|
||||
class TransactionRepositoryImpl implements TransactionRepository {
|
||||
@@ -10,9 +12,21 @@ class TransactionRepositoryImpl implements TransactionRepository {
|
||||
TransactionRepositoryImpl(this._dio);
|
||||
|
||||
@override
|
||||
Future<List<Transaction>> fetchTransactions(String accountNo) async {
|
||||
Future<List<Transaction>> fetchTransactions(String accountNo,
|
||||
{DateTime? fromDate, DateTime? toDate}) async {
|
||||
final queryParameters = <String, String>{};
|
||||
|
||||
final resp = await _dio.get('/api/transactions/account/$accountNo');
|
||||
if (fromDate != null) {
|
||||
queryParameters['fromDate'] = DateFormat('ddMMyyyy').format(fromDate);
|
||||
}
|
||||
if (toDate != null) {
|
||||
queryParameters['toDate'] = DateFormat('ddMMyyyy').format(toDate);
|
||||
}
|
||||
|
||||
final resp = await _dio.get(
|
||||
'/api/transactions/account/$accountNo',
|
||||
queryParameters: queryParameters.isNotEmpty ? queryParameters : null,
|
||||
);
|
||||
|
||||
if (resp.statusCode != 200) {
|
||||
throw Exception(
|
||||
@@ -25,4 +39,4 @@ class TransactionRepositoryImpl implements TransactionRepository {
|
||||
.map((e) => Transaction.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import 'package:kmobile/data/models/transfer.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
|
||||
abstract class TransferRepository {
|
||||
Future<TransferResponse> transfer(Transfer transfer);
|
||||
}
|
||||
@@ -25,4 +24,4 @@ class TransferRepositoryImpl implements TransferRepository {
|
||||
|
||||
return TransferResponse.fromJson(resp.data as Map<String, dynamic>);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:kmobile/api/services/branch_service.dart';
|
||||
import 'package:kmobile/api/services/limit_service.dart';
|
||||
import 'package:kmobile/api/services/rtgs_service.dart';
|
||||
import 'package:kmobile/api/services/neft_service.dart';
|
||||
import 'package:kmobile/api/services/imps_service.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:kmobile/api/services/beneficiary_service.dart';
|
||||
@@ -5,20 +11,23 @@ import 'package:kmobile/api/services/payment_service.dart';
|
||||
import 'package:kmobile/api/services/user_service.dart';
|
||||
import 'package:kmobile/data/repositories/transaction_repository.dart';
|
||||
import 'package:kmobile/features/auth/controllers/theme_cubit.dart';
|
||||
import 'package:kmobile/features/auth/controllers/theme_mode_cubit.dart';
|
||||
import '../api/services/auth_service.dart';
|
||||
import '../api/interceptors/auth_interceptor.dart';
|
||||
import '../api/services/change_password_service.dart';
|
||||
import '../data/repositories/auth_repository.dart';
|
||||
import '../features/auth/controllers/auth_cubit.dart';
|
||||
import '../security/secure_storage.dart';
|
||||
|
||||
|
||||
final getIt = GetIt.instance;
|
||||
|
||||
Future<void> setupDependencies() async {
|
||||
|
||||
getIt.registerSingleton<RouteObserver<ModalRoute<void>>>(
|
||||
RouteObserver<ModalRoute<void>>());
|
||||
//getIt.registerLazySingleton<ThemeController>(() => ThemeController());
|
||||
//getIt.registerLazySingleton<ThemeModeController>(() => ThemeModeController());
|
||||
getIt.registerSingleton<ThemeCubit>( ThemeCubit());
|
||||
getIt.registerSingleton<ThemeCubit>(ThemeCubit());
|
||||
getIt.registerSingleton<ThemeModeCubit>(ThemeModeCubit());
|
||||
|
||||
// Register Dio client
|
||||
getIt.registerSingleton<Dio>(_createDioClient());
|
||||
@@ -42,6 +51,14 @@ Future<void> setupDependencies() async {
|
||||
|
||||
getIt.registerSingleton<PaymentService>(PaymentService(getIt<Dio>()));
|
||||
getIt.registerSingleton<BeneficiaryService>(BeneficiaryService(getIt<Dio>()));
|
||||
getIt.registerSingleton<LimitService>(LimitService(getIt<Dio>()));
|
||||
getIt.registerSingleton<NeftService>(NeftService(getIt<Dio>()));
|
||||
getIt.registerSingleton<RtgsService>(RtgsService(getIt<Dio>()));
|
||||
getIt.registerSingleton<ImpsService>(ImpsService(getIt<Dio>()));
|
||||
getIt.registerSingleton<BranchService>(BranchService(getIt<Dio>()));
|
||||
getIt.registerLazySingleton<ChangePasswordService>(
|
||||
() => ChangePasswordService(getIt<Dio>()),
|
||||
);
|
||||
|
||||
// Add auth interceptor after repository is available
|
||||
getIt<Dio>().interceptors.add(
|
||||
@@ -49,22 +66,23 @@ Future<void> setupDependencies() async {
|
||||
);
|
||||
|
||||
// Register controllers/cubits
|
||||
getIt.registerFactory<AuthCubit>(
|
||||
() => AuthCubit(getIt<AuthRepository>(), getIt<UserService>()));
|
||||
|
||||
getIt.registerFactory<AuthCubit>(() => AuthCubit(
|
||||
getIt<AuthRepository>(), getIt<UserService>(), getIt<SecureStorage>()));
|
||||
}
|
||||
|
||||
Dio _createDioClient() {
|
||||
final dio = Dio(
|
||||
BaseOptions(
|
||||
baseUrl:
|
||||
//'http://lb-test-mobile-banking-app-192209417.ap-south-1.elb.amazonaws.com:8080',
|
||||
'http://localhost:8081',
|
||||
connectTimeout: const Duration(seconds: 5),
|
||||
receiveTimeout: const Duration(seconds: 3),
|
||||
'http://lb-test-mobile-banking-app-192209417.ap-south-1.elb.amazonaws.com:8080', //test
|
||||
//'http://lb-kccb-mobile-banking-app-848675342.ap-south-1.elb.amazonaws.com', //prod
|
||||
//'https://kccbmbnk.net', //prod small
|
||||
connectTimeout: const Duration(seconds: 60),
|
||||
receiveTimeout: const Duration(seconds: 60),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
'X-Login-Type': 'MB',
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
@@ -4,7 +4,7 @@ class Account {
|
||||
final String accountType;
|
||||
final double balance;
|
||||
final String currency;
|
||||
|
||||
|
||||
Account({
|
||||
required this.id,
|
||||
required this.accountNumber,
|
||||
@@ -12,4 +12,4 @@ class Account {
|
||||
required this.balance,
|
||||
required this.currency,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:kmobile/data/models/user.dart';
|
||||
import 'package:material_symbols_icons/material_symbols_icons.dart';
|
||||
import '../../../l10n/app_localizations.dart';
|
||||
|
||||
class AccountInfoScreen extends StatefulWidget {
|
||||
@@ -20,110 +18,161 @@ class AccountInfoScreen extends StatefulWidget {
|
||||
|
||||
class _AccountInfoScreen extends State<AccountInfoScreen> {
|
||||
late User selectedUser;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
selectedUser = widget.users[widget.selectedIndex];
|
||||
}
|
||||
|
||||
String getFullAccountType(String? accountType) {
|
||||
if (accountType == null || accountType.isEmpty) return 'N/A';
|
||||
// Convert to title case
|
||||
switch (accountType.toLowerCase()) {
|
||||
case 'sa':
|
||||
return AppLocalizations.of(context).savingsAccount;
|
||||
case 'sb':
|
||||
return AppLocalizations.of(context).savingsAccount;
|
||||
case 'ln':
|
||||
return AppLocalizations.of(context).loanAccount;
|
||||
case 'td':
|
||||
return AppLocalizations.of(context).termDeposit;
|
||||
case 'rd':
|
||||
return AppLocalizations.of(context).recurringDeposit;
|
||||
case 'ca':
|
||||
return "Current Account";
|
||||
case 'cc':
|
||||
return "Cash Credit Account";
|
||||
case 'od':
|
||||
return "Overdraft Account";
|
||||
default:
|
||||
return AppLocalizations.of(context).unknownAccount;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final users = widget.users;
|
||||
|
||||
int selectedIndex = widget.selectedIndex;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: IconButton(
|
||||
icon: const Icon(Symbols.arrow_back_ios_new),
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
title: Text(
|
||||
AppLocalizations.of(context).accountInfo,
|
||||
style: const TextStyle(
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
centerTitle: false,
|
||||
actions: [
|
||||
title: Text(AppLocalizations.of(context)
|
||||
.accountInfo
|
||||
.replaceFirst(RegExp('\n'), '')),
|
||||
),
|
||||
body: Stack(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 10.0),
|
||||
child: CircleAvatar(
|
||||
backgroundColor: Colors.grey[200],
|
||||
radius: 20,
|
||||
child: SvgPicture.asset(
|
||||
'assets/images/avatar_male.svg',
|
||||
width: 40,
|
||||
height: 40,
|
||||
fit: BoxFit.cover,
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Column(
|
||||
children: [
|
||||
Card(
|
||||
elevation: 4,
|
||||
margin: const EdgeInsets.symmetric(vertical: 8.0),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
AppLocalizations.of(context).accountNumber,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold, fontSize: 18),
|
||||
),
|
||||
DropdownButton<User>(
|
||||
value: selectedUser,
|
||||
onChanged: (User? newUser) {
|
||||
if (newUser != null) {
|
||||
setState(() {
|
||||
selectedUser = newUser;
|
||||
});
|
||||
}
|
||||
},
|
||||
items: widget.users.map((user) {
|
||||
return DropdownMenuItem<User>(
|
||||
value: user,
|
||||
child: Text(
|
||||
user.accountNo.toString(),
|
||||
style: const TextStyle(
|
||||
fontSize: 20, fontWeight: FontWeight.bold),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
isExpanded: true,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Card(
|
||||
elevation: 4,
|
||||
margin: const EdgeInsets.symmetric(vertical: 8.0),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: ListView(
|
||||
children: [
|
||||
InfoRow(
|
||||
title: AppLocalizations.of(context).customerNumber,
|
||||
value: selectedUser.cifNumber ?? 'N/A',
|
||||
),
|
||||
InfoRow(
|
||||
title: AppLocalizations.of(context).accountType,
|
||||
value: getFullAccountType(selectedUser.accountType),
|
||||
),
|
||||
InfoRow(
|
||||
title: AppLocalizations.of(context).productName,
|
||||
value: selectedUser.productType ?? 'N/A',
|
||||
),
|
||||
InfoRow(
|
||||
title: AppLocalizations.of(context).accountStatus,
|
||||
value: 'OPEN',
|
||||
),
|
||||
InfoRow(
|
||||
title:
|
||||
AppLocalizations.of(context).availableBalance,
|
||||
value: selectedUser.availableBalance ?? 'N/A',
|
||||
),
|
||||
InfoRow(
|
||||
title: AppLocalizations.of(context).currentBalance,
|
||||
value: selectedUser.currentBalance ?? 'N/A',
|
||||
),
|
||||
if (users[selectedIndex].approvedAmount != null)
|
||||
InfoRow(
|
||||
title:
|
||||
AppLocalizations.of(context).approvedAmount,
|
||||
value: selectedUser.approvedAmount ?? 'N/A',
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
IgnorePointer(
|
||||
child: Center(
|
||||
child: Opacity(
|
||||
opacity: 0.07, // Reduced opacity
|
||||
|
||||
child: ClipOval(
|
||||
child: Image.asset(
|
||||
'assets/images/logo.png',
|
||||
|
||||
width: 200, // Adjust size as needed
|
||||
|
||||
height: 200, // Adjust size as needed
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
children: [
|
||||
Text(
|
||||
AppLocalizations.of(context).accountNumber,
|
||||
style: const TextStyle(fontWeight: FontWeight.w500, fontSize: 14),
|
||||
),
|
||||
|
||||
/// Dropdown to change account
|
||||
DropdownButton<User>(
|
||||
value: selectedUser,
|
||||
onChanged: (User? newUser) {
|
||||
if (newUser != null) {
|
||||
setState(() {
|
||||
selectedUser = newUser;
|
||||
});
|
||||
}
|
||||
},
|
||||
items: widget.users.map((user) {
|
||||
return DropdownMenuItem<User>(
|
||||
value: user,
|
||||
child: Text(user.accountNo.toString()),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
|
||||
/*InfoRow(
|
||||
title: AppLocalizations.of(context).accountNumber,
|
||||
value: users[selectedIndex].accountNo ?? 'N/A'),
|
||||
// InfoRow(title: 'Nominee Customer No', value: user.nomineeCustomerNo),
|
||||
// InfoRow(title: 'SMS Service', value: user.smsService),
|
||||
// InfoRow(title: 'Missed Call Service', value: user.missedCallService),*/
|
||||
InfoRow(
|
||||
title: AppLocalizations.of(context).customerNumber,
|
||||
value: selectedUser.cifNumber ?? 'N/A',
|
||||
),
|
||||
InfoRow(
|
||||
title: AppLocalizations.of(context).productName,
|
||||
value: selectedUser.productType ?? 'N/A',
|
||||
),
|
||||
// InfoRow(title: 'Account Opening Date', value: users[selectedIndex].accountOpeningDate ?? 'N/A'),
|
||||
InfoRow(
|
||||
title: AppLocalizations.of(context).accountStatus,
|
||||
value: 'OPEN',
|
||||
),
|
||||
InfoRow(
|
||||
title: AppLocalizations.of(context).availableBalance,
|
||||
value: selectedUser.availableBalance ?? 'N/A',
|
||||
),
|
||||
InfoRow(
|
||||
title: AppLocalizations.of(context).currentBalance,
|
||||
value: selectedUser.currentBalance ?? 'N/A',
|
||||
),
|
||||
|
||||
users[selectedIndex].approvedAmount != null
|
||||
? InfoRow(
|
||||
title: AppLocalizations.of(context).approvedAmount,
|
||||
value: selectedUser.approvedAmount ?? 'N/A',
|
||||
)
|
||||
: const SizedBox.shrink(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -136,6 +185,7 @@ class InfoRow extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
margin: const EdgeInsets.symmetric(vertical: 8),
|
||||
@@ -144,16 +194,19 @@ class InfoRow extends StatelessWidget {
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.black87,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 3),
|
||||
Text(
|
||||
value,
|
||||
style: const TextStyle(fontSize: 16, color: Colors.black),
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: theme.colorScheme.onSurface),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
155
lib/features/accounts/screens/all_accounts_screen.dart
Normal file
@@ -0,0 +1,155 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:kmobile/data/models/user.dart';
|
||||
import 'package:material_symbols_icons/material_symbols_icons.dart';
|
||||
|
||||
import '../../../l10n/app_localizations.dart';
|
||||
|
||||
class AllAccountsScreen extends StatefulWidget {
|
||||
final List<User> users;
|
||||
const AllAccountsScreen({super.key, required this.users});
|
||||
|
||||
@override
|
||||
State<AllAccountsScreen> createState() => _AllAccountsScreenState();
|
||||
}
|
||||
|
||||
class _AllAccountsScreenState extends State<AllAccountsScreen> {
|
||||
final Map<String, bool> _visibilityMap = {};
|
||||
|
||||
String getFullAccountType(BuildContext context, String? accountType) {
|
||||
// This is duplicated from dashboard_screen.dart.
|
||||
// In a real app, this should be moved to a utility/helper class.
|
||||
if (accountType == null || accountType.isEmpty) return 'N/A';
|
||||
switch (accountType.toLowerCase()) {
|
||||
case 'sa':
|
||||
return AppLocalizations.of(context).savingsAccount;
|
||||
case 'sb':
|
||||
return AppLocalizations.of(context).savingsAccount;
|
||||
case 'ln':
|
||||
return AppLocalizations.of(context).loanAccount;
|
||||
case 'td':
|
||||
return AppLocalizations.of(context).termDeposit;
|
||||
case 'rd':
|
||||
return AppLocalizations.of(context).recurringDeposit;
|
||||
case 'ca':
|
||||
return "Current Account";
|
||||
case 'cc':
|
||||
return "Cash Credit Account";
|
||||
case 'od':
|
||||
return "Overdraft Account";
|
||||
default:
|
||||
return AppLocalizations.of(context).unknownAccount;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(AppLocalizations.of(context).viewall),
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
const SizedBox(height: 16.0), // Added space below the app bar
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: widget.users.length,
|
||||
itemBuilder: (context, index) {
|
||||
final user = widget.users[index];
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16.0, vertical: 8.0),
|
||||
child: _buildAccountCard(user),
|
||||
);
|
||||
},
|
||||
),
|
||||
), // Closing Expanded
|
||||
], // Closing Column
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAccountCard(User user) {
|
||||
final theme = Theme.of(context);
|
||||
final accountNo = user.accountNo ?? '';
|
||||
final isVisible = _visibilityMap[accountNo] ?? false;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 18, vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF01A04C),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Top section: Account Type and Number
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
getFullAccountType(context, user.accountType),
|
||||
style: TextStyle(
|
||||
color: theme.colorScheme.onPrimary,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
user.accountNo ?? 'N/A',
|
||||
style: TextStyle(
|
||||
color: theme.colorScheme.onPrimary,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
// Bottom section: Balance and Toggle
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
"₹ ",
|
||||
style: TextStyle(
|
||||
color: theme.colorScheme.onPrimary,
|
||||
fontSize: 32,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
isVisible ? user.currentBalance ?? '0.00' : '*****',
|
||||
style: TextStyle(
|
||||
color: theme.colorScheme.onPrimary,
|
||||
fontSize: 32,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
InkWell(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_visibilityMap[accountNo] = !isVisible;
|
||||
});
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Icon(
|
||||
isVisible ? Symbols.visibility_lock : Symbols.visibility,
|
||||
color: theme.scaffoldBackgroundColor,
|
||||
weight: 800,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
135
lib/features/accounts/screens/transaction_details_screen.dart
Normal file
@@ -0,0 +1,135 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:kmobile/l10n/app_localizations.dart';
|
||||
import 'package:material_symbols_icons/symbols.dart';
|
||||
|
||||
class TransactionDetailsScreen extends StatelessWidget {
|
||||
final dynamic transaction;
|
||||
|
||||
const TransactionDetailsScreen({super.key, required this.transaction});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final bool isCredit = transaction.type?.toUpperCase() == 'CR';
|
||||
|
||||
return Scaffold(
|
||||
appBar:
|
||||
AppBar(title: Text(AppLocalizations.of(context).transactionDetails)),
|
||||
body: Stack(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// Amount + icon + Share Button
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
"₹ ${transaction.amount}",
|
||||
style: const TextStyle(
|
||||
fontSize: 40,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Icon(
|
||||
isCredit
|
||||
? Symbols.call_received
|
||||
: Symbols.call_made,
|
||||
color: isCredit
|
||||
? const Color(0xFF10BB10)
|
||||
: Theme.of(context).colorScheme.error,
|
||||
size: 28,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
// Date centered
|
||||
Text(
|
||||
transaction.date ?? "",
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: Theme.of(context).textTheme.bodySmall?.color,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Divider(color: Theme.of(context).dividerColor),
|
||||
Expanded(
|
||||
flex: 5,
|
||||
child: ListView(
|
||||
children: [
|
||||
_buildDetailRow(
|
||||
AppLocalizations.of(context).transactionType,
|
||||
transaction.type ?? ""),
|
||||
_buildDetailRow(AppLocalizations.of(context).transferType,
|
||||
transaction.name.split("/").first ?? ""),
|
||||
// if (transaction.name.length > 12) ...[
|
||||
// _buildDetailRow(AppLocalizations.of(context).utrNo,
|
||||
// transaction.name.split("= ")[1].split(" ")[0] ?? ""),
|
||||
// _buildDetailRow(
|
||||
// AppLocalizations.of(context).beneficiaryAccountNo,
|
||||
// transaction.name.split("A/C ").last ?? "")
|
||||
// ]
|
||||
_buildDetailRow(AppLocalizations.of(context).details,
|
||||
transaction.name),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
IgnorePointer(
|
||||
child: Center(
|
||||
child: Opacity(
|
||||
opacity: 0.07, // Reduced opacity
|
||||
child: ClipOval(
|
||||
child: Image.asset(
|
||||
'assets/images/logo.png',
|
||||
width: 200, // Adjust size as needed
|
||||
height: 200, // Adjust size as needed
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDetailRow(String label, String value) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
"$label: ",
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 17,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
Expanded(
|
||||
child: Text(
|
||||
value,
|
||||
style: const TextStyle(fontSize: 16),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,19 @@
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:kmobile/api/services/user_service.dart';
|
||||
import 'package:kmobile/core/errors/exceptions.dart';
|
||||
import 'package:kmobile/data/models/user.dart';
|
||||
import 'package:kmobile/features/auth/models/auth_token.dart';
|
||||
import 'package:kmobile/security/secure_storage.dart';
|
||||
import '../../../data/repositories/auth_repository.dart';
|
||||
import 'auth_state.dart';
|
||||
|
||||
class AuthCubit extends Cubit<AuthState> {
|
||||
final AuthRepository _authRepository;
|
||||
final UserService _userService;
|
||||
final SecureStorage _secureStorage;
|
||||
|
||||
AuthCubit(this._authRepository, this._userService) : super(AuthInitial()) {
|
||||
AuthCubit(this._authRepository, this._userService, this._secureStorage)
|
||||
: super(AuthInitial()) {
|
||||
checkAuthStatus();
|
||||
}
|
||||
|
||||
@@ -29,22 +34,62 @@ class AuthCubit extends Cubit<AuthState> {
|
||||
|
||||
Future<void> refreshUserData() async {
|
||||
try {
|
||||
// emit(AuthLoading());
|
||||
final users = await _userService.getUserDetails();
|
||||
emit(Authenticated(users));
|
||||
} catch (e) {
|
||||
emit(AuthError('Failed to refresh user data: ${e.toString()}'));
|
||||
// Optionally, re-emit the previous state or handle as needed
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> login(String customerNo, String password) async {
|
||||
emit(AuthLoading());
|
||||
try {
|
||||
final users = await _authRepository.login(customerNo, password);
|
||||
emit(Authenticated(users));
|
||||
final (users, authToken) =
|
||||
await _authRepository.login(customerNo, password);
|
||||
|
||||
if (authToken.tnc == false) {
|
||||
emit(ShowTncDialog(authToken, users));
|
||||
} else {
|
||||
await _checkMpinAndNavigate(users);
|
||||
}
|
||||
} catch (e) {
|
||||
emit(AuthError(e is AuthException ? e.message : e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> onTncDialogResult(
|
||||
bool agreed, AuthToken authToken, List<User> users) async {
|
||||
if (agreed) {
|
||||
try {
|
||||
await _authRepository.acceptTnc();
|
||||
// The user is NOT fully authenticated yet. Just check for MPIN.
|
||||
await _checkMpinAndNavigate(users);
|
||||
} catch (e) {
|
||||
emit(AuthError('Failed to accept TNC: $e'));
|
||||
}
|
||||
} else {
|
||||
emit(NavigateToTncRequiredScreen());
|
||||
}
|
||||
}
|
||||
|
||||
void mpinSetupCompleted() {
|
||||
if (state is NavigateToMpinSetupScreen) {
|
||||
final users = (state as NavigateToMpinSetupScreen).users;
|
||||
emit(Authenticated(users));
|
||||
} else {
|
||||
// Handle unexpected state if necessary
|
||||
emit(AuthError("Invalid state during MPIN setup completion."));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _checkMpinAndNavigate(List<User> users) async {
|
||||
final mpin = await _secureStorage.read('mpin');
|
||||
if (mpin == null) {
|
||||
// No MPIN, tell UI to navigate to MPIN setup, carrying user data
|
||||
emit(NavigateToMpinSetupScreen(users));
|
||||
} else {
|
||||
// MPIN exists, user is authenticated
|
||||
emit(Authenticated(users));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import '../../../data/models/user.dart';
|
||||
import 'package:kmobile/data/models/user.dart';
|
||||
import 'package:kmobile/features/auth/models/auth_token.dart';
|
||||
|
||||
abstract class AuthState extends Equatable {
|
||||
const AuthState();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class AuthInitial extends AuthState {}
|
||||
@@ -12,20 +15,44 @@ class AuthLoading extends AuthState {}
|
||||
|
||||
class Authenticated extends AuthState {
|
||||
final List<User> users;
|
||||
|
||||
Authenticated(this.users);
|
||||
const Authenticated(this.users);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [users];
|
||||
List<Object> get props => [users];
|
||||
}
|
||||
|
||||
class Unauthenticated extends AuthState {}
|
||||
|
||||
class AuthError extends AuthState {
|
||||
final String message;
|
||||
|
||||
AuthError(this.message);
|
||||
const AuthError(this.message);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [message];
|
||||
List<Object> get props => [message];
|
||||
}
|
||||
|
||||
// --- New States for Navigation and Dialog ---
|
||||
|
||||
// State to indicate that the TNC dialog needs to be shown
|
||||
class ShowTncDialog extends AuthState {
|
||||
final AuthToken authToken;
|
||||
final List<User> users;
|
||||
const ShowTncDialog(this.authToken, this.users);
|
||||
|
||||
@override
|
||||
List<Object> get props => [authToken, users];
|
||||
}
|
||||
|
||||
// States to trigger specific navigations from the UI
|
||||
class NavigateToTncRequiredScreen extends AuthState {}
|
||||
|
||||
class NavigateToMpinSetupScreen extends AuthState {
|
||||
final List<User> users;
|
||||
|
||||
const NavigateToMpinSetupScreen(this.users);
|
||||
|
||||
@override
|
||||
List<Object> get props => [users];
|
||||
}
|
||||
|
||||
class NavigateToDashboardScreen extends AuthState {}
|
||||
|
||||
@@ -1,48 +1,27 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'theme_state.dart';
|
||||
import 'package:kmobile/config/theme_type.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'theme_state.dart';
|
||||
|
||||
class ThemeCubit extends Cubit<ThemeState> {
|
||||
ThemeCubit(): super(ThemeViolet()) {
|
||||
ThemeCubit() : super(const ThemeState(themeType: ThemeType.violet)) {
|
||||
loadTheme();
|
||||
}
|
||||
|
||||
Future<void> loadTheme() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final themeIndex = prefs.getInt('theme_type') ?? 0;
|
||||
// final isDark = prefs.getBool('is_dark_mode') ?? false;
|
||||
|
||||
final type = ThemeType.values[themeIndex];
|
||||
switch(type) {
|
||||
case ThemeType.blue:
|
||||
emit(ThemeBlue());
|
||||
case ThemeType.violet:
|
||||
emit(ThemeViolet());
|
||||
default:
|
||||
emit(ThemeViolet());
|
||||
}
|
||||
emit(ThemeState(themeType: type));
|
||||
}
|
||||
|
||||
Future<void> changeTheme(ThemeType type) async {
|
||||
log("Attempting to change theme...");
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setInt('theme_type', type.index);
|
||||
log("Mode Change");
|
||||
print("mode changed");
|
||||
switch(type) {
|
||||
case ThemeType.blue:
|
||||
emit(ThemeBlue());
|
||||
print('blue matched');
|
||||
break;
|
||||
case ThemeType.violet:
|
||||
emit(ThemeViolet());
|
||||
print('violet matched');
|
||||
break;
|
||||
default:
|
||||
emit(ThemeBlue());
|
||||
print('default macthed');
|
||||
}
|
||||
emit(ThemeState(themeType: type));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
23
lib/features/auth/controllers/theme_mode_cubit.dart
Normal file
@@ -0,0 +1,23 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'theme_mode_state.dart';
|
||||
|
||||
class ThemeModeCubit extends Cubit<ThemeModeState> {
|
||||
ThemeModeCubit() : super(const ThemeModeState(mode: ThemeMode.system)) {
|
||||
loadThemeMode();
|
||||
}
|
||||
|
||||
Future<void> loadThemeMode() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final modeIndex = prefs.getInt('theme_mode') ?? 0; // default system
|
||||
final mode = ThemeMode.values[modeIndex];
|
||||
emit(ThemeModeState(mode: mode));
|
||||
}
|
||||
|
||||
Future<void> changeThemeMode(ThemeMode mode) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setInt('theme_mode', mode.index);
|
||||
emit(ThemeModeState(mode: mode));
|
||||
}
|
||||
}
|
||||
11
lib/features/auth/controllers/theme_mode_state.dart
Normal file
@@ -0,0 +1,11 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class ThemeModeState extends Equatable {
|
||||
final ThemeMode mode;
|
||||
|
||||
const ThemeModeState({required this.mode});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [mode];
|
||||
}
|
||||
@@ -1,27 +1,38 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
/*import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:kmobile/config/theme_type.dart';
|
||||
import 'package:kmobile/config/themes.dart';
|
||||
|
||||
class ThemeState extends Equatable {
|
||||
final ThemeType themeType;
|
||||
|
||||
abstract class ThemeState extends Equatable {
|
||||
getThemeData();
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
const ThemeState({required this.themeType});
|
||||
|
||||
class ThemeBlue extends ThemeState {
|
||||
|
||||
@override
|
||||
getThemeData() {
|
||||
print('returning blue theme');
|
||||
return AppThemes.getLightTheme(ThemeType.blue);
|
||||
ThemeData getThemeData() {
|
||||
return AppThemes.getLightTheme(themeType);
|
||||
}
|
||||
}
|
||||
|
||||
class ThemeViolet extends ThemeState {
|
||||
@override
|
||||
getThemeData() {
|
||||
print('returning violet theme');
|
||||
return AppThemes.getLightTheme(ThemeType.violet);
|
||||
List<Object?> get props => [themeType];
|
||||
}*/
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:kmobile/config/theme_type.dart';
|
||||
import 'package:kmobile/config/themes.dart';
|
||||
|
||||
class ThemeState extends Equatable {
|
||||
final ThemeType themeType;
|
||||
const ThemeState({required this.themeType});
|
||||
|
||||
ThemeData getLightThemeData() {
|
||||
return AppThemes.getLightTheme(themeType);
|
||||
}
|
||||
}
|
||||
|
||||
ThemeData getDarkThemeData() {
|
||||
return AppThemes.getDarkTheme(themeType);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [themeType];
|
||||
}
|
||||
|
||||
@@ -6,16 +6,31 @@ import 'package:equatable/equatable.dart';
|
||||
class AuthToken extends Equatable {
|
||||
final String accessToken;
|
||||
final DateTime expiresAt;
|
||||
|
||||
final bool tnc;
|
||||
|
||||
const AuthToken({
|
||||
required this.accessToken,
|
||||
required this.expiresAt,
|
||||
required this.tnc,
|
||||
});
|
||||
|
||||
|
||||
factory AuthToken.fromJson(Map<String, dynamic> json) {
|
||||
final token = json['token'];
|
||||
|
||||
// Safely extract tnc.mobile directly from the outer JSON
|
||||
bool tncMobileValue = false; // Default to false if not found or invalid
|
||||
if (json.containsKey('tnc') && json['tnc'] is Map<String, dynamic>) {
|
||||
final tncMap = json['tnc'] as Map<String, dynamic>;
|
||||
if (tncMap.containsKey('mobile') && tncMap['mobile'] is bool) {
|
||||
tncMobileValue = tncMap['mobile'] as bool;
|
||||
}
|
||||
}
|
||||
|
||||
return AuthToken(
|
||||
accessToken: json['token'],
|
||||
expiresAt: _decodeExpiryFromToken(json['token']),
|
||||
accessToken: token,
|
||||
expiresAt: _decodeExpiryFromToken(
|
||||
token), // This method is still valid for JWT expiry
|
||||
tnc: tncMobileValue, // Use the correctly extracted value
|
||||
);
|
||||
}
|
||||
|
||||
@@ -29,7 +44,8 @@ class AuthToken extends Equatable {
|
||||
// Pad the payload if necessary
|
||||
String normalized = base64Url.normalize(payload);
|
||||
final payloadMap = json.decode(utf8.decode(base64Url.decode(normalized)));
|
||||
if (payloadMap is! Map<String, dynamic> || !payloadMap.containsKey('exp')) {
|
||||
if (payloadMap is! Map<String, dynamic> ||
|
||||
!payloadMap.containsKey('exp')) {
|
||||
throw Exception('Invalid payload');
|
||||
}
|
||||
final exp = payloadMap['exp'];
|
||||
@@ -40,9 +56,46 @@ class AuthToken extends Equatable {
|
||||
return DateTime.now().add(const Duration(hours: 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// static bool _decodeTncFromToken(String token) {
|
||||
// try {
|
||||
// final parts = token.split('.');
|
||||
// if (parts.length != 3) {
|
||||
// throw Exception('Invalid JWT format for TNC decoding');
|
||||
// }
|
||||
// final payload = parts[1];
|
||||
// String normalized = base64Url.normalize(payload);
|
||||
// final payloadMap = json.decode(utf8.decode(base64Url.decode(normalized)));
|
||||
|
||||
// if (payloadMap is! Map<String, dynamic> || !payloadMap.containsKey('tnc')) {
|
||||
// // If 'tnc' is not present in the payload, default to false
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// final tncValue = payloadMap['tnc'];
|
||||
|
||||
// // Handle different representations of 'true'
|
||||
// if (tncValue is bool) {
|
||||
// return tncValue;
|
||||
// }
|
||||
// if (tncValue is String) {
|
||||
// return tncValue.toLowerCase() == 'true';
|
||||
// }
|
||||
// if (tncValue is int) {
|
||||
// return tncValue == 1;
|
||||
// }
|
||||
|
||||
// // Default to false for any other case
|
||||
// return false;
|
||||
// } catch (e) {
|
||||
// log('Error decoding tnc from token: $e');
|
||||
// // Default to false if decoding fails or 'tnc' is not found/invalid
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
bool get isExpired => DateTime.now().isAfter(expiresAt);
|
||||
|
||||
|
||||
@override
|
||||
List<Object> get props => [accessToken, expiresAt];
|
||||
List<Object> get props => [accessToken, expiresAt, tnc];
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import '../../../l10n/app_localizations.dart';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:kmobile/di/injection.dart';
|
||||
import 'package:kmobile/app.dart';
|
||||
import 'package:kmobile/features/auth/screens/mpin_screen.dart';
|
||||
import 'package:kmobile/security/secure_storage.dart';
|
||||
import '../../../app.dart';
|
||||
import 'package:kmobile/features/auth/screens/set_password_screen.dart';
|
||||
import 'package:kmobile/features/auth/screens/tnc_required_screen.dart';
|
||||
import 'package:kmobile/features/auth/screens/verification_screen.dart';
|
||||
import 'package:kmobile/widgets/tnc_dialog.dart';
|
||||
import '../../../l10n/app_localizations.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../controllers/auth_cubit.dart';
|
||||
import '../controllers/auth_state.dart';
|
||||
|
||||
@@ -22,77 +23,282 @@ class LoginScreenState extends State<LoginScreen>
|
||||
final _customerNumberController = TextEditingController();
|
||||
final _passwordController = TextEditingController();
|
||||
bool _obscurePassword = true;
|
||||
//bool _showWelcome = true;
|
||||
late AnimationController _logoController;
|
||||
late Animation<double> _logoAnimation;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_logoController = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(seconds: 1),
|
||||
)..repeat(reverse: true);
|
||||
|
||||
_logoAnimation = Tween<double>(begin: 0.2, end: 1).animate(_logoController);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_logoController.dispose();
|
||||
_customerNumberController.dispose();
|
||||
_passwordController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _submitForm() {
|
||||
void _submitForm() async {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
context.read<AuthCubit>().login(
|
||||
_customerNumberController.text.trim(),
|
||||
_passwordController.text,
|
||||
final bool? verificationSuccess = await Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => VerificationScreen(
|
||||
customerNo: _customerNumberController.text.trim(),
|
||||
password: _passwordController.text,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
if (verificationSuccess == true && mounted) {
|
||||
context.read<AuthCubit>().login(
|
||||
_customerNumberController.text.trim(),
|
||||
_passwordController.text,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// return Scaffold(
|
||||
// body: BlocConsumer<AuthCubit, AuthState>(
|
||||
// listener: (context, state) async {
|
||||
// if (state is ShowTncDialog) {
|
||||
// // The dialog now returns a boolean for the 'disagree' case,
|
||||
// // or it completes when the 'proceed' action is finished.
|
||||
// final agreed = await showDialog<bool>(
|
||||
// context: context,
|
||||
// barrierDismissible: false,
|
||||
// builder: (dialogContext) => TncDialog(
|
||||
// onProceed: () async {
|
||||
// // This function is passed to the dialog.
|
||||
// // It calls the cubit and completes when the cubit's work is done.
|
||||
// await context
|
||||
// .read<AuthCubit>()
|
||||
// .onTncDialogResult(true, state.authToken, state.users);
|
||||
// },
|
||||
// ),
|
||||
// );
|
||||
|
||||
// // If 'agreed' is false, it means the user clicked 'Disagree'.
|
||||
// if (agreed == false) {
|
||||
// if (!context.mounted) return;
|
||||
// context
|
||||
// .read<AuthCubit>()
|
||||
// .onTncDialogResult(false, state.authToken, state.users);
|
||||
// }
|
||||
// } else if (state is NavigateToTncRequiredScreen) {
|
||||
// Navigator.of(context).pushNamed(TncRequiredScreen.routeName);
|
||||
// } else if (state is NavigateToMpinSetupScreen) {
|
||||
// Navigator.of(context).push( // Use push, NOT pushReplacement
|
||||
// MaterialPageRoute(
|
||||
// builder: (_) => MPinScreen(
|
||||
// mode: MPinMode.set,
|
||||
// onCompleted: (_) {
|
||||
// // This clears the entire stack and pushes the dashboard
|
||||
// Navigator.of(context, rootNavigator: true).pushAndRemoveUntil(
|
||||
// MaterialPageRoute(builder: (_) => const NavigationScaffold()),
|
||||
// (route) => false,
|
||||
// );
|
||||
// },
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// } else if (state is NavigateToDashboardScreen) {
|
||||
// Navigator.of(context).pushReplacement(
|
||||
// MaterialPageRoute(builder: (_) => const NavigationScaffold()),
|
||||
// );
|
||||
// } else if (state is AuthError) {
|
||||
// if (state.message == 'MIGRATED_USER_HAS_NO_PASSWORD') {
|
||||
// Navigator.of(context).push(MaterialPageRoute(
|
||||
// builder: (_) => SetPasswordScreen(
|
||||
// customerNo: _customerNumberController.text.trim(),
|
||||
// )));
|
||||
// } else {
|
||||
// ScaffoldMessenger.of(context)
|
||||
// .showSnackBar(SnackBar(content: Text(state.message)));
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
// builder: (context, state) {
|
||||
// // The commented out section is removed for clarity, the logic is now above.
|
||||
// return Padding(
|
||||
// padding: const EdgeInsets.all(24.0),
|
||||
// child: Form(
|
||||
// key: _formKey,
|
||||
// child: Column(
|
||||
// mainAxisAlignment: MainAxisAlignment.center,
|
||||
// children: [
|
||||
// Image.asset(
|
||||
// 'assets/images/logo.png',
|
||||
// width: 150,
|
||||
// height: 150,
|
||||
// errorBuilder: (context, error, stackTrace) {
|
||||
// return Icon(
|
||||
// Icons.account_balance,
|
||||
// size: 100,
|
||||
// color: Theme.of(context).primaryColor,
|
||||
// );
|
||||
// },
|
||||
// ),
|
||||
// const SizedBox(height: 16),
|
||||
// Text(
|
||||
// AppLocalizations.of(context).kccb,
|
||||
// style: TextStyle(
|
||||
// fontSize: 32,
|
||||
// fontWeight: FontWeight.bold,
|
||||
// color: Theme.of(context).primaryColor,
|
||||
// ),
|
||||
// ),
|
||||
// const SizedBox(height: 48),
|
||||
// TextFormField(
|
||||
// controller: _customerNumberController,
|
||||
// decoration: InputDecoration(
|
||||
// labelText: AppLocalizations.of(context).customerNumber,
|
||||
// border: const OutlineInputBorder(),
|
||||
// isDense: true,
|
||||
// filled: true,
|
||||
// fillColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
// enabledBorder: OutlineInputBorder(
|
||||
// borderSide: BorderSide(
|
||||
// color: Theme.of(context).colorScheme.outline),
|
||||
// ),
|
||||
// focusedBorder: OutlineInputBorder(
|
||||
// borderSide: BorderSide(
|
||||
// color: Theme.of(context).colorScheme.primary,
|
||||
// width: 2),
|
||||
// ),
|
||||
// ),
|
||||
// keyboardType: TextInputType.number,
|
||||
// textInputAction: TextInputAction.next,
|
||||
// validator: (value) {
|
||||
// if (value == null || value.isEmpty) {
|
||||
// return AppLocalizations.of(context).pleaseEnterUsername;
|
||||
// }
|
||||
// return null;
|
||||
// },
|
||||
// ),
|
||||
// const SizedBox(height: 24),
|
||||
// TextFormField(
|
||||
// controller: _passwordController,
|
||||
// obscureText: _obscurePassword,
|
||||
// textInputAction: TextInputAction.done,
|
||||
// onFieldSubmitted: (_) => _submitForm(),
|
||||
// decoration: InputDecoration(
|
||||
// labelText: AppLocalizations.of(context).password,
|
||||
// border: const OutlineInputBorder(),
|
||||
// isDense: true,
|
||||
// filled: true,
|
||||
// fillColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
// enabledBorder: OutlineInputBorder(
|
||||
// borderSide: BorderSide(
|
||||
// color: Theme.of(context).colorScheme.outline),
|
||||
// ),
|
||||
// focusedBorder: OutlineInputBorder(
|
||||
// borderSide: BorderSide(
|
||||
// color: Theme.of(context).colorScheme.primary,
|
||||
// width: 2),
|
||||
// ),
|
||||
// suffixIcon: IconButton(
|
||||
// icon: Icon(
|
||||
// _obscurePassword
|
||||
// ? Icons.visibility
|
||||
// : Icons.visibility_off,
|
||||
// ),
|
||||
// onPressed: () {
|
||||
// setState(() {
|
||||
// _obscurePassword = !_obscurePassword;
|
||||
// });
|
||||
// },
|
||||
// ),
|
||||
// ),
|
||||
// validator: (value) {
|
||||
// if (value == null || value.isEmpty) {
|
||||
// return AppLocalizations.of(context).pleaseEnterPassword;
|
||||
// }
|
||||
// return null;
|
||||
// },
|
||||
// ),
|
||||
// const SizedBox(height: 24),
|
||||
// SizedBox(
|
||||
// width: 250,
|
||||
// child: ElevatedButton(
|
||||
// onPressed: state is AuthLoading ? null : _submitForm,
|
||||
// style: ElevatedButton.styleFrom(
|
||||
// shape: const StadiumBorder(),
|
||||
// padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
// backgroundColor:
|
||||
// Theme.of(context).scaffoldBackgroundColor,
|
||||
// foregroundColor: Theme.of(context).primaryColorDark,
|
||||
// side: BorderSide(
|
||||
// color: Theme.of(context).colorScheme.outline,
|
||||
// width: 1),
|
||||
// elevation: 0,
|
||||
// ),
|
||||
// child: state is AuthLoading
|
||||
// ? const CircularProgressIndicator()
|
||||
// : Text(
|
||||
// AppLocalizations.of(context).login,
|
||||
// style: TextStyle(
|
||||
// color: Theme.of(context)
|
||||
// .colorScheme
|
||||
// .onPrimaryContainer),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// const SizedBox(height: 25),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// },
|
||||
// ),
|
||||
// );
|
||||
return Scaffold(
|
||||
// appBar: AppBar(title: const Text('Login')),
|
||||
body: BlocConsumer<AuthCubit, AuthState>(
|
||||
listener: (context, state) async {
|
||||
if (state is Authenticated) {
|
||||
final storage = getIt<SecureStorage>();
|
||||
final mpin = await storage.read('mpin');
|
||||
if (mpin == null) {
|
||||
Navigator.of(context).pushReplacement(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => MPinScreen(
|
||||
mode: MPinMode.set,
|
||||
onCompleted: (_) {
|
||||
Navigator.of(
|
||||
context,
|
||||
rootNavigator: true,
|
||||
).pushReplacement(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => const NavigationScaffold(),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
listener: (context, state) {
|
||||
if (state is ShowTncDialog) {
|
||||
showDialog<bool>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (dialogContext) => TncDialog(
|
||||
onProceed: () async {
|
||||
// Pop the dialog before the cubit action
|
||||
Navigator.of(dialogContext).pop();
|
||||
await context
|
||||
.read<AuthCubit>()
|
||||
.onTncDialogResult(true, state.authToken, state.users);
|
||||
},
|
||||
),
|
||||
);
|
||||
} else if (state is NavigateToTncRequiredScreen) {
|
||||
Navigator.of(context).pushNamed(TncRequiredScreen.routeName);
|
||||
} else if (state is NavigateToMpinSetupScreen) {
|
||||
Navigator.of(context).push(
|
||||
// Use push, NOT pushReplacement
|
||||
MaterialPageRoute(
|
||||
builder: (_) => MPinScreen(
|
||||
mode: MPinMode.set,
|
||||
onCompleted: (_) {
|
||||
// Call the cubit to signal MPIN setup is complete
|
||||
context.read<AuthCubit>().mpinSetupCompleted();
|
||||
},
|
||||
),
|
||||
);
|
||||
} else {
|
||||
Navigator.of(context).pushReplacement(
|
||||
MaterialPageRoute(builder: (_) => const NavigationScaffold()),
|
||||
);
|
||||
}
|
||||
),
|
||||
);
|
||||
} else if (state is Authenticated) {
|
||||
// This is the single source of truth for navigating to the dashboard
|
||||
Navigator.of(context, rootNavigator: true).pushAndRemoveUntil(
|
||||
MaterialPageRoute(builder: (_) => const NavigationScaffold()),
|
||||
(route) => false,
|
||||
);
|
||||
} else if (state is AuthError) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(state.message)));
|
||||
if (state.message == 'MIGRATED_USER_HAS_NO_PASSWORD') {
|
||||
Navigator.of(context).push(MaterialPageRoute(
|
||||
builder: (_) => SetPasswordScreen(
|
||||
customerNo: _customerNumberController.text.trim(),
|
||||
)));
|
||||
} else {
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(SnackBar(content: Text(state.message)));
|
||||
}
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
// The builder part remains largely the same, focusing on UI display
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Form(
|
||||
@@ -100,24 +306,19 @@ class LoginScreenState extends State<LoginScreen>
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
// 🔁 Animated Blinking Logo
|
||||
FadeTransition(
|
||||
opacity: _logoAnimation,
|
||||
child: Image.asset(
|
||||
'assets/images/logo.png',
|
||||
width: 150,
|
||||
height: 150,
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
return Icon(
|
||||
Icons.account_balance,
|
||||
size: 100,
|
||||
color: Theme.of(context).primaryColor,
|
||||
);
|
||||
},
|
||||
),
|
||||
Image.asset(
|
||||
'assets/images/logo.png',
|
||||
width: 150,
|
||||
height: 150,
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
return Icon(
|
||||
Icons.account_balance,
|
||||
size: 100,
|
||||
color: Theme.of(context).primaryColor,
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
// Title
|
||||
Text(
|
||||
AppLocalizations.of(context).kccb,
|
||||
style: TextStyle(
|
||||
@@ -127,21 +328,22 @@ class LoginScreenState extends State<LoginScreen>
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 48),
|
||||
|
||||
TextFormField(
|
||||
controller: _customerNumberController,
|
||||
decoration: InputDecoration(
|
||||
labelText: AppLocalizations.of(context).customerNumber,
|
||||
// prefixIcon: Icon(Icons.person),
|
||||
border: OutlineInputBorder(),
|
||||
border: const OutlineInputBorder(),
|
||||
isDense: true,
|
||||
filled: true,
|
||||
fillColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.black),
|
||||
borderSide: BorderSide(
|
||||
color: Theme.of(context).colorScheme.outline),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.black, width: 2),
|
||||
borderSide: BorderSide(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
width: 2),
|
||||
),
|
||||
),
|
||||
keyboardType: TextInputType.number,
|
||||
@@ -154,24 +356,25 @@ class LoginScreenState extends State<LoginScreen>
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
// Password
|
||||
TextFormField(
|
||||
controller: _passwordController,
|
||||
obscureText: _obscurePassword,
|
||||
textInputAction: TextInputAction.done,
|
||||
onFieldSubmitted: (_) =>
|
||||
_submitForm(), // ⌨️ Enter key submits
|
||||
onFieldSubmitted: (_) => _submitForm(),
|
||||
decoration: InputDecoration(
|
||||
labelText: AppLocalizations.of(context).password,
|
||||
border: const OutlineInputBorder(),
|
||||
isDense: true,
|
||||
filled: true,
|
||||
fillColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
enabledBorder: const OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.black),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: Theme.of(context).colorScheme.outline),
|
||||
),
|
||||
focusedBorder: const OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.black, width: 2),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
width: 2),
|
||||
),
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(
|
||||
@@ -194,7 +397,6 @@ class LoginScreenState extends State<LoginScreen>
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
//Login Button
|
||||
SizedBox(
|
||||
width: 250,
|
||||
child: ElevatedButton(
|
||||
@@ -202,52 +404,26 @@ class LoginScreenState extends State<LoginScreen>
|
||||
style: ElevatedButton.styleFrom(
|
||||
shape: const StadiumBorder(),
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
backgroundColor:
|
||||
Theme.of(context).scaffoldBackgroundColor,
|
||||
foregroundColor: Theme.of(context).primaryColorDark,
|
||||
side: const BorderSide(color: Colors.black, width: 1),
|
||||
side: BorderSide(
|
||||
color: Theme.of(context).colorScheme.outline,
|
||||
width: 1),
|
||||
elevation: 0,
|
||||
),
|
||||
child: state is AuthLoading
|
||||
? const CircularProgressIndicator()
|
||||
: Text(
|
||||
AppLocalizations.of(context).login,
|
||||
style: TextStyle(fontSize: 16),
|
||||
style: TextStyle(
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.onPrimaryContainer),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(child: Divider()),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 8),
|
||||
child: Text(AppLocalizations.of(context).or),
|
||||
),
|
||||
Expanded(child: Divider()),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 25),
|
||||
|
||||
// Register Button
|
||||
SizedBox(
|
||||
width: 250,
|
||||
child: ElevatedButton(
|
||||
//disable until registration is implemented
|
||||
onPressed: null,
|
||||
style: OutlinedButton.styleFrom(
|
||||
shape: const StadiumBorder(),
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
backgroundColor: Theme.of(context).primaryColorLight,
|
||||
foregroundColor: Colors.black,
|
||||
),
|
||||
child: Text(AppLocalizations.of(context).register),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -257,227 +433,3 @@ class LoginScreenState extends State<LoginScreen>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/*import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:kmobile/di/injection.dart';
|
||||
import 'package:kmobile/features/auth/screens/mpin_screen.dart';
|
||||
import 'package:kmobile/security/secure_storage.dart';
|
||||
import '../../../app.dart';
|
||||
import '../controllers/auth_cubit.dart';
|
||||
import '../controllers/auth_state.dart';
|
||||
|
||||
class LoginScreen extends StatefulWidget {
|
||||
const LoginScreen({super.key});
|
||||
|
||||
@override
|
||||
LoginScreenState createState() => LoginScreenState();
|
||||
}
|
||||
|
||||
class LoginScreenState extends State<LoginScreen> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final _customerNumberController = TextEditingController();
|
||||
final _passwordController = TextEditingController();
|
||||
bool _obscurePassword = true;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_customerNumberController.dispose();
|
||||
_passwordController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _submitForm() {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
context.read<AuthCubit>().login(
|
||||
_customerNumberController.text.trim(),
|
||||
_passwordController.text,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
// appBar: AppBar(title: const Text('Login')),
|
||||
body: BlocConsumer<AuthCubit, AuthState>(
|
||||
listener: (context, state) async {
|
||||
if (state is Authenticated) {
|
||||
final storage = getIt<SecureStorage>();
|
||||
final mpin = await storage.read('mpin');
|
||||
if (mpin == null) {
|
||||
Navigator.of(context).pushReplacement(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => MPinScreen(
|
||||
mode: MPinMode.set,
|
||||
onCompleted: (_) {
|
||||
Navigator.of(context, rootNavigator: true)
|
||||
.pushReplacement(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => const NavigationScaffold()),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
Navigator.of(context).pushReplacement(
|
||||
MaterialPageRoute(builder: (_) => const NavigationScaffold()),
|
||||
);
|
||||
}
|
||||
} else if (state is AuthError) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(state.message)),
|
||||
);
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Image.asset('assets/images/logo.png', width: 150, height: 150,
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
return const Icon(Icons.account_balance,
|
||||
size: 100, color: Colors.blue);
|
||||
}),
|
||||
const SizedBox(height: 16),
|
||||
// Title
|
||||
const Text(
|
||||
'KCCB',
|
||||
style: TextStyle(
|
||||
fontSize: 32,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.blue),
|
||||
),
|
||||
const SizedBox(height: 48),
|
||||
|
||||
TextFormField(
|
||||
controller: _customerNumberController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Customer Number',
|
||||
// prefixIcon: Icon(Icons.person),
|
||||
border: OutlineInputBorder(),
|
||||
isDense: true,
|
||||
filled: true,
|
||||
fillColor: Colors.white,
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.black),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.black, width: 2),
|
||||
),
|
||||
),
|
||||
keyboardType: TextInputType.number,
|
||||
textInputAction: TextInputAction.next,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Please enter your username';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
TextFormField(
|
||||
controller: _passwordController,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Password',
|
||||
// prefixIcon: const Icon(Icons.lock),
|
||||
border: const OutlineInputBorder(),
|
||||
isDense: true,
|
||||
filled: true,
|
||||
fillColor: Colors.white,
|
||||
enabledBorder: const OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.black),
|
||||
),
|
||||
focusedBorder: const OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.black, width: 2),
|
||||
),
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(
|
||||
_obscurePassword
|
||||
? Icons.visibility
|
||||
: Icons.visibility_off,
|
||||
),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_obscurePassword = !_obscurePassword;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
textInputAction: TextInputAction.done,
|
||||
obscureText: _obscurePassword,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Please enter your password';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
SizedBox(
|
||||
width: 250,
|
||||
child: ElevatedButton(
|
||||
onPressed: state is AuthLoading ? null : _submitForm,
|
||||
style: ElevatedButton.styleFrom(
|
||||
shape: const StadiumBorder(),
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
backgroundColor: Colors.white,
|
||||
foregroundColor: Colors.blueAccent,
|
||||
side: const BorderSide(color: Colors.black, width: 1),
|
||||
elevation: 0),
|
||||
child: state is AuthLoading
|
||||
? const CircularProgressIndicator()
|
||||
: const Text(
|
||||
'Login',
|
||||
style: TextStyle(fontSize: 16),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(child: Divider()),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 8),
|
||||
child: Text('OR'),
|
||||
),
|
||||
Expanded(child: Divider()),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 25),
|
||||
|
||||
// Register Button
|
||||
SizedBox(
|
||||
width: 250,
|
||||
child: ElevatedButton(
|
||||
//disable until registration is implemented
|
||||
onPressed: null,
|
||||
style: OutlinedButton.styleFrom(
|
||||
shape: const StadiumBorder(),
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
backgroundColor: Colors.lightBlue[100],
|
||||
foregroundColor: Colors.black),
|
||||
child: const Text('Register'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import '../../../l10n/app_localizations.dart';
|
||||
import 'dart:math';
|
||||
|
||||
import 'dart:developer';
|
||||
// import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:kmobile/app.dart';
|
||||
import 'package:kmobile/di/injection.dart';
|
||||
import 'package:kmobile/security/secure_storage.dart';
|
||||
import 'package:local_auth/local_auth.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
enum MPinMode { enter, set, confirm }
|
||||
|
||||
@@ -14,38 +15,96 @@ class MPinScreen extends StatefulWidget {
|
||||
final MPinMode mode;
|
||||
final String? initialPin;
|
||||
final void Function(String pin)? onCompleted;
|
||||
final bool disableBiometric;
|
||||
final String? customTitle;
|
||||
final String? customConfirmTitle;
|
||||
|
||||
const MPinScreen({
|
||||
super.key,
|
||||
required this.mode,
|
||||
this.initialPin,
|
||||
this.onCompleted,
|
||||
this.disableBiometric = false,
|
||||
this.customTitle,
|
||||
this.customConfirmTitle,
|
||||
});
|
||||
|
||||
@override
|
||||
State<MPinScreen> createState() => _MPinScreenState();
|
||||
}
|
||||
|
||||
class _MPinScreenState extends State<MPinScreen> {
|
||||
class _MPinScreenState extends State<MPinScreen> with TickerProviderStateMixin {
|
||||
List<String> mPin = [];
|
||||
String? errorText;
|
||||
|
||||
// Animation controllers
|
||||
late final AnimationController _bounceController;
|
||||
late final Animation<double> _bounceAnimation;
|
||||
late final AnimationController _shakeController;
|
||||
late final AnimationController _waveController;
|
||||
late final Animation<double> _waveAnimation;
|
||||
|
||||
// State flags for animations
|
||||
bool _isError = false;
|
||||
bool _isSuccess = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (widget.mode == MPinMode.enter) {
|
||||
// Bounce animation for single dot entry
|
||||
_bounceController = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 150),
|
||||
);
|
||||
_bounceAnimation = Tween<double>(begin: 1.0, end: 1.2).animate(
|
||||
CurvedAnimation(
|
||||
parent: _bounceController,
|
||||
curve: Curves.elasticIn,
|
||||
reverseCurve: Curves.elasticOut,
|
||||
),
|
||||
)..addStatusListener((status) {
|
||||
if (status == AnimationStatus.completed) {
|
||||
_bounceController.reverse();
|
||||
}
|
||||
});
|
||||
|
||||
// Shake animation for error
|
||||
_shakeController = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 400),
|
||||
);
|
||||
|
||||
// Wave animation for success
|
||||
_waveController = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 800),
|
||||
);
|
||||
_waveAnimation = Tween<double>(begin: 0, end: 1).animate(
|
||||
CurvedAnimation(parent: _waveController, curve: Curves.easeInOut),
|
||||
);
|
||||
|
||||
if (widget.mode == MPinMode.enter && !widget.disableBiometric) {
|
||||
_tryBiometricBeforePin();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_bounceController.dispose();
|
||||
_shakeController.dispose();
|
||||
_waveController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _tryBiometricBeforePin() async {
|
||||
final storage = getIt<SecureStorage>();
|
||||
final enabled = await storage.read('biometric_enabled');
|
||||
log('biometric_enabled: $enabled');
|
||||
// log('biometric_enabled: $enabled');
|
||||
if (enabled != null && enabled) {
|
||||
final auth = LocalAuthentication();
|
||||
if (await auth.canCheckBiometrics) {
|
||||
final didAuth = await auth.authenticate(
|
||||
// ignore: use_build_context_synchronously
|
||||
localizedReason: AppLocalizations.of(context).authenticateToAccess,
|
||||
options: const AuthenticationOptions(biometricOnly: true),
|
||||
);
|
||||
@@ -61,11 +120,13 @@ class _MPinScreenState extends State<MPinScreen> {
|
||||
}
|
||||
|
||||
void addDigit(String digit) {
|
||||
if (_shakeController.isAnimating || _waveController.isAnimating) return;
|
||||
if (mPin.length < 4) {
|
||||
setState(() {
|
||||
mPin.add(digit);
|
||||
errorText = null;
|
||||
});
|
||||
_bounceController.forward(from: 0);
|
||||
if (mPin.length == 4) {
|
||||
_handleComplete();
|
||||
}
|
||||
@@ -73,6 +134,7 @@ class _MPinScreenState extends State<MPinScreen> {
|
||||
}
|
||||
|
||||
void deleteDigit() {
|
||||
if (_shakeController.isAnimating || _waveController.isAnimating) return;
|
||||
if (mPin.isNotEmpty) {
|
||||
setState(() {
|
||||
mPin.removeLast();
|
||||
@@ -82,71 +144,148 @@ class _MPinScreenState extends State<MPinScreen> {
|
||||
}
|
||||
|
||||
Future<void> _handleComplete() async {
|
||||
if (_shakeController.isAnimating || _waveController.isAnimating) return;
|
||||
|
||||
final pin = mPin.join();
|
||||
final storage = SecureStorage();
|
||||
|
||||
switch (widget.mode) {
|
||||
case MPinMode.enter:
|
||||
final storedPin = await storage.read('mpin');
|
||||
log('storedPin: $storedPin');
|
||||
// log('storedPin: $storedPin');
|
||||
if (storedPin == int.tryParse(pin)) {
|
||||
widget.onCompleted?.call(pin);
|
||||
} else {
|
||||
// Correct PIN
|
||||
setState(() {
|
||||
_isSuccess = true;
|
||||
errorText = null;
|
||||
});
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
_waveController.forward(from: 0).whenComplete(() {
|
||||
widget.onCompleted?.call(pin);
|
||||
});
|
||||
} else {
|
||||
// Incorrect PIN
|
||||
setState(() {
|
||||
_isError = true;
|
||||
errorText = AppLocalizations.of(context).incorrectMPIN;
|
||||
});
|
||||
await _shakeController.forward(from: 0);
|
||||
setState(() {
|
||||
mPin.clear();
|
||||
_isError = false;
|
||||
// Keep error text until next digit is entered
|
||||
});
|
||||
}
|
||||
break;
|
||||
case MPinMode.set:
|
||||
// propagate parent onCompleted into confirm step
|
||||
Navigator.push(
|
||||
// Navigate to confirm and wait for result
|
||||
final result = await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => MPinScreen(
|
||||
mode: MPinMode.confirm,
|
||||
initialPin: pin,
|
||||
onCompleted: widget.onCompleted, // <-- use parent callback
|
||||
onCompleted: (confirmedPin) {
|
||||
// Just pop with the pin, don't call parent callback yet
|
||||
Navigator.of(context).pop(confirmedPin);
|
||||
},
|
||||
disableBiometric: widget.disableBiometric,
|
||||
customTitle: widget.customConfirmTitle,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// If confirm succeeded, call parent callback
|
||||
if (result != null && mounted) {
|
||||
widget.onCompleted?.call(result);
|
||||
}
|
||||
break;
|
||||
case MPinMode.confirm:
|
||||
if (widget.initialPin == pin) {
|
||||
// 1) persist the pin
|
||||
await storage.write('mpin', pin);
|
||||
|
||||
// 3) now clear the entire navigation stack and go to your main scaffold
|
||||
// 2) Call the onCompleted callback to let the parent handle navigation
|
||||
if (mounted) {
|
||||
Navigator.of(context, rootNavigator: true).pushAndRemoveUntil(
|
||||
MaterialPageRoute(builder: (_) => const NavigationScaffold()),
|
||||
(route) => false,
|
||||
);
|
||||
widget.onCompleted?.call(pin);
|
||||
}
|
||||
} else {
|
||||
setState(() {
|
||||
_isError = true;
|
||||
errorText = AppLocalizations.of(context).pinsDoNotMatch;
|
||||
});
|
||||
await _shakeController.forward(from: 0);
|
||||
setState(() {
|
||||
mPin.clear();
|
||||
_isError = false;
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Widget buildMPinDots() {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: List.generate(4, (index) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.all(8),
|
||||
width: 15,
|
||||
height: 15,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: index < mPin.length ? Colors.black : Colors.grey[400],
|
||||
Widget buildMPinDots(BuildContext context) {
|
||||
return AnimatedBuilder(
|
||||
animation: Listenable.merge(
|
||||
[_bounceController, _shakeController, _waveController]),
|
||||
builder: (context, child) {
|
||||
double shakeOffset = 0;
|
||||
if (_shakeController.isAnimating) {
|
||||
// 4 cycles of sine wave for shake
|
||||
shakeOffset = sin(_shakeController.value * 4 * pi) * 12;
|
||||
}
|
||||
|
||||
return Transform.translate(
|
||||
offset: Offset(shakeOffset, 0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: List.generate(4, (index) {
|
||||
final isFilled = index < mPin.length;
|
||||
|
||||
// Bounce animation for single dot
|
||||
final isAnimatingBounce =
|
||||
index == mPin.length - 1 && _bounceController.isAnimating;
|
||||
double bounceScale =
|
||||
isAnimatingBounce ? _bounceAnimation.value : 1.0;
|
||||
|
||||
// Success wave animation
|
||||
double waveScale = 1.0;
|
||||
if (_isSuccess) {
|
||||
final waveDelay = index * 0.15;
|
||||
final waveValue =
|
||||
(_waveAnimation.value - waveDelay).clamp(0.0, 1.0);
|
||||
// Grow and shrink
|
||||
waveScale = 1.0 + sin(waveValue * pi) * 0.4;
|
||||
}
|
||||
|
||||
// Determine dot color
|
||||
Color dotColor;
|
||||
if (_isError) {
|
||||
dotColor = Theme.of(context).colorScheme.error;
|
||||
} else if (_isSuccess) {
|
||||
dotColor = Colors.green.shade600;
|
||||
} else {
|
||||
dotColor = isFilled
|
||||
? Theme.of(context).colorScheme.onSurfaceVariant
|
||||
: Theme.of(context).colorScheme.surfaceContainerHighest;
|
||||
}
|
||||
|
||||
return Transform.scale(
|
||||
scale: bounceScale * waveScale,
|
||||
child: Container(
|
||||
margin: const EdgeInsets.all(8),
|
||||
width: 25,
|
||||
height: 25,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: dotColor,
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
);
|
||||
}),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -164,9 +303,10 @@ class _MPinScreenState extends State<MPinScreen> {
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: row.map((key) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
padding: const EdgeInsets.all(1.0),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
HapticFeedback.lightImpact();
|
||||
if (key == '<') {
|
||||
deleteDigit();
|
||||
} else if (key == 'Enter') {
|
||||
@@ -184,11 +324,10 @@ class _MPinScreenState extends State<MPinScreen> {
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
width: 70,
|
||||
height: 70,
|
||||
decoration: BoxDecoration(
|
||||
width: 80,
|
||||
height: 80,
|
||||
decoration: const BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: Colors.grey[200],
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: key == 'Enter'
|
||||
@@ -196,8 +335,10 @@ class _MPinScreenState extends State<MPinScreen> {
|
||||
: Text(
|
||||
key == '<' ? '⌫' : key,
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
color: key == 'Enter' ? Theme.of(context).primaryColor : Colors.black,
|
||||
fontSize: 30,
|
||||
color: key == 'Enter'
|
||||
? Theme.of(context).primaryColor
|
||||
: Theme.of(context).colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -210,6 +351,9 @@ class _MPinScreenState extends State<MPinScreen> {
|
||||
}
|
||||
|
||||
String getTitle() {
|
||||
if (widget.customTitle != null) {
|
||||
return widget.customTitle!;
|
||||
}
|
||||
switch (widget.mode) {
|
||||
case MPinMode.enter:
|
||||
return AppLocalizations.of(context).enterMPIN;
|
||||
@@ -226,7 +370,7 @@ class _MPinScreenState extends State<MPinScreen> {
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
const Spacer(),
|
||||
const SizedBox(height: 50),
|
||||
// Logo
|
||||
Image.asset('assets/images/logo.png', height: 100),
|
||||
const SizedBox(height: 20),
|
||||
@@ -234,19 +378,18 @@ class _MPinScreenState extends State<MPinScreen> {
|
||||
getTitle(),
|
||||
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.w500),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
buildMPinDots(),
|
||||
const Spacer(),
|
||||
buildMPinDots(context),
|
||||
if (errorText != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8.0),
|
||||
child: Text(
|
||||
errorText!,
|
||||
style: const TextStyle(color: Colors.red),
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
buildNumberPad(),
|
||||
const Spacer(),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||