Compare commits
188 Commits
language-t
...
testing-2
| Author | SHA1 | Date | |
|---|---|---|---|
| 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/debug
|
||||||
/android/app/profile
|
/android/app/profile
|
||||||
/android/app/release
|
/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,
|
# The following line activates a set of recommended lints for Flutter apps,
|
||||||
# packages, and plugins designed to encourage good coding practices.
|
# 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
|
include: package:flutter_lints/flutter.yaml
|
||||||
|
|
||||||
linter:
|
linter:
|
||||||
|
|||||||
@@ -22,10 +22,16 @@ if (flutterVersionName == null) {
|
|||||||
flutterVersionName = '1.0'
|
flutterVersionName = '1.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def keystoreProperties = new Properties()
|
||||||
|
def keystorePropertiesFile = rootProject.file('key.properties')
|
||||||
|
if (keystorePropertiesFile.exists()) {
|
||||||
|
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
|
||||||
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
namespace "com.example.kmobile"
|
namespace "com.example.kmobile"
|
||||||
compileSdk flutter.compileSdkVersion
|
compileSdk flutter.compileSdkVersion
|
||||||
ndkVersion flutter.ndkVersion
|
ndkVersion "27.0.12077973"
|
||||||
|
|
||||||
compileOptions {
|
compileOptions {
|
||||||
sourceCompatibility JavaVersion.VERSION_1_8
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
@@ -45,17 +51,27 @@ android {
|
|||||||
applicationId "com.example.kmobile"
|
applicationId "com.example.kmobile"
|
||||||
// You can update the following values to match your application needs.
|
// 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.
|
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
|
||||||
minSdkVersion flutter.minSdkVersion
|
minSdkVersion 29
|
||||||
targetSdkVersion flutter.targetSdkVersion
|
targetSdkVersion flutter.targetSdkVersion
|
||||||
versionCode flutterVersionCode.toInteger()
|
versionCode flutterVersionCode.toInteger()
|
||||||
versionName flutterVersionName
|
versionName flutterVersionName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
signingConfigs {
|
||||||
|
release {
|
||||||
|
keyAlias keystoreProperties['keyAlias']
|
||||||
|
keyPassword keystoreProperties['keyPassword']
|
||||||
|
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
|
||||||
|
storePassword keystoreProperties['storePassword']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
// TODO: Add your own signing config for the release build.
|
signingConfig signingConfigs.release
|
||||||
// Signing with the debug keys for now, so `flutter run --release` works.
|
minifyEnabled true
|
||||||
signingConfig signingConfigs.debug
|
shrinkResources true
|
||||||
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
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
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
android:label="kmobile"
|
android:label="kmobile"
|
||||||
android:name="${applicationName}"
|
android:name="${applicationName}"
|
||||||
android:usesCleartextTraffic="true"
|
android:usesCleartextTraffic="true"
|
||||||
|
android:allowBackup="false"
|
||||||
android:icon="@mipmap/ic_launcher">
|
android:icon="@mipmap/ic_launcher">
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
@@ -39,6 +40,20 @@
|
|||||||
https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.
|
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. -->
|
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>
|
<queries>
|
||||||
<intent>
|
<intent>
|
||||||
<action android:name="android.intent.action.PROCESS_TEXT"/>
|
<action android:name="android.intent.action.PROCESS_TEXT"/>
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
package com.example.kmobile
|
package com.example.kmobile
|
||||||
|
|
||||||
import io.flutter.embedding.android.FlutterFragmentActivity
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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/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;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
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_ANALYZER_NONNULL = YES;
|
||||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||||
CLANG_CXX_LIBRARY = "libc++";
|
CLANG_CXX_LIBRARY = "libc++";
|
||||||
@@ -484,7 +484,7 @@
|
|||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
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_ANALYZER_NONNULL = YES;
|
||||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||||
CLANG_CXX_LIBRARY = "libc++";
|
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/>
|
<true/>
|
||||||
<key>NSFaceIDUsageDescription</key>
|
<key>NSFaceIDUsageDescription</key>
|
||||||
<string>We use Face ID to secure your data.</string>
|
<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>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// ignore_for_file: unused_local_variable
|
||||||
|
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import '../../data/repositories/auth_repository.dart';
|
import '../../data/repositories/auth_repository.dart';
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import '../../features/auth/models/auth_token.dart';
|
|||||||
import '../../features/auth/models/auth_credentials.dart';
|
import '../../features/auth/models/auth_credentials.dart';
|
||||||
import '../../core/errors/exceptions.dart';
|
import '../../core/errors/exceptions.dart';
|
||||||
|
|
||||||
|
|
||||||
class AuthService {
|
class AuthService {
|
||||||
final Dio _dio;
|
final Dio _dio;
|
||||||
AuthService(this._dio);
|
AuthService(this._dio);
|
||||||
@@ -26,11 +25,13 @@ class AuthService {
|
|||||||
print(e.toString());
|
print(e.toString());
|
||||||
}
|
}
|
||||||
if (e.response?.statusCode == 401) {
|
if (e.response?.statusCode == 401) {
|
||||||
throw AuthException('Invalid credentials');
|
throw AuthException(
|
||||||
|
e.response?.data['error'] ?? 'SOMETHING WENT WRONG');
|
||||||
}
|
}
|
||||||
throw NetworkException('Network error during login');
|
throw NetworkException('Network error during login');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw UnexpectedException('Unexpected error during login: ${e.toString()}');
|
throw UnexpectedException(
|
||||||
|
'Unexpected error during login: ${e.toString()}');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +67,8 @@ class AuthService {
|
|||||||
}
|
}
|
||||||
throw NetworkException('Network error during TPIN check');
|
throw NetworkException('Network error during TPIN check');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw UnexpectedException('Unexpected error during TPIN check: ${e.toString()}');
|
throw UnexpectedException(
|
||||||
|
'Unexpected error during TPIN check: ${e.toString()}');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,8 +88,76 @@ class AuthService {
|
|||||||
}
|
}
|
||||||
throw NetworkException('Network error during TPIN setup');
|
throw NetworkException('Network error during TPIN setup');
|
||||||
} catch (e) {
|
} 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:dio/dio.dart';
|
||||||
|
import 'package:kmobile/core/errors/exceptions.dart';
|
||||||
import 'package:kmobile/data/models/ifsc.dart';
|
import 'package:kmobile/data/models/ifsc.dart';
|
||||||
import 'package:kmobile/data/models/beneficiary.dart';
|
import 'package:kmobile/data/models/beneficiary.dart';
|
||||||
|
|
||||||
@@ -9,14 +11,16 @@ class BeneficiaryService {
|
|||||||
|
|
||||||
Future<String> validateBeneficiaryWithinBank(String accountNumber) async {
|
Future<String> validateBeneficiaryWithinBank(String accountNumber) async {
|
||||||
try {
|
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,
|
'accountNumber': accountNumber,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
return response.data['name'];
|
return response.data['name'];
|
||||||
} else {
|
} else {
|
||||||
throw Exception(response.data['error'] ?? 'Failed to validate beneficiary');
|
throw Exception(
|
||||||
|
response.data['error'] ?? 'Failed to validate beneficiary');
|
||||||
}
|
}
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
throw Exception('Network error: ${e.message}');
|
throw Exception('Network error: ${e.message}');
|
||||||
@@ -25,136 +29,73 @@ class BeneficiaryService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<Ifsc> validateIFSC(String ifscCode) async {
|
||||||
Future<ifsc?> validateIFSC(String ifscCode) async {
|
|
||||||
try {
|
try {
|
||||||
final response = await _dio.get('/api/beneficiary/ifsc-details', queryParameters: {
|
final response = await _dio.get('/api/beneficiary/ifsc-details',
|
||||||
"ifscCode": ifscCode
|
queryParameters: {"ifscCode": ifscCode});
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
return ifsc.fromJson(response.data);
|
return Ifsc.fromJson(response.data);
|
||||||
}
|
}
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
if (e.response?.statusCode == 404) {
|
if (e.response?.statusCode == 404) {
|
||||||
print('Invalid IFSC code.');
|
throw Exception('INVALID IFSC CODE');
|
||||||
} else {
|
} else if (e.response?.statusCode == 401) {
|
||||||
print('API error: ${e.message}');
|
throw Exception('INVALID IFSC CODE');
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('Unexpected error: $e');
|
throw UnexpectedException(
|
||||||
|
'Unexpected error during login: ${e.toString()}');
|
||||||
|
}
|
||||||
|
return Ifsc.fromJson({});
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
Future<String> validateBeneficiary({
|
||||||
|
|
||||||
}
|
|
||||||
///Step 1: Validate beneficiary (returns refNo)
|
|
||||||
Future<String?> validateBeneficiary({
|
|
||||||
required String accountNo,
|
required String accountNo,
|
||||||
required String ifscCode,
|
required String ifscCode,
|
||||||
required String remitterName,
|
required String remitterName,
|
||||||
}) async {
|
}) async {
|
||||||
|
log('inside validate beneficiary service');
|
||||||
try {
|
final response = await _dio.get(
|
||||||
final response = await _dio.post(
|
'/api/beneficiary/validate/outside-bank',
|
||||||
'/api/beneficiary/validate/outside_bank',
|
|
||||||
queryParameters: {
|
queryParameters: {
|
||||||
'accountNo': accountNo,
|
'accountNo': accountNo,
|
||||||
'ifscCode': ifscCode,
|
'ifscCode': ifscCode,
|
||||||
'remitterName': remitterName,
|
'remitterName': remitterName,
|
||||||
},
|
},
|
||||||
|
options: Options(
|
||||||
|
sendTimeout: const Duration(seconds: 60),
|
||||||
|
receiveTimeout: const Duration(seconds: 60),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
if (response.statusCode != 200) {
|
||||||
if (response.statusCode == 200) {
|
throw Exception("Invalid Beneficiary Details");
|
||||||
return response.data['refNo'];
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
print("Error validating beneficiary: $e");
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
return response.data['name'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Step 2: Check validation status (returns Beneficiary name if success)
|
// Beneficiary Validate And ADD
|
||||||
Future<String?> checkValidationStatus(String refNo) async {
|
Future<bool> sendForValidation(Beneficiary beneficiary) async {
|
||||||
try {
|
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(
|
final response = await _dio.post(
|
||||||
'/api/beneficiary/add',
|
'/api/beneficiary',
|
||||||
data: beneficiary.toJson(),
|
data: beneficiary.toJson(),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
print("SENT FOR VALIDATION");
|
return true;
|
||||||
} else {
|
} else {
|
||||||
print("VALIDATION REQUEST FAILED: ${response.statusCode}");
|
return false;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print("ERROR IN SENDING REQUEST: $e");
|
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Poll to check if beneficiary is found
|
Future<List<Beneficiary>> fetchBeneficiaryList() async {
|
||||||
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 {
|
try {
|
||||||
final response = await _dio.get(
|
final response = await _dio.get(
|
||||||
'/api/beneficiary/check?',
|
"/api/beneficiary",
|
||||||
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{
|
|
||||||
try {
|
|
||||||
final response = await _dio.get(
|
|
||||||
"/api/beneficiary/get",
|
|
||||||
options: Options(
|
options: Options(
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -164,16 +105,25 @@ class BeneficiaryService {
|
|||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
return Beneficiary.listFromJson(response.data);
|
return Beneficiary.listFromJson(response.data);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw Exception("Failed to fetch beneficiaries");
|
throw Exception("Failed to fetch beneficiaries");
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print("Error fetching beneficiaries: $e");
|
|
||||||
return [];
|
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()}');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
137
lib/api/services/branch_service.dart
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
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()}');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
57
lib/api/services/limit_service.dart
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
// 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()}');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
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 'dart:developer';
|
||||||
|
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:kmobile/data/models/payment_response.dart';
|
import 'package:kmobile/data/models/payment_response.dart';
|
||||||
import 'package:kmobile/data/models/transfer.dart';
|
import 'package:kmobile/data/models/transfer.dart';
|
||||||
|
|||||||
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()}');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@ class UserService {
|
|||||||
|
|
||||||
Future<List<User>> getUserDetails() async {
|
Future<List<User>> getUserDetails() async {
|
||||||
try {
|
try {
|
||||||
final response = await _dio.get('/api/customer/details');
|
final response = await _dio.get('/api/customer');
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
log('Response: ${response.data}');
|
log('Response: ${response.data}');
|
||||||
return (response.data as List)
|
return (response.data as List)
|
||||||
|
|||||||
244
lib/app.dart
@@ -2,6 +2,8 @@ import 'dart:io';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.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:kmobile/security/secure_storage.dart';
|
||||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||||
import './l10n/app_localizations.dart';
|
import './l10n/app_localizations.dart';
|
||||||
@@ -11,13 +13,14 @@ import 'config/routes.dart';
|
|||||||
import 'di/injection.dart';
|
import 'di/injection.dart';
|
||||||
import 'features/auth/controllers/auth_cubit.dart';
|
import 'features/auth/controllers/auth_cubit.dart';
|
||||||
import 'features/card/screens/card_management_screen.dart';
|
import 'features/card/screens/card_management_screen.dart';
|
||||||
import 'features/auth/screens/welcome_screen.dart';
|
import 'features/auth/screens/splash_screen.dart';
|
||||||
import 'features/auth/screens/login_screen.dart';
|
import 'features/auth/screens/login_screen.dart';
|
||||||
import 'features/service/screens/service_screen.dart';
|
import 'features/service/screens/service_screen.dart';
|
||||||
import 'features/dashboard/screens/dashboard_screen.dart';
|
import 'features/dashboard/screens/dashboard_screen.dart';
|
||||||
import 'features/auth/screens/mpin_screen.dart';
|
import 'features/auth/screens/mpin_screen.dart';
|
||||||
import 'package:local_auth/local_auth.dart';
|
import 'package:local_auth/local_auth.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
class KMobile extends StatefulWidget {
|
class KMobile extends StatefulWidget {
|
||||||
const KMobile({super.key});
|
const KMobile({super.key});
|
||||||
@@ -26,38 +29,64 @@ class KMobile extends StatefulWidget {
|
|||||||
State<KMobile> createState() => _KMobileState();
|
State<KMobile> createState() => _KMobileState();
|
||||||
|
|
||||||
static void setLocale(BuildContext context, Locale newLocale) {
|
static void setLocale(BuildContext context, Locale newLocale) {
|
||||||
final _KMobileState? state = context.findAncestorStateOfType<_KMobileState>();
|
final _KMobileState? state =
|
||||||
|
context.findAncestorStateOfType<_KMobileState>();
|
||||||
state?.setLocale(newLocale);
|
state?.setLocale(newLocale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _KMobileState extends State<KMobile> {
|
class _KMobileState extends State<KMobile> with WidgetsBindingObserver {
|
||||||
|
Timer? _backgroundTimer;
|
||||||
bool showSplash = true;
|
bool showSplash = true;
|
||||||
Locale? _locale;
|
Locale? _locale;
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
WidgetsBinding.instance.addObserver(this);
|
||||||
loadPreferences();
|
loadPreferences();
|
||||||
Future.delayed(const Duration(seconds: 2), () {
|
Future.delayed(const Duration(seconds: 3), () {
|
||||||
setState(() {
|
setState(() {
|
||||||
showSplash = false;
|
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 {
|
Future<void> loadPreferences() async {
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
|
||||||
// Load Locale
|
|
||||||
final String? langCode = prefs.getString('locale');
|
final String? langCode = prefs.getString('locale');
|
||||||
if (langCode != null) {
|
if (langCode != null) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_locale = Locale(langCode);
|
_locale = Locale(langCode);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setLocale(Locale locale) {
|
void setLocale(Locale locale) {
|
||||||
@@ -67,56 +96,55 @@ class _KMobileState extends State<KMobile> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// Set status bar color and brightness
|
SystemChrome.setSystemUIOverlayStyle(
|
||||||
SystemChrome.setSystemUIOverlayStyle(
|
const SystemUiOverlayStyle(
|
||||||
const SystemUiOverlayStyle(
|
statusBarColor: Colors.transparent,
|
||||||
statusBarColor: Colors.transparent,
|
statusBarIconBrightness: Brightness.dark,
|
||||||
statusBarIconBrightness: Brightness.dark,
|
),
|
||||||
),
|
);
|
||||||
);
|
|
||||||
|
|
||||||
return MultiBlocProvider(
|
return MultiBlocProvider(
|
||||||
providers: [
|
providers: [
|
||||||
BlocProvider<AuthCubit>(create: (_) => getIt<AuthCubit>()),
|
BlocProvider<AuthCubit>(create: (_) => getIt<AuthCubit>()),
|
||||||
BlocProvider<ThemeCubit>(create: (_) => getIt<ThemeCubit>()),
|
BlocProvider<ThemeCubit>(create: (_) => ThemeCubit()),
|
||||||
],
|
BlocProvider<ThemeModeCubit>(create: (_) => ThemeModeCubit()),
|
||||||
child: BlocBuilder<ThemeCubit, ThemeState>(
|
],
|
||||||
builder: (context, themeState) {
|
child: BlocBuilder<ThemeCubit, ThemeState>(
|
||||||
print('global theme state changed');
|
builder: (context, themeState) {
|
||||||
print(themeState);
|
return BlocBuilder<ThemeModeCubit, ThemeModeState>(
|
||||||
return MaterialApp(
|
builder: (context, modeState) {
|
||||||
debugShowCheckedModeBanner: false,
|
return MaterialApp(
|
||||||
locale: _locale ?? const Locale('en'),
|
debugShowCheckedModeBanner: false,
|
||||||
supportedLocales: const [
|
locale: _locale ?? const Locale('en'),
|
||||||
Locale('en'),
|
supportedLocales: const [
|
||||||
Locale('hi'),
|
Locale('en'),
|
||||||
],
|
Locale('hi'),
|
||||||
localizationsDelegates: const [
|
],
|
||||||
AppLocalizations.delegate,
|
localizationsDelegates: const [
|
||||||
GlobalMaterialLocalizations.delegate,
|
AppLocalizations.delegate,
|
||||||
GlobalWidgetsLocalizations.delegate,
|
GlobalMaterialLocalizations.delegate,
|
||||||
GlobalCupertinoLocalizations.delegate,
|
GlobalWidgetsLocalizations.delegate,
|
||||||
],
|
GlobalCupertinoLocalizations.delegate,
|
||||||
title: 'kMobile',
|
],
|
||||||
//theme: AppThemes.getLightTheme(themeState.themeType),
|
title: 'kMobile',
|
||||||
theme: themeState.getThemeData(),
|
theme: themeState.getLightThemeData(),
|
||||||
// darkTheme: AppThemes.getDarkTheme(themeState.themeType),
|
darkTheme: themeState.getDarkThemeData(),
|
||||||
themeMode: ThemeMode.system,
|
themeMode: context.watch<ThemeModeCubit>().state.mode,
|
||||||
onGenerateRoute: AppRoutes.generateRoute,
|
onGenerateRoute: AppRoutes.generateRoute,
|
||||||
initialRoute: AppRoutes.splash,
|
initialRoute: AppRoutes.splash,
|
||||||
home: showSplash ? const SplashScreen() : const AuthGate(),
|
home: showSplash ? const SplashScreen() : const AuthGate(),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
);
|
||||||
);
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
class AuthGate extends StatefulWidget {
|
class AuthGate extends StatefulWidget {
|
||||||
const AuthGate({super.key});
|
const AuthGate({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<AuthGate> createState() => _AuthGateState();
|
State<AuthGate> createState() => _AuthGateState();
|
||||||
}
|
}
|
||||||
@@ -124,7 +152,6 @@ class AuthGate extends StatefulWidget {
|
|||||||
class _AuthGateState extends State<AuthGate> {
|
class _AuthGateState extends State<AuthGate> {
|
||||||
bool _checking = true;
|
bool _checking = true;
|
||||||
bool _isLoggedIn = false;
|
bool _isLoggedIn = false;
|
||||||
bool _showWelcome = true;
|
|
||||||
bool _hasMPin = false;
|
bool _hasMPin = false;
|
||||||
bool _biometricEnabled = false;
|
bool _biometricEnabled = false;
|
||||||
bool _biometricTried = false;
|
bool _biometricTried = false;
|
||||||
@@ -142,8 +169,7 @@ class _AuthGateState extends State<AuthGate> {
|
|||||||
final mpin = await storage.read('mpin');
|
final mpin = await storage.read('mpin');
|
||||||
final biometric = await storage.read('biometric_enabled');
|
final biometric = await storage.read('biometric_enabled');
|
||||||
setState(() {
|
setState(() {
|
||||||
_isLoggedIn =
|
_isLoggedIn = accessToken != null &&
|
||||||
accessToken != null &&
|
|
||||||
accessTokenExpiry != null &&
|
accessTokenExpiry != null &&
|
||||||
DateTime.parse(accessTokenExpiry).isAfter(DateTime.now());
|
DateTime.parse(accessTokenExpiry).isAfter(DateTime.now());
|
||||||
_hasMPin = mpin != null;
|
_hasMPin = mpin != null;
|
||||||
@@ -158,9 +184,13 @@ class _AuthGateState extends State<AuthGate> {
|
|||||||
final localAuth = LocalAuthentication();
|
final localAuth = LocalAuthentication();
|
||||||
final canCheck = await localAuth.canCheckBiometrics;
|
final canCheck = await localAuth.canCheckBiometrics;
|
||||||
if (!canCheck) return false;
|
if (!canCheck) return false;
|
||||||
|
String localizedReason = "";
|
||||||
|
if (mounted) {
|
||||||
|
localizedReason = AppLocalizations.of(context).authenticateToAccess;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
final didAuth = await localAuth.authenticate(
|
final didAuth = await localAuth.authenticate(
|
||||||
localizedReason: AppLocalizations.of(context).authenticateToAccess,
|
localizedReason: localizedReason,
|
||||||
options: const AuthenticationOptions(
|
options: const AuthenticationOptions(
|
||||||
stickyAuth: true,
|
stickyAuth: true,
|
||||||
biometricOnly: true,
|
biometricOnly: true,
|
||||||
@@ -172,24 +202,11 @@ class _AuthGateState extends State<AuthGate> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (_checking) {
|
if (_checking) {
|
||||||
return const SplashScreen();
|
return const SplashScreen();
|
||||||
}
|
}
|
||||||
// ✅ Step 1: Show welcome screen first, only once
|
|
||||||
if (_showWelcome) {
|
|
||||||
return WelcomeScreen(
|
|
||||||
onContinue: () {
|
|
||||||
setState(() {
|
|
||||||
_showWelcome = false;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ✅ Step 2: Check login status
|
|
||||||
if (_isLoggedIn) {
|
if (_isLoggedIn) {
|
||||||
if (_hasMPin) {
|
if (_hasMPin) {
|
||||||
if (_biometricEnabled) {
|
if (_biometricEnabled) {
|
||||||
@@ -199,12 +216,9 @@ class _AuthGateState extends State<AuthGate> {
|
|||||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||||
return const SplashScreen();
|
return const SplashScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (snapshot.data == true) {
|
if (snapshot.data == true) {
|
||||||
return const NavigationScaffold(); // Authenticated
|
return const NavigationScaffold();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ❌ Biometric failed → Show MPIN screen
|
|
||||||
return MPinScreen(
|
return MPinScreen(
|
||||||
mode: MPinMode.enter,
|
mode: MPinMode.enter,
|
||||||
onCompleted: (_) {
|
onCompleted: (_) {
|
||||||
@@ -230,13 +244,11 @@ class _AuthGateState extends State<AuthGate> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// No MPIN set → show MPIN set screen + biometric dialog
|
|
||||||
return MPinScreen(
|
return MPinScreen(
|
||||||
mode: MPinMode.set,
|
mode: MPinMode.set,
|
||||||
onCompleted: (_) async {
|
onCompleted: (_) async {
|
||||||
final storage = getIt<SecureStorage>();
|
final storage = getIt<SecureStorage>();
|
||||||
final localAuth = LocalAuthentication();
|
final localAuth = LocalAuthentication();
|
||||||
|
|
||||||
final optIn = await showDialog<bool>(
|
final optIn = await showDialog<bool>(
|
||||||
context: context,
|
context: context,
|
||||||
barrierDismissible: false,
|
barrierDismissible: false,
|
||||||
@@ -257,15 +269,16 @@ class _AuthGateState extends State<AuthGate> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (optIn == true) {
|
if (optIn == true) {
|
||||||
final canCheck = await localAuth.canCheckBiometrics;
|
final canCheck = await localAuth.canCheckBiometrics;
|
||||||
bool didAuth = false;
|
bool didAuth = false;
|
||||||
|
String authEnable = "";
|
||||||
|
if (context.mounted) {
|
||||||
|
authEnable = AppLocalizations.of(context).authenticateToEnable;
|
||||||
|
}
|
||||||
if (canCheck) {
|
if (canCheck) {
|
||||||
didAuth = await localAuth.authenticate(
|
didAuth = await localAuth.authenticate(
|
||||||
localizedReason:
|
localizedReason: authEnable,
|
||||||
AppLocalizations.of(context).authenticateToEnable,
|
|
||||||
options: const AuthenticationOptions(
|
options: const AuthenticationOptions(
|
||||||
stickyAuth: true,
|
stickyAuth: true,
|
||||||
biometricOnly: true,
|
biometricOnly: true,
|
||||||
@@ -277,25 +290,23 @@ class _AuthGateState extends State<AuthGate> {
|
|||||||
await storage.write('biometric_enabled', 'false');
|
await storage.write('biometric_enabled', 'false');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (context.mounted) {
|
||||||
Navigator.of(context).pushReplacement(
|
Navigator.of(context).pushReplacement(
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (_) => const NavigationScaffold(),
|
builder: (_) => const NavigationScaffold(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ✅ Step 3: If not logged in, show login screen
|
|
||||||
return const LoginScreen();
|
return const LoginScreen();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class NavigationScaffold extends StatefulWidget {
|
class NavigationScaffold extends StatefulWidget {
|
||||||
const NavigationScaffold({super.key});
|
const NavigationScaffold({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<NavigationScaffold> createState() => _NavigationScaffoldState();
|
State<NavigationScaffold> createState() => _NavigationScaffoldState();
|
||||||
}
|
}
|
||||||
@@ -303,20 +314,12 @@ class NavigationScaffold extends StatefulWidget {
|
|||||||
class _NavigationScaffoldState extends State<NavigationScaffold> {
|
class _NavigationScaffoldState extends State<NavigationScaffold> {
|
||||||
final PageController _pageController = PageController();
|
final PageController _pageController = PageController();
|
||||||
int _selectedIndex = 0;
|
int _selectedIndex = 0;
|
||||||
|
|
||||||
final List<Widget> _pages = [
|
final List<Widget> _pages = [
|
||||||
const DashboardScreen(),
|
const DashboardScreen(),
|
||||||
const CardManagementScreen(),
|
// const CardManagementScreen(),
|
||||||
const ServiceScreen(),
|
const ServiceScreen(),
|
||||||
];
|
];
|
||||||
|
|
||||||
void _onItemTapped(int index) {
|
|
||||||
setState(() {
|
|
||||||
_selectedIndex = index;
|
|
||||||
});
|
|
||||||
_pageController.jumpToPage(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return PopScope(
|
return PopScope(
|
||||||
@@ -357,19 +360,24 @@ class _NavigationScaffoldState extends State<NavigationScaffold> {
|
|||||||
bottomNavigationBar: BottomNavigationBar(
|
bottomNavigationBar: BottomNavigationBar(
|
||||||
currentIndex: _selectedIndex,
|
currentIndex: _selectedIndex,
|
||||||
type: BottomNavigationBarType.fixed,
|
type: BottomNavigationBarType.fixed,
|
||||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor, // Light blue background
|
backgroundColor: const Color(0XFF1E58AD),
|
||||||
selectedItemColor: Theme.of(context).primaryColor,
|
selectedItemColor: Theme.of(context).colorScheme.onPrimary,
|
||||||
unselectedItemColor: Colors.black54,
|
unselectedItemColor: Theme.of(context).colorScheme.onSecondary,
|
||||||
onTap: _onItemTapped,
|
onTap: (index) {
|
||||||
|
setState(() {
|
||||||
|
_selectedIndex = index;
|
||||||
|
});
|
||||||
|
_pageController.jumpToPage(index);
|
||||||
|
},
|
||||||
items: [
|
items: [
|
||||||
BottomNavigationBarItem(
|
BottomNavigationBarItem(
|
||||||
icon: const Icon(Icons.home_filled),
|
icon: const Icon(Icons.home_filled),
|
||||||
label: AppLocalizations.of(context).home,
|
label: AppLocalizations.of(context).home,
|
||||||
),
|
),
|
||||||
BottomNavigationBarItem(
|
// BottomNavigationBarItem(
|
||||||
icon: const Icon(Icons.credit_card),
|
// icon: const Icon(Icons.credit_card),
|
||||||
label: AppLocalizations.of(context).card,
|
// label: AppLocalizations.of(context).card,
|
||||||
),
|
// ),
|
||||||
BottomNavigationBarItem(
|
BottomNavigationBarItem(
|
||||||
icon: const Icon(Icons.miscellaneous_services),
|
icon: const Icon(Icons.miscellaneous_services),
|
||||||
label: AppLocalizations.of(context).services,
|
label: AppLocalizations.of(context).services,
|
||||||
@@ -381,34 +389,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 {
|
class BiometricPromptScreen extends StatelessWidget {
|
||||||
final VoidCallback onCompleted;
|
final VoidCallback onCompleted;
|
||||||
const BiometricPromptScreen({super.key, required this.onCompleted});
|
const BiometricPromptScreen({super.key, required this.onCompleted});
|
||||||
|
|
||||||
Future<void> _handleBiometric(BuildContext context) async {
|
Future<void> _handleBiometric(BuildContext context) async {
|
||||||
final localAuth = LocalAuthentication();
|
final localAuth = LocalAuthentication();
|
||||||
final canCheck = await localAuth.canCheckBiometrics;
|
final canCheck = await localAuth.canCheckBiometrics;
|
||||||
@@ -416,8 +399,12 @@ class BiometricPromptScreen extends StatelessWidget {
|
|||||||
onCompleted();
|
onCompleted();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
String localizedReason = "";
|
||||||
|
if (context.mounted) {
|
||||||
|
localizedReason = AppLocalizations.of(context).enableFingerprintQuick;
|
||||||
|
}
|
||||||
final didAuth = await localAuth.authenticate(
|
final didAuth = await localAuth.authenticate(
|
||||||
localizedReason: AppLocalizations.of(context).enableFingerprintQuick,
|
localizedReason: localizedReason,
|
||||||
options: const AuthenticationOptions(
|
options: const AuthenticationOptions(
|
||||||
stickyAuth: true,
|
stickyAuth: true,
|
||||||
biometricOnly: true,
|
biometricOnly: true,
|
||||||
@@ -461,6 +448,9 @@ class BiometricPromptScreen extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
if (!context.mounted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (result == true) {
|
if (result == true) {
|
||||||
await _handleBiometric(context);
|
await _handleBiometric(context);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:kmobile/features/auth/screens/mpin_screen.dart';
|
import 'package:kmobile/features/auth/screens/mpin_screen.dart';
|
||||||
|
import 'package:kmobile/features/auth/screens/splash_screen.dart';
|
||||||
import '../app.dart';
|
import '../app.dart';
|
||||||
import '../features/auth/screens/login_screen.dart';
|
import '../features/auth/screens/login_screen.dart';
|
||||||
// import '../features/auth/screens/forgot_password_screen.dart';
|
// import '../features/auth/screens/forgot_password_screen.dart';
|
||||||
@@ -9,6 +10,7 @@ import '../features/dashboard/screens/dashboard_screen.dart';
|
|||||||
// import '../features/transactions/screens/transactions_screen.dart';
|
// import '../features/transactions/screens/transactions_screen.dart';
|
||||||
// import '../features/payments/screens/payments_screen.dart';
|
// import '../features/payments/screens/payments_screen.dart';
|
||||||
// import '../features/settings/screens/settings_screen.dart';
|
// import '../features/settings/screens/settings_screen.dart';
|
||||||
|
import 'package:kmobile/features/auth/screens/tnc_required_screen.dart';
|
||||||
|
|
||||||
class AppRoutes {
|
class AppRoutes {
|
||||||
// Private constructor to prevent instantiation
|
// Private constructor to prevent instantiation
|
||||||
@@ -33,9 +35,14 @@ class AppRoutes {
|
|||||||
return MaterialPageRoute(builder: (_) => const SplashScreen());
|
return MaterialPageRoute(builder: (_) => const SplashScreen());
|
||||||
case login:
|
case login:
|
||||||
return MaterialPageRoute(builder: (_) => const LoginScreen());
|
return MaterialPageRoute(builder: (_) => const LoginScreen());
|
||||||
|
case TncRequiredScreen.routeName: // Renamed class
|
||||||
|
return MaterialPageRoute(
|
||||||
|
builder: (_) => const TncRequiredScreen()); // Renamed class
|
||||||
case mPin:
|
case mPin:
|
||||||
return MaterialPageRoute(builder: (_) => const MPinScreen(mode: MPinMode.enter,));
|
return MaterialPageRoute(
|
||||||
|
builder: (_) => const MPinScreen(
|
||||||
|
mode: MPinMode.enter,
|
||||||
|
));
|
||||||
|
|
||||||
case register:
|
case register:
|
||||||
// Placeholder - create the RegisterScreen class and uncomment
|
// Placeholder - create the RegisterScreen class and uncomment
|
||||||
@@ -68,7 +75,6 @@ class AppRoutes {
|
|||||||
// return MaterialPageRoute(builder: (_) => const PaymentsScreen());
|
// return MaterialPageRoute(builder: (_) => const PaymentsScreen());
|
||||||
return _errorRoute();
|
return _errorRoute();
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return _errorRoute();
|
return _errorRoute();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
enum ThemeType {
|
enum ThemeType {
|
||||||
violet,
|
violet,
|
||||||
green,
|
green,
|
||||||
orange,
|
orange,
|
||||||
blue,
|
blue,
|
||||||
|
yellow,
|
||||||
}
|
}
|
||||||
@@ -1,32 +1,52 @@
|
|||||||
|
import 'dart:developer';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'theme_type.dart';
|
import 'theme_type.dart';
|
||||||
|
import 'package:google_fonts/google_fonts.dart';
|
||||||
|
|
||||||
class AppThemes {
|
class AppThemes {
|
||||||
static ThemeData getLightTheme(ThemeType type) {
|
static ThemeData getLightTheme(ThemeType type) {
|
||||||
switch (type) {
|
final Color seedColor = _getSeedColor(type);
|
||||||
case ThemeType.green:
|
final colorScheme = ColorScheme.fromSeed(
|
||||||
return ThemeData(primarySwatch: Colors.green);
|
seedColor: seedColor,
|
||||||
case ThemeType.orange:
|
brightness: Brightness.light,
|
||||||
return ThemeData(primarySwatch: Colors.orange);
|
);
|
||||||
case ThemeType.blue:
|
return ThemeData.from(
|
||||||
return ThemeData(primarySwatch: Colors.blue);
|
colorScheme: colorScheme,
|
||||||
case ThemeType.violet:
|
useMaterial3: true,
|
||||||
default:
|
textTheme: GoogleFonts.rubikTextTheme(),
|
||||||
return ThemeData(primarySwatch: Colors.deepPurple);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static ThemeData getDarkTheme(ThemeType type) {
|
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,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Color _getSeedColor(ThemeType type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ThemeType.green:
|
case ThemeType.green:
|
||||||
return ThemeData.dark().copyWith(primaryColor: Colors.green);
|
return Colors.green;
|
||||||
case ThemeType.orange:
|
case ThemeType.orange:
|
||||||
return ThemeData.dark().copyWith(primaryColor: Colors.orange);
|
return Colors.orange;
|
||||||
case ThemeType.blue:
|
case ThemeType.blue:
|
||||||
return ThemeData.dark().copyWith(primaryColor: Colors.blue);
|
return Colors.blue;
|
||||||
case ThemeType.violet:
|
case ThemeType.violet:
|
||||||
default:
|
return Colors.deepPurple;
|
||||||
return ThemeData.dark().copyWith(primaryColor: Colors.deepPurple);
|
case ThemeType.yellow:
|
||||||
|
return Colors.yellow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,7 +11,7 @@ class NetworkException extends AppException {
|
|||||||
NetworkException(super.message);
|
NetworkException(super.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
class AuthException implements Exception{
|
class AuthException implements Exception {
|
||||||
final String message;
|
final String message;
|
||||||
AuthException(this.message);
|
AuthException(this.message);
|
||||||
|
|
||||||
|
|||||||
@@ -1,47 +1,61 @@
|
|||||||
|
|
||||||
|
|
||||||
// ignore_for_file: non_constant_identifier_names
|
|
||||||
|
|
||||||
class Beneficiary {
|
class Beneficiary {
|
||||||
final String accountNo;
|
final String accountNo;
|
||||||
final String accountType;
|
final String accountType;
|
||||||
final String name;
|
final String name;
|
||||||
|
final DateTime? createdAt;
|
||||||
final String ifscCode;
|
final String ifscCode;
|
||||||
final String? bankName;
|
final String? bankName;
|
||||||
final String? branchName;
|
final String? branchName;
|
||||||
|
final String? tpin;
|
||||||
|
|
||||||
Beneficiary({
|
Beneficiary({
|
||||||
required this.accountNo,
|
required this.accountNo,
|
||||||
required this.accountType,
|
required this.accountType,
|
||||||
required this.name,
|
required this.name,
|
||||||
|
this.createdAt,
|
||||||
required this.ifscCode,
|
required this.ifscCode,
|
||||||
this.bankName,
|
this.bankName,
|
||||||
this.branchName,
|
this.branchName,
|
||||||
|
this.tpin,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory Beneficiary.fromJson(Map<String, dynamic> json) {
|
factory Beneficiary.fromJson(Map<String, dynamic> json) {
|
||||||
return Beneficiary(
|
return Beneficiary(
|
||||||
accountNo: json['accountNo'] ?? '',
|
accountNo: json['account_no'] ?? json['accountNo'] ?? '',
|
||||||
accountType: json['accountType'] ?? '',
|
accountType: json['account_type'] ?? json['accountType'] ?? '',
|
||||||
|
createdAt: json['createdAt'] == null
|
||||||
|
? null
|
||||||
|
: DateTime.tryParse(json['createdAt']),
|
||||||
name: json['name'] ?? '',
|
name: json['name'] ?? '',
|
||||||
ifscCode: json['ifscCode'] ?? '',
|
ifscCode: json['ifsc_code'] ?? json['ifscCode'] ?? '',
|
||||||
bankName: json['bankName'] ?? '',
|
bankName: json['bank_name'] ?? json['bankName'] ?? '',
|
||||||
branchName: json['branchName'] ?? '',
|
branchName: json['branch_name'] ?? json['branchName'] ?? '',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
return {
|
final Map<String, dynamic> json = {
|
||||||
'accountNo': accountNo,
|
'accountNo': accountNo,
|
||||||
'accountType': accountType,
|
'accountType': accountType,
|
||||||
'name': name,
|
'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) {
|
static List<Beneficiary> listFromJson(List<dynamic> jsonList) {
|
||||||
final beneficiaryList = jsonList.map((beneficiary) => Beneficiary.fromJson(beneficiary)).toList();
|
final beneficiaryList = jsonList
|
||||||
print(beneficiaryList);
|
.map((beneficiary) => Beneficiary.fromJson(beneficiary))
|
||||||
|
.toList();
|
||||||
return beneficiaryList;
|
return beneficiaryList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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 ifscCode;
|
||||||
final String bankName;
|
final String bankName;
|
||||||
final String branchName;
|
final String branchName;
|
||||||
|
|
||||||
ifsc({
|
Ifsc({
|
||||||
required this.ifscCode,
|
required this.ifscCode,
|
||||||
required this.bankName,
|
required this.bankName,
|
||||||
required this.branchName,
|
required this.branchName,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory ifsc.fromJson(Map<String, dynamic> json) {
|
factory Ifsc.fromJson(Map<String, dynamic> json) {
|
||||||
return ifsc(
|
return Ifsc(
|
||||||
ifscCode: json['ifsc_code'] ?? '',
|
ifscCode: json['ifsc_code'] ?? '',
|
||||||
bankName: json['bank_name'] ?? '',
|
bankName: json['bank_name'] ?? '',
|
||||||
branchName: json['branch_name'] ?? '',
|
branchName: json['branch_name'] ?? '',
|
||||||
|
|||||||
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? currency;
|
||||||
final String? errorMessage;
|
final String? errorMessage;
|
||||||
final String? errorCode;
|
final String? errorCode;
|
||||||
|
final String? utr;
|
||||||
|
|
||||||
PaymentResponse({
|
PaymentResponse({
|
||||||
required this.isSuccess,
|
required this.isSuccess,
|
||||||
@@ -15,5 +16,6 @@ class PaymentResponse {
|
|||||||
this.currency,
|
this.currency,
|
||||||
this.errorMessage,
|
this.errorMessage,
|
||||||
this.errorCode,
|
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? date;
|
||||||
final String? amount;
|
final String? amount;
|
||||||
final String? type;
|
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() {
|
Map<String, dynamic> toJson() {
|
||||||
return {
|
return {
|
||||||
'id': id,
|
'id': id,
|
||||||
@@ -13,6 +23,8 @@ class Transaction {
|
|||||||
'date': date,
|
'date': date,
|
||||||
'amount': amount,
|
'amount': amount,
|
||||||
'type': type,
|
'type': type,
|
||||||
|
'balance': balance,
|
||||||
|
'balanceType': balanceType
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,6 +35,7 @@ class Transaction {
|
|||||||
date: json['date'] as String?,
|
date: json['date'] as String?,
|
||||||
amount: json['amount'] as String?,
|
amount: json['amount'] as String?,
|
||||||
type: json['type'] 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 toAccountType;
|
||||||
final String amount;
|
final String amount;
|
||||||
String? tpin;
|
String? tpin;
|
||||||
|
String? remarks;
|
||||||
|
|
||||||
Transfer({
|
Transfer({
|
||||||
required this.fromAccount,
|
required this.fromAccount,
|
||||||
@@ -11,6 +12,7 @@ class Transfer {
|
|||||||
required this.toAccountType,
|
required this.toAccountType,
|
||||||
required this.amount,
|
required this.amount,
|
||||||
this.tpin,
|
this.tpin,
|
||||||
|
this.remarks,
|
||||||
});
|
});
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
@@ -20,6 +22,7 @@ class Transfer {
|
|||||||
'toAccountType': toAccountType,
|
'toAccountType': toAccountType,
|
||||||
'amount': amount,
|
'amount': amount,
|
||||||
'tpin': tpin,
|
'tpin': tpin,
|
||||||
|
'remarks': remarks,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,12 +13,15 @@ class AuthRepository {
|
|||||||
|
|
||||||
static const _accessTokenKey = 'access_token';
|
static const _accessTokenKey = 'access_token';
|
||||||
static const _tokenExpiryKey = 'token_expiry';
|
static const _tokenExpiryKey = 'token_expiry';
|
||||||
|
static const _tncKey = 'tnc';
|
||||||
|
|
||||||
AuthRepository(this._authService, this._userService, this._secureStorage);
|
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
|
// 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);
|
final authToken = await _authService.login(credentials);
|
||||||
|
|
||||||
// Save token securely
|
// Save token securely
|
||||||
@@ -26,7 +29,7 @@ class AuthRepository {
|
|||||||
|
|
||||||
// Get and save user profile
|
// Get and save user profile
|
||||||
final users = await _userService.getUserDetails();
|
final users = await _userService.getUserDetails();
|
||||||
return users;
|
return (users, authToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> isLoggedIn() async {
|
Future<bool> isLoggedIn() async {
|
||||||
@@ -44,19 +47,40 @@ class AuthRepository {
|
|||||||
// Private helper methods
|
// Private helper methods
|
||||||
Future<void> _saveAuthToken(AuthToken token) async {
|
Future<void> _saveAuthToken(AuthToken token) async {
|
||||||
await _secureStorage.write(_accessTokenKey, token.accessToken);
|
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 {
|
Future<AuthToken?> _getAuthToken() async {
|
||||||
final accessToken = await _secureStorage.read(_accessTokenKey);
|
final accessToken = await _secureStorage.read(_accessTokenKey);
|
||||||
final expiryString = await _secureStorage.read(_tokenExpiryKey);
|
final expiryString = await _secureStorage.read(_tokenExpiryKey);
|
||||||
|
final tncString = await _secureStorage.read(_tncKey);
|
||||||
|
|
||||||
if (accessToken != null && expiryString != null) {
|
if (accessToken != null && expiryString != null) {
|
||||||
return AuthToken(
|
final authToken = AuthToken(
|
||||||
accessToken: accessToken,
|
accessToken: accessToken,
|
||||||
expiresAt: DateTime.parse(expiryString),
|
expiresAt: DateTime.parse(expiryString),
|
||||||
|
tnc:
|
||||||
|
tncString == 'true', // Parse 'true' string to true, otherwise false
|
||||||
);
|
);
|
||||||
|
return authToken;
|
||||||
}
|
}
|
||||||
return null;
|
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:dio/dio.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
import 'package:kmobile/data/models/transaction.dart';
|
import 'package:kmobile/data/models/transaction.dart';
|
||||||
|
|
||||||
abstract class TransactionRepository {
|
abstract class TransactionRepository {
|
||||||
Future<List<Transaction>> fetchTransactions(String accountNo);
|
Future<List<Transaction>> fetchTransactions(String accountNo,
|
||||||
|
{DateTime? fromDate, DateTime? toDate});
|
||||||
}
|
}
|
||||||
|
|
||||||
class TransactionRepositoryImpl implements TransactionRepository {
|
class TransactionRepositoryImpl implements TransactionRepository {
|
||||||
@@ -10,9 +12,21 @@ class TransactionRepositoryImpl implements TransactionRepository {
|
|||||||
TransactionRepositoryImpl(this._dio);
|
TransactionRepositoryImpl(this._dio);
|
||||||
|
|
||||||
@override
|
@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) {
|
if (resp.statusCode != 200) {
|
||||||
throw Exception(
|
throw Exception(
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import 'package:kmobile/data/models/transfer.dart';
|
import 'package:kmobile/data/models/transfer.dart';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
|
|
||||||
|
|
||||||
abstract class TransferRepository {
|
abstract class TransferRepository {
|
||||||
Future<TransferResponse> transfer(Transfer transfer);
|
Future<TransferResponse> transfer(Transfer transfer);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
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:get_it/get_it.dart';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:kmobile/api/services/beneficiary_service.dart';
|
import 'package:kmobile/api/services/beneficiary_service.dart';
|
||||||
@@ -5,20 +10,21 @@ import 'package:kmobile/api/services/payment_service.dart';
|
|||||||
import 'package:kmobile/api/services/user_service.dart';
|
import 'package:kmobile/api/services/user_service.dart';
|
||||||
import 'package:kmobile/data/repositories/transaction_repository.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_cubit.dart';
|
||||||
|
import 'package:kmobile/features/auth/controllers/theme_mode_cubit.dart';
|
||||||
import '../api/services/auth_service.dart';
|
import '../api/services/auth_service.dart';
|
||||||
import '../api/interceptors/auth_interceptor.dart';
|
import '../api/interceptors/auth_interceptor.dart';
|
||||||
|
import '../api/services/change_password_service.dart';
|
||||||
import '../data/repositories/auth_repository.dart';
|
import '../data/repositories/auth_repository.dart';
|
||||||
import '../features/auth/controllers/auth_cubit.dart';
|
import '../features/auth/controllers/auth_cubit.dart';
|
||||||
import '../security/secure_storage.dart';
|
import '../security/secure_storage.dart';
|
||||||
|
|
||||||
|
|
||||||
final getIt = GetIt.instance;
|
final getIt = GetIt.instance;
|
||||||
|
|
||||||
Future<void> setupDependencies() async {
|
Future<void> setupDependencies() async {
|
||||||
|
|
||||||
//getIt.registerLazySingleton<ThemeController>(() => ThemeController());
|
//getIt.registerLazySingleton<ThemeController>(() => ThemeController());
|
||||||
//getIt.registerLazySingleton<ThemeModeController>(() => ThemeModeController());
|
//getIt.registerLazySingleton<ThemeModeController>(() => ThemeModeController());
|
||||||
getIt.registerSingleton<ThemeCubit>( ThemeCubit());
|
getIt.registerSingleton<ThemeCubit>(ThemeCubit());
|
||||||
|
getIt.registerSingleton<ThemeModeCubit>(ThemeModeCubit());
|
||||||
|
|
||||||
// Register Dio client
|
// Register Dio client
|
||||||
getIt.registerSingleton<Dio>(_createDioClient());
|
getIt.registerSingleton<Dio>(_createDioClient());
|
||||||
@@ -42,6 +48,14 @@ Future<void> setupDependencies() async {
|
|||||||
|
|
||||||
getIt.registerSingleton<PaymentService>(PaymentService(getIt<Dio>()));
|
getIt.registerSingleton<PaymentService>(PaymentService(getIt<Dio>()));
|
||||||
getIt.registerSingleton<BeneficiaryService>(BeneficiaryService(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
|
// Add auth interceptor after repository is available
|
||||||
getIt<Dio>().interceptors.add(
|
getIt<Dio>().interceptors.add(
|
||||||
@@ -49,22 +63,23 @@ Future<void> setupDependencies() async {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Register controllers/cubits
|
// Register controllers/cubits
|
||||||
getIt.registerFactory<AuthCubit>(
|
getIt.registerFactory<AuthCubit>(() => AuthCubit(
|
||||||
() => AuthCubit(getIt<AuthRepository>(), getIt<UserService>()));
|
getIt<AuthRepository>(), getIt<UserService>(), getIt<SecureStorage>()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Dio _createDioClient() {
|
Dio _createDioClient() {
|
||||||
final dio = Dio(
|
final dio = Dio(
|
||||||
BaseOptions(
|
BaseOptions(
|
||||||
baseUrl:
|
baseUrl:
|
||||||
//'http://lb-test-mobile-banking-app-192209417.ap-south-1.elb.amazonaws.com:8080',
|
// 'http://lb-test-mobile-banking-app-192209417.ap-south-1.elb.amazonaws.com:8080', //test
|
||||||
'http://localhost:8081',
|
//'http://lb-kccb-mobile-banking-app-848675342.ap-south-1.elb.amazonaws.com', //prod
|
||||||
connectTimeout: const Duration(seconds: 5),
|
'https://kccbmbnk.net', //prod small
|
||||||
receiveTimeout: const Duration(seconds: 3),
|
connectTimeout: const Duration(seconds: 60),
|
||||||
|
receiveTimeout: const Duration(seconds: 60),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
|
'X-Login-Type': 'MB',
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_svg/svg.dart';
|
|
||||||
import 'package:kmobile/data/models/user.dart';
|
import 'package:kmobile/data/models/user.dart';
|
||||||
import 'package:material_symbols_icons/material_symbols_icons.dart';
|
|
||||||
import '../../../l10n/app_localizations.dart';
|
import '../../../l10n/app_localizations.dart';
|
||||||
|
|
||||||
class AccountInfoScreen extends StatefulWidget {
|
class AccountInfoScreen extends StatefulWidget {
|
||||||
@@ -32,45 +30,21 @@ class _AccountInfoScreen extends State<AccountInfoScreen> {
|
|||||||
int selectedIndex = widget.selectedIndex;
|
int selectedIndex = widget.selectedIndex;
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
leading: IconButton(
|
title: Text(AppLocalizations.of(context)
|
||||||
icon: const Icon(Symbols.arrow_back_ios_new),
|
.accountInfo
|
||||||
onPressed: () {
|
.replaceFirst(RegExp('\n'), '')),
|
||||||
Navigator.pop(context);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
title: Text(
|
body: Stack(
|
||||||
AppLocalizations.of(context).accountInfo,
|
children: [
|
||||||
style: const TextStyle(
|
ListView(
|
||||||
color: Colors.black,
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
centerTitle: false,
|
|
||||||
actions: [
|
|
||||||
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,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
body: ListView(
|
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.all(16.0),
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
AppLocalizations.of(context).accountNumber,
|
AppLocalizations.of(context).accountNumber,
|
||||||
style: const TextStyle(fontWeight: FontWeight.w500, fontSize: 14),
|
style:
|
||||||
|
const TextStyle(fontWeight: FontWeight.w500, fontSize: 14),
|
||||||
),
|
),
|
||||||
|
|
||||||
/// Dropdown to change account
|
|
||||||
DropdownButton<User>(
|
DropdownButton<User>(
|
||||||
value: selectedUser,
|
value: selectedUser,
|
||||||
onChanged: (User? newUser) {
|
onChanged: (User? newUser) {
|
||||||
@@ -88,12 +62,6 @@ class _AccountInfoScreen extends State<AccountInfoScreen> {
|
|||||||
}).toList(),
|
}).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(
|
InfoRow(
|
||||||
title: AppLocalizations.of(context).customerNumber,
|
title: AppLocalizations.of(context).customerNumber,
|
||||||
value: selectedUser.cifNumber ?? 'N/A',
|
value: selectedUser.cifNumber ?? 'N/A',
|
||||||
@@ -124,6 +92,22 @@ class _AccountInfoScreen extends State<AccountInfoScreen> {
|
|||||||
: const SizedBox.shrink(),
|
: const SizedBox.shrink(),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
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
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -136,6 +120,7 @@ class InfoRow extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
return Container(
|
return Container(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
margin: const EdgeInsets.symmetric(vertical: 8),
|
margin: const EdgeInsets.symmetric(vertical: 8),
|
||||||
@@ -144,16 +129,16 @@ class InfoRow extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
title,
|
title,
|
||||||
style: const TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 15,
|
fontSize: 15,
|
||||||
fontWeight: FontWeight.w500,
|
fontWeight: FontWeight.w500,
|
||||||
color: Colors.black87,
|
color: theme.colorScheme.onSurfaceVariant,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 3),
|
const SizedBox(height: 3),
|
||||||
Text(
|
Text(
|
||||||
value,
|
value,
|
||||||
style: const TextStyle(fontSize: 16, color: Colors.black),
|
style: TextStyle(fontSize: 16, color: theme.colorScheme.onSurface),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,15 +1,29 @@
|
|||||||
|
import 'dart:io';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_svg/svg.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:material_symbols_icons/material_symbols_icons.dart';
|
import 'package:material_symbols_icons/material_symbols_icons.dart';
|
||||||
import 'package:shimmer/shimmer.dart';
|
import 'package:shimmer/shimmer.dart';
|
||||||
import 'package:kmobile/data/models/transaction.dart';
|
import 'package:kmobile/data/models/transaction.dart';
|
||||||
import 'package:kmobile/data/repositories/transaction_repository.dart';
|
import 'package:kmobile/data/repositories/transaction_repository.dart';
|
||||||
import 'package:kmobile/di/injection.dart';
|
import 'package:kmobile/di/injection.dart';
|
||||||
import '../../../l10n/app_localizations.dart';
|
import '../../../l10n/app_localizations.dart';
|
||||||
|
import 'transaction_details_screen.dart';
|
||||||
|
import 'package:pdf/widgets.dart' as pw;
|
||||||
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
|
import 'package:device_info_plus/device_info_plus.dart';
|
||||||
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
import 'package:share_plus/share_plus.dart';
|
||||||
|
|
||||||
class AccountStatementScreen extends StatefulWidget {
|
class AccountStatementScreen extends StatefulWidget {
|
||||||
final String accountNo;
|
final String accountNo;
|
||||||
const AccountStatementScreen({super.key, required this.accountNo});
|
final String balance;
|
||||||
|
final String accountType;
|
||||||
|
const AccountStatementScreen({
|
||||||
|
super.key,
|
||||||
|
required this.accountNo,
|
||||||
|
required this.balance,
|
||||||
|
required this.accountType,
|
||||||
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<AccountStatementScreen> createState() => _AccountStatementScreen();
|
State<AccountStatementScreen> createState() => _AccountStatementScreen();
|
||||||
@@ -22,6 +36,7 @@ class _AccountStatementScreen extends State<AccountStatementScreen> {
|
|||||||
List<Transaction> _transactions = [];
|
List<Transaction> _transactions = [];
|
||||||
final _minAmountController = TextEditingController();
|
final _minAmountController = TextEditingController();
|
||||||
final _maxAmountController = TextEditingController();
|
final _maxAmountController = TextEditingController();
|
||||||
|
//Future<Map<String, dynamic>?>? accountStatementsFuture;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -36,7 +51,11 @@ class _AccountStatementScreen extends State<AccountStatementScreen> {
|
|||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
final repo = getIt<TransactionRepository>();
|
final repo = getIt<TransactionRepository>();
|
||||||
final txs = await repo.fetchTransactions(widget.accountNo);
|
final txs = await repo.fetchTransactions(
|
||||||
|
widget.accountNo,
|
||||||
|
fromDate: fromDate,
|
||||||
|
toDate: toDate,
|
||||||
|
);
|
||||||
setState(() => _transactions = txs);
|
setState(() => _transactions = txs);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
@@ -109,32 +128,14 @@ class _AccountStatementScreen extends State<AccountStatementScreen> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
leading: IconButton(
|
|
||||||
icon: const Icon(Symbols.arrow_back_ios_new),
|
|
||||||
onPressed: () => Navigator.pop(context),
|
|
||||||
),
|
|
||||||
title: Text(
|
title: Text(
|
||||||
AppLocalizations.of(context).accountStatement,
|
AppLocalizations.of(context).accountStatement,
|
||||||
style: const TextStyle(color: Colors.black, fontWeight: FontWeight.w500),
|
|
||||||
),
|
),
|
||||||
centerTitle: false,
|
centerTitle: false,
|
||||||
actions: [
|
),
|
||||||
|
body: Stack(
|
||||||
|
children: [
|
||||||
Padding(
|
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,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
body: Padding(
|
|
||||||
padding: const EdgeInsets.all(12.0),
|
padding: const EdgeInsets.all(12.0),
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
@@ -144,11 +145,25 @@ class _AccountStatementScreen extends State<AccountStatementScreen> {
|
|||||||
Text(
|
Text(
|
||||||
"${AppLocalizations.of(context).accountNumber}: ",
|
"${AppLocalizations.of(context).accountNumber}: ",
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 19,
|
fontSize: 17,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Text(widget.accountNo, style: const TextStyle(fontSize: 17)),
|
Text(widget.accountNo,
|
||||||
|
style: const TextStyle(fontSize: 17)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 15),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
"${AppLocalizations.of(context).availableBalance}: ",
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 17,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Text(' ₹ ${widget.balance}',
|
||||||
|
style: const TextStyle(fontSize: 17)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 15),
|
const SizedBox(height: 15),
|
||||||
@@ -181,56 +196,29 @@ class _AccountStatementScreen extends State<AccountStatementScreen> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: TextFormField(
|
|
||||||
controller: _minAmountController,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
labelText: AppLocalizations.of(context).minAmount,
|
|
||||||
border: const OutlineInputBorder(),
|
|
||||||
isDense: true,
|
|
||||||
filled: true,
|
|
||||||
fillColor: Theme.of(context).scaffoldBackgroundColor,
|
|
||||||
),
|
|
||||||
keyboardType: TextInputType.number,
|
|
||||||
textInputAction: TextInputAction.next,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Expanded(
|
|
||||||
child: TextFormField(
|
|
||||||
controller: _maxAmountController,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
labelText: AppLocalizations.of(context).maxAmount,
|
|
||||||
border: const OutlineInputBorder(),
|
|
||||||
isDense: true,
|
|
||||||
filled: true,
|
|
||||||
fillColor: Theme.of(context).scaffoldBackgroundColor,
|
|
||||||
),
|
|
||||||
keyboardType: TextInputType.number,
|
|
||||||
textInputAction: TextInputAction.done,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: 70,
|
width: double.infinity,
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed: _loadTransactions,
|
onPressed: _loadTransactions,
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
backgroundColor: Theme.of(context).primaryColor,
|
backgroundColor:
|
||||||
|
Theme.of(context).colorScheme.primaryContainer,
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||||
),
|
),
|
||||||
child: Icon(
|
child: Text(
|
||||||
Symbols.arrow_forward,
|
AppLocalizations.of(context).search,
|
||||||
color: Theme.of(context).scaffoldBackgroundColor,
|
style: TextStyle(
|
||||||
size: 30,
|
color: Theme.of(context).colorScheme.onPrimaryContainer,
|
||||||
|
fontSize: 16,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 35),
|
const SizedBox(height: 15),
|
||||||
if (!_txLoading && _transactions.isNotEmpty)
|
if (!_txLoading &&
|
||||||
|
_transactions.isNotEmpty &&
|
||||||
|
fromDate == null &&
|
||||||
|
toDate == null)
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(bottom: 12.0),
|
padding: const EdgeInsets.only(bottom: 12.0),
|
||||||
child: Text(
|
child: Text(
|
||||||
@@ -238,7 +226,7 @@ class _AccountStatementScreen extends State<AccountStatementScreen> {
|
|||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
fontWeight: FontWeight.w500,
|
fontWeight: FontWeight.w500,
|
||||||
color: Colors.grey[700],
|
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -252,7 +240,8 @@ class _AccountStatementScreen extends State<AccountStatementScreen> {
|
|||||||
highlightColor: Colors.grey[100]!,
|
highlightColor: Colors.grey[100]!,
|
||||||
child: CircleAvatar(
|
child: CircleAvatar(
|
||||||
radius: 12,
|
radius: 12,
|
||||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
backgroundColor:
|
||||||
|
Theme.of(context).scaffoldBackgroundColor,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
title: Shimmer.fromColors(
|
title: Shimmer.fromColors(
|
||||||
@@ -261,7 +250,8 @@ class _AccountStatementScreen extends State<AccountStatementScreen> {
|
|||||||
child: Container(
|
child: Container(
|
||||||
height: 10,
|
height: 10,
|
||||||
width: 100,
|
width: 100,
|
||||||
color: Theme.of(context).scaffoldBackgroundColor,
|
color:
|
||||||
|
Theme.of(context).scaffoldBackgroundColor,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
subtitle: Shimmer.fromColors(
|
subtitle: Shimmer.fromColors(
|
||||||
@@ -270,7 +260,8 @@ class _AccountStatementScreen extends State<AccountStatementScreen> {
|
|||||||
child: Container(
|
child: Container(
|
||||||
height: 8,
|
height: 8,
|
||||||
width: 60,
|
width: 60,
|
||||||
color: Theme.of(context).scaffoldBackgroundColor,
|
color:
|
||||||
|
Theme.of(context).scaffoldBackgroundColor,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -280,10 +271,12 @@ class _AccountStatementScreen extends State<AccountStatementScreen> {
|
|||||||
child: Text(
|
child: Text(
|
||||||
AppLocalizations.of(context).noTransactions,
|
AppLocalizations.of(context).noTransactions,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 16, color: Colors.grey[600]),
|
fontSize: 16,
|
||||||
),
|
color:
|
||||||
|
Theme.of(context).colorScheme.onSurface,
|
||||||
|
)),
|
||||||
)
|
)
|
||||||
: ListView.builder(
|
: ListView.separated(
|
||||||
itemCount: _transactions.length,
|
itemCount: _transactions.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final tx = _transactions[index];
|
final tx = _transactions[index];
|
||||||
@@ -292,40 +285,265 @@ class _AccountStatementScreen extends State<AccountStatementScreen> {
|
|||||||
tx.type == 'CR'
|
tx.type == 'CR'
|
||||||
? Symbols.call_received
|
? Symbols.call_received
|
||||||
: Symbols.call_made,
|
: Symbols.call_made,
|
||||||
color:
|
color: tx.type == 'CR'
|
||||||
tx.type == 'CR' ? Colors.green : Colors.red,
|
? Colors.green
|
||||||
|
: Theme.of(context).colorScheme.error,
|
||||||
),
|
),
|
||||||
title: Text(
|
title: Text(
|
||||||
tx.name != null
|
tx.date ?? '',
|
||||||
? (tx.name!.length > 18
|
style: const TextStyle(fontSize: 15),
|
||||||
? tx.name!.substring(0, 20)
|
|
||||||
: tx.name!)
|
|
||||||
: '',
|
|
||||||
style: const TextStyle(fontSize: 14),
|
|
||||||
),
|
),
|
||||||
subtitle: Text(
|
subtitle: Text(
|
||||||
tx.date ?? '',
|
tx.name != null
|
||||||
|
? (tx.name!.length > 22
|
||||||
|
? tx.name!.substring(0, 22)
|
||||||
|
: tx.name!)
|
||||||
|
: '',
|
||||||
style: const TextStyle(fontSize: 12),
|
style: const TextStyle(fontSize: 12),
|
||||||
),
|
),
|
||||||
trailing: Text(
|
trailing: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.end,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
"₹${tx.amount}",
|
"₹${tx.amount}",
|
||||||
style: const TextStyle(fontSize: 16),
|
style: const TextStyle(fontSize: 17),
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
"Bal: ₹${tx.balance}",
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize:
|
||||||
|
12), // Style matches tx.name
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
onTap: () {
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (_) =>
|
||||||
|
TransactionDetailsScreen(
|
||||||
|
transaction: tx),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
separatorBuilder: (context, index) {
|
||||||
|
return const Divider();
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
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
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
floatingActionButton: FloatingActionButton(
|
||||||
|
onPressed: () {
|
||||||
|
_exportToPdf();
|
||||||
|
},
|
||||||
|
child: const Icon(Icons.download),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _exportToPdf() async {
|
||||||
|
// Step 1: Check if there are any transactions to export.
|
||||||
|
if (_transactions.isEmpty) {
|
||||||
|
if (mounted) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(
|
||||||
|
content: Text('No transactions to export.'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var logo = await rootBundle.load('assets/images/logo.png');
|
||||||
|
var rubik = await rootBundle.load("assets/fonts/Rubik-Regular.ttf");
|
||||||
|
final pdf = pw.Document();
|
||||||
|
|
||||||
|
pdf.addPage(pw.MultiPage(
|
||||||
|
margin: const pw.EdgeInsets.all(20),
|
||||||
|
build: (pw.Context context) {
|
||||||
|
return [
|
||||||
|
pw.Row(
|
||||||
|
mainAxisAlignment: pw.MainAxisAlignment.start,
|
||||||
|
crossAxisAlignment: pw.CrossAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
pw.Image(pw.MemoryImage(logo.buffer.asUint8List()),
|
||||||
|
width: 50, height: 50),
|
||||||
|
pw.SizedBox(width: 20),
|
||||||
|
pw.Text('Account Statement - KCCB',
|
||||||
|
style: pw.TextStyle(
|
||||||
|
fontSize: 24, fontWeight: pw.FontWeight.bold)),
|
||||||
|
]),
|
||||||
|
pw.SizedBox(height: 20),
|
||||||
|
pw.Row(
|
||||||
|
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
pw.Text('Account Number: ${widget.accountNo}',
|
||||||
|
style:
|
||||||
|
pw.TextStyle(font: pw.Font.ttf(rubik), fontSize: 15)),
|
||||||
|
pw.Text('Account Type: ${widget.accountType}',
|
||||||
|
style: pw.TextStyle(
|
||||||
|
fontSize: 15,
|
||||||
|
font: pw.Font.ttf(rubik),
|
||||||
|
)),
|
||||||
|
]),
|
||||||
|
pw.SizedBox(height: 20),
|
||||||
|
pw.Table(border: pw.TableBorder.all(), columnWidths: {
|
||||||
|
0: const pw.FractionColumnWidth(0.2),
|
||||||
|
1: const pw.FractionColumnWidth(0.45),
|
||||||
|
2: const pw.FractionColumnWidth(0.15),
|
||||||
|
3: const pw.FractionColumnWidth(0.20),
|
||||||
|
}, children: [
|
||||||
|
pw.TableRow(
|
||||||
|
children: [
|
||||||
|
pw.Padding(
|
||||||
|
padding: const pw.EdgeInsets.all(4),
|
||||||
|
child: pw.Text('Date')),
|
||||||
|
pw.Padding(
|
||||||
|
padding: const pw.EdgeInsets.all(4),
|
||||||
|
child: pw.Text('Description', softWrap: true)),
|
||||||
|
pw.Padding(
|
||||||
|
padding: const pw.EdgeInsets.all(4),
|
||||||
|
child: pw.Text('Amount')),
|
||||||
|
pw.Padding(
|
||||||
|
padding: const pw.EdgeInsets.all(4),
|
||||||
|
child: pw.Text('Balance')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
..._transactions.map<pw.TableRow>((tx) {
|
||||||
|
return pw.TableRow(children: [
|
||||||
|
pw.Padding(
|
||||||
|
padding: const pw.EdgeInsets.all(10),
|
||||||
|
child: pw.Text(tx.date ?? '',
|
||||||
|
style: pw.TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
font: pw.Font.ttf(rubik),
|
||||||
|
))),
|
||||||
|
pw.Padding(
|
||||||
|
padding: const pw.EdgeInsets.all(10),
|
||||||
|
child: pw.Text(tx.name ?? '',
|
||||||
|
style: pw.TextStyle(
|
||||||
|
fontSize: 12, font: pw.Font.ttf(rubik)))),
|
||||||
|
pw.Padding(
|
||||||
|
padding: const pw.EdgeInsets.all(10),
|
||||||
|
child: pw.Text("₹${tx.amount} ${tx.type}",
|
||||||
|
style: pw.TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
font: pw.Font.ttf(rubik),
|
||||||
|
))),
|
||||||
|
pw.Padding(
|
||||||
|
padding: const pw.EdgeInsets.all(10),
|
||||||
|
child: pw.Text("₹${tx.balance} ${tx.balanceType}",
|
||||||
|
style: pw.TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
font: pw.Font.ttf(rubik),
|
||||||
|
))),
|
||||||
|
]);
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
];
|
||||||
|
},
|
||||||
|
footer: (pw.Context context) {
|
||||||
|
return pw.Container(
|
||||||
|
alignment: pw.Alignment.centerRight,
|
||||||
|
margin: const pw.EdgeInsets.only(top: 10),
|
||||||
|
child: pw.Text(
|
||||||
|
'Kangra Central Co-Operative Bank Pvt Ltd. ©. All rights reserved.',
|
||||||
|
style: pw.TextStyle(
|
||||||
|
font: pw.Font.ttf(rubik),
|
||||||
|
fontSize: 8,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}));
|
||||||
|
|
||||||
|
//Logic For all platforms
|
||||||
|
try {
|
||||||
|
final Uint8List pdfBytes = await pdf.save();
|
||||||
|
final String timestamp = DateTime.now().millisecondsSinceEpoch.toString();
|
||||||
|
final String fileName = 'account_statement_$timestamp.pdf';
|
||||||
|
|
||||||
|
// For Android
|
||||||
|
if (Platform.isAndroid) {
|
||||||
|
final androidInfo = await DeviceInfoPlugin().androidInfo;
|
||||||
|
if (androidInfo.version.sdkInt < 29) {
|
||||||
|
final status = await Permission.storage.status;
|
||||||
|
if (status.isDenied) {
|
||||||
|
final result = await Permission.storage.request();
|
||||||
|
if (result.isDenied) {
|
||||||
|
if (mounted) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(
|
||||||
|
content: Text('Storage permission is required to save PDF'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final directory = Directory('/storage/emulated/0/Download');
|
||||||
|
final file = File('${directory.path}/$fileName');
|
||||||
|
await file.writeAsBytes(pdfBytes);
|
||||||
|
|
||||||
|
if (mounted) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text('PDF saved to: ${file.path}'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Add for IOS
|
||||||
|
else if (Platform.isIOS) {
|
||||||
|
// On iOS, we save to a temporary directory and then open the share sheet.
|
||||||
|
final tempDir = await getTemporaryDirectory();
|
||||||
|
final file = await File('${tempDir.path}/$fileName').create();
|
||||||
|
await file.writeAsBytes(pdfBytes);
|
||||||
|
|
||||||
|
// Use share_plus to open the iOS share dialog
|
||||||
|
await Share.shareXFiles(
|
||||||
|
[XFile(file.path)],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
if (mounted) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text('Error saving PDF: $e'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Widget buildDateBox(String label, DateTime? date) {
|
Widget buildDateBox(String label, DateTime? date) {
|
||||||
return Container(
|
return Container(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 16),
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 16),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
border: Border.all(color: Colors.grey),
|
border:
|
||||||
|
Border.all(color: Theme.of(context).colorScheme.onSurfaceVariant),
|
||||||
borderRadius: BorderRadius.circular(6),
|
borderRadius: BorderRadius.circular(6),
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
@@ -335,7 +553,9 @@ class _AccountStatementScreen extends State<AccountStatementScreen> {
|
|||||||
date != null ? _formatDate(date) : label,
|
date != null ? _formatDate(date) : label,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
color: date != null ? Colors.black : Colors.grey,
|
color: date != null
|
||||||
|
? Theme.of(context).colorScheme.onSurface
|
||||||
|
: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const Icon(Icons.arrow_drop_down),
|
const Icon(Icons.arrow_drop_down),
|
||||||
|
|||||||
133
lib/features/accounts/screens/transaction_details_screen.dart
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
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 ? Colors.green : Colors.red,
|
||||||
|
size: 28,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
// Date centered
|
||||||
|
Text(
|
||||||
|
transaction.date ?? "",
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
color: Colors.grey,
|
||||||
|
),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const Divider(),
|
||||||
|
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:bloc/bloc.dart';
|
||||||
import 'package:kmobile/api/services/user_service.dart';
|
import 'package:kmobile/api/services/user_service.dart';
|
||||||
import 'package:kmobile/core/errors/exceptions.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 '../../../data/repositories/auth_repository.dart';
|
||||||
import 'auth_state.dart';
|
import 'auth_state.dart';
|
||||||
|
|
||||||
class AuthCubit extends Cubit<AuthState> {
|
class AuthCubit extends Cubit<AuthState> {
|
||||||
final AuthRepository _authRepository;
|
final AuthRepository _authRepository;
|
||||||
final UserService _userService;
|
final UserService _userService;
|
||||||
|
final SecureStorage _secureStorage;
|
||||||
|
|
||||||
AuthCubit(this._authRepository, this._userService) : super(AuthInitial()) {
|
AuthCubit(this._authRepository, this._userService, this._secureStorage)
|
||||||
|
: super(AuthInitial()) {
|
||||||
checkAuthStatus();
|
checkAuthStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,22 +34,62 @@ class AuthCubit extends Cubit<AuthState> {
|
|||||||
|
|
||||||
Future<void> refreshUserData() async {
|
Future<void> refreshUserData() async {
|
||||||
try {
|
try {
|
||||||
// emit(AuthLoading());
|
|
||||||
final users = await _userService.getUserDetails();
|
final users = await _userService.getUserDetails();
|
||||||
emit(Authenticated(users));
|
emit(Authenticated(users));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(AuthError('Failed to refresh user data: ${e.toString()}'));
|
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 {
|
Future<void> login(String customerNo, String password) async {
|
||||||
emit(AuthLoading());
|
emit(AuthLoading());
|
||||||
try {
|
try {
|
||||||
final users = await _authRepository.login(customerNo, password);
|
final (users, authToken) =
|
||||||
emit(Authenticated(users));
|
await _authRepository.login(customerNo, password);
|
||||||
|
|
||||||
|
if (authToken.tnc == false) {
|
||||||
|
emit(ShowTncDialog(authToken, users));
|
||||||
|
} else {
|
||||||
|
await _checkMpinAndNavigate(users);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(AuthError(e is AuthException ? e.message : e.toString()));
|
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 '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 {
|
abstract class AuthState extends Equatable {
|
||||||
|
const AuthState();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [];
|
List<Object> get props => [];
|
||||||
}
|
}
|
||||||
|
|
||||||
class AuthInitial extends AuthState {}
|
class AuthInitial extends AuthState {}
|
||||||
@@ -12,20 +15,44 @@ class AuthLoading extends AuthState {}
|
|||||||
|
|
||||||
class Authenticated extends AuthState {
|
class Authenticated extends AuthState {
|
||||||
final List<User> users;
|
final List<User> users;
|
||||||
|
const Authenticated(this.users);
|
||||||
Authenticated(this.users);
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [users];
|
List<Object> get props => [users];
|
||||||
}
|
}
|
||||||
|
|
||||||
class Unauthenticated extends AuthState {}
|
class Unauthenticated extends AuthState {}
|
||||||
|
|
||||||
class AuthError extends AuthState {
|
class AuthError extends AuthState {
|
||||||
final String message;
|
final String message;
|
||||||
|
const AuthError(this.message);
|
||||||
AuthError(this.message);
|
|
||||||
|
|
||||||
@override
|
@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 'dart:developer';
|
||||||
|
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'theme_state.dart';
|
|
||||||
import 'package:kmobile/config/theme_type.dart';
|
import 'package:kmobile/config/theme_type.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
|
import 'theme_state.dart';
|
||||||
|
|
||||||
class ThemeCubit extends Cubit<ThemeState> {
|
class ThemeCubit extends Cubit<ThemeState> {
|
||||||
ThemeCubit(): super(ThemeViolet()) {
|
ThemeCubit() : super(const ThemeState(themeType: ThemeType.violet)) {
|
||||||
loadTheme();
|
loadTheme();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> loadTheme() async {
|
Future<void> loadTheme() async {
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
final themeIndex = prefs.getInt('theme_type') ?? 0;
|
final themeIndex = prefs.getInt('theme_type') ?? 0;
|
||||||
// final isDark = prefs.getBool('is_dark_mode') ?? false;
|
|
||||||
|
|
||||||
final type = ThemeType.values[themeIndex];
|
final type = ThemeType.values[themeIndex];
|
||||||
switch(type) {
|
emit(ThemeState(themeType: type));
|
||||||
case ThemeType.blue:
|
|
||||||
emit(ThemeBlue());
|
|
||||||
case ThemeType.violet:
|
|
||||||
emit(ThemeViolet());
|
|
||||||
default:
|
|
||||||
emit(ThemeViolet());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> changeTheme(ThemeType type) async {
|
Future<void> changeTheme(ThemeType type) async {
|
||||||
|
log("Attempting to change theme...");
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
await prefs.setInt('theme_type', type.index);
|
await prefs.setInt('theme_type', type.index);
|
||||||
log("Mode Change");
|
emit(ThemeState(themeType: type));
|
||||||
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');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
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/theme_type.dart';
|
||||||
import 'package:kmobile/config/themes.dart';
|
import 'package:kmobile/config/themes.dart';
|
||||||
|
|
||||||
|
class ThemeState extends Equatable {
|
||||||
|
final ThemeType themeType;
|
||||||
|
|
||||||
abstract class ThemeState extends Equatable {
|
const ThemeState({required this.themeType});
|
||||||
getThemeData();
|
|
||||||
@override
|
|
||||||
List<Object?> get props => [];
|
|
||||||
}
|
|
||||||
|
|
||||||
class ThemeBlue extends ThemeState {
|
ThemeData getThemeData() {
|
||||||
|
return AppThemes.getLightTheme(themeType);
|
||||||
@override
|
|
||||||
getThemeData() {
|
|
||||||
print('returning blue theme');
|
|
||||||
return AppThemes.getLightTheme(ThemeType.blue);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
class ThemeViolet extends ThemeState {
|
|
||||||
@override
|
@override
|
||||||
getThemeData() {
|
List<Object?> get props => [themeType];
|
||||||
print('returning violet theme');
|
}*/
|
||||||
return AppThemes.getLightTheme(ThemeType.violet);
|
|
||||||
|
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 {
|
class AuthToken extends Equatable {
|
||||||
final String accessToken;
|
final String accessToken;
|
||||||
final DateTime expiresAt;
|
final DateTime expiresAt;
|
||||||
|
final bool tnc;
|
||||||
|
|
||||||
const AuthToken({
|
const AuthToken({
|
||||||
required this.accessToken,
|
required this.accessToken,
|
||||||
required this.expiresAt,
|
required this.expiresAt,
|
||||||
|
required this.tnc,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory AuthToken.fromJson(Map<String, dynamic> json) {
|
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(
|
return AuthToken(
|
||||||
accessToken: json['token'],
|
accessToken: token,
|
||||||
expiresAt: _decodeExpiryFromToken(json['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
|
// Pad the payload if necessary
|
||||||
String normalized = base64Url.normalize(payload);
|
String normalized = base64Url.normalize(payload);
|
||||||
final payloadMap = json.decode(utf8.decode(base64Url.decode(normalized)));
|
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');
|
throw Exception('Invalid payload');
|
||||||
}
|
}
|
||||||
final exp = payloadMap['exp'];
|
final exp = payloadMap['exp'];
|
||||||
@@ -41,8 +57,45 @@ class AuthToken extends Equatable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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);
|
bool get isExpired => DateTime.now().isAfter(expiresAt);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [accessToken, expiresAt];
|
List<Object> get props => [accessToken, expiresAt, tnc];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import '../../../l10n/app_localizations.dart';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_bloc/flutter_bloc.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/features/auth/screens/mpin_screen.dart';
|
||||||
import 'package:kmobile/security/secure_storage.dart';
|
import 'package:kmobile/features/auth/screens/set_password_screen.dart';
|
||||||
import '../../../app.dart';
|
import 'package:kmobile/features/auth/screens/tnc_required_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_cubit.dart';
|
||||||
import '../controllers/auth_state.dart';
|
import '../controllers/auth_state.dart';
|
||||||
|
|
||||||
@@ -22,24 +22,9 @@ class LoginScreenState extends State<LoginScreen>
|
|||||||
final _customerNumberController = TextEditingController();
|
final _customerNumberController = TextEditingController();
|
||||||
final _passwordController = TextEditingController();
|
final _passwordController = TextEditingController();
|
||||||
bool _obscurePassword = true;
|
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
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_logoController.dispose();
|
|
||||||
_customerNumberController.dispose();
|
_customerNumberController.dispose();
|
||||||
_passwordController.dispose();
|
_passwordController.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
@@ -56,43 +41,252 @@ class LoginScreenState extends State<LoginScreen>
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
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(
|
return Scaffold(
|
||||||
// appBar: AppBar(title: const Text('Login')),
|
|
||||||
body: BlocConsumer<AuthCubit, AuthState>(
|
body: BlocConsumer<AuthCubit, AuthState>(
|
||||||
listener: (context, state) async {
|
listener: (context, state) {
|
||||||
if (state is Authenticated) {
|
if (state is ShowTncDialog) {
|
||||||
final storage = getIt<SecureStorage>();
|
showDialog<bool>(
|
||||||
final mpin = await storage.read('mpin');
|
context: context,
|
||||||
if (mpin == null) {
|
barrierDismissible: false,
|
||||||
Navigator.of(context).pushReplacement(
|
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(
|
MaterialPageRoute(
|
||||||
builder: (_) => MPinScreen(
|
builder: (_) => MPinScreen(
|
||||||
mode: MPinMode.set,
|
mode: MPinMode.set,
|
||||||
onCompleted: (_) {
|
onCompleted: (_) {
|
||||||
Navigator.of(
|
// Call the cubit to signal MPIN setup is complete
|
||||||
context,
|
context.read<AuthCubit>().mpinSetupCompleted();
|
||||||
rootNavigator: true,
|
|
||||||
).pushReplacement(
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (_) => const NavigationScaffold(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else {
|
} else if (state is Authenticated) {
|
||||||
Navigator.of(context).pushReplacement(
|
// This is the single source of truth for navigating to the dashboard
|
||||||
|
Navigator.of(context, rootNavigator: true).pushAndRemoveUntil(
|
||||||
MaterialPageRoute(builder: (_) => const NavigationScaffold()),
|
MaterialPageRoute(builder: (_) => const NavigationScaffold()),
|
||||||
|
(route) => false,
|
||||||
);
|
);
|
||||||
}
|
|
||||||
} else if (state is AuthError) {
|
} else if (state is AuthError) {
|
||||||
ScaffoldMessenger.of(
|
if (state.message == 'MIGRATED_USER_HAS_NO_PASSWORD') {
|
||||||
context,
|
Navigator.of(context).push(MaterialPageRoute(
|
||||||
).showSnackBar(SnackBar(content: Text(state.message)));
|
builder: (_) => SetPasswordScreen(
|
||||||
|
customerNo: _customerNumberController.text.trim(),
|
||||||
|
)));
|
||||||
|
} else {
|
||||||
|
ScaffoldMessenger.of(context)
|
||||||
|
.showSnackBar(SnackBar(content: Text(state.message)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
|
// The builder part remains largely the same, focusing on UI display
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.all(24.0),
|
padding: const EdgeInsets.all(24.0),
|
||||||
child: Form(
|
child: Form(
|
||||||
@@ -100,10 +294,7 @@ class LoginScreenState extends State<LoginScreen>
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
// 🔁 Animated Blinking Logo
|
Image.asset(
|
||||||
FadeTransition(
|
|
||||||
opacity: _logoAnimation,
|
|
||||||
child: Image.asset(
|
|
||||||
'assets/images/logo.png',
|
'assets/images/logo.png',
|
||||||
width: 150,
|
width: 150,
|
||||||
height: 150,
|
height: 150,
|
||||||
@@ -115,9 +306,7 @@ class LoginScreenState extends State<LoginScreen>
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
// Title
|
|
||||||
Text(
|
Text(
|
||||||
AppLocalizations.of(context).kccb,
|
AppLocalizations.of(context).kccb,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
@@ -127,21 +316,22 @@ class LoginScreenState extends State<LoginScreen>
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 48),
|
const SizedBox(height: 48),
|
||||||
|
|
||||||
TextFormField(
|
TextFormField(
|
||||||
controller: _customerNumberController,
|
controller: _customerNumberController,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: AppLocalizations.of(context).customerNumber,
|
labelText: AppLocalizations.of(context).customerNumber,
|
||||||
// prefixIcon: Icon(Icons.person),
|
border: const OutlineInputBorder(),
|
||||||
border: OutlineInputBorder(),
|
|
||||||
isDense: true,
|
isDense: true,
|
||||||
filled: true,
|
filled: true,
|
||||||
fillColor: Theme.of(context).scaffoldBackgroundColor,
|
fillColor: Theme.of(context).scaffoldBackgroundColor,
|
||||||
enabledBorder: OutlineInputBorder(
|
enabledBorder: OutlineInputBorder(
|
||||||
borderSide: BorderSide(color: Colors.black),
|
borderSide: BorderSide(
|
||||||
|
color: Theme.of(context).colorScheme.outline),
|
||||||
),
|
),
|
||||||
focusedBorder: OutlineInputBorder(
|
focusedBorder: OutlineInputBorder(
|
||||||
borderSide: BorderSide(color: Colors.black, width: 2),
|
borderSide: BorderSide(
|
||||||
|
color: Theme.of(context).colorScheme.primary,
|
||||||
|
width: 2),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
keyboardType: TextInputType.number,
|
keyboardType: TextInputType.number,
|
||||||
@@ -154,24 +344,25 @@ class LoginScreenState extends State<LoginScreen>
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
// Password
|
|
||||||
TextFormField(
|
TextFormField(
|
||||||
controller: _passwordController,
|
controller: _passwordController,
|
||||||
obscureText: _obscurePassword,
|
obscureText: _obscurePassword,
|
||||||
textInputAction: TextInputAction.done,
|
textInputAction: TextInputAction.done,
|
||||||
onFieldSubmitted: (_) =>
|
onFieldSubmitted: (_) => _submitForm(),
|
||||||
_submitForm(), // ⌨️ Enter key submits
|
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: AppLocalizations.of(context).password,
|
labelText: AppLocalizations.of(context).password,
|
||||||
border: const OutlineInputBorder(),
|
border: const OutlineInputBorder(),
|
||||||
isDense: true,
|
isDense: true,
|
||||||
filled: true,
|
filled: true,
|
||||||
fillColor: Theme.of(context).scaffoldBackgroundColor,
|
fillColor: Theme.of(context).scaffoldBackgroundColor,
|
||||||
enabledBorder: const OutlineInputBorder(
|
enabledBorder: OutlineInputBorder(
|
||||||
borderSide: BorderSide(color: Colors.black),
|
borderSide: BorderSide(
|
||||||
|
color: Theme.of(context).colorScheme.outline),
|
||||||
),
|
),
|
||||||
focusedBorder: const OutlineInputBorder(
|
focusedBorder: OutlineInputBorder(
|
||||||
borderSide: BorderSide(color: Colors.black, width: 2),
|
borderSide: BorderSide(
|
||||||
|
color: Theme.of(context).colorScheme.primary,
|
||||||
|
width: 2),
|
||||||
),
|
),
|
||||||
suffixIcon: IconButton(
|
suffixIcon: IconButton(
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
@@ -194,7 +385,6 @@ class LoginScreenState extends State<LoginScreen>
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
//Login Button
|
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: 250,
|
width: 250,
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
@@ -202,275 +392,26 @@ class LoginScreenState extends State<LoginScreen>
|
|||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
shape: const StadiumBorder(),
|
shape: const StadiumBorder(),
|
||||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
backgroundColor:
|
||||||
|
Theme.of(context).scaffoldBackgroundColor,
|
||||||
foregroundColor: Theme.of(context).primaryColorDark,
|
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,
|
elevation: 0,
|
||||||
),
|
),
|
||||||
child: state is AuthLoading
|
child: state is AuthLoading
|
||||||
? const CircularProgressIndicator()
|
? const CircularProgressIndicator()
|
||||||
: Text(
|
: Text(
|
||||||
AppLocalizations.of(context).login,
|
AppLocalizations.of(context).login,
|
||||||
style: TextStyle(fontSize: 16),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
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),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*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(
|
style: TextStyle(
|
||||||
fontSize: 32,
|
color: Theme.of(context)
|
||||||
fontWeight: FontWeight.bold,
|
.colorScheme
|
||||||
color: Colors.blue),
|
.onPrimaryContainer),
|
||||||
),
|
),
|
||||||
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),
|
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'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -480,4 +421,3 @@ class LoginScreenState extends State<LoginScreen> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
import '../../../l10n/app_localizations.dart';
|
import '../../../l10n/app_localizations.dart';
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
import 'dart:developer';
|
// import 'dart:developer';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:kmobile/app.dart';
|
|
||||||
import 'package:kmobile/di/injection.dart';
|
import 'package:kmobile/di/injection.dart';
|
||||||
import 'package:kmobile/security/secure_storage.dart';
|
import 'package:kmobile/security/secure_storage.dart';
|
||||||
import 'package:local_auth/local_auth.dart';
|
import 'package:local_auth/local_auth.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
enum MPinMode { enter, set, confirm }
|
enum MPinMode { enter, set, confirm }
|
||||||
|
|
||||||
@@ -14,38 +15,96 @@ class MPinScreen extends StatefulWidget {
|
|||||||
final MPinMode mode;
|
final MPinMode mode;
|
||||||
final String? initialPin;
|
final String? initialPin;
|
||||||
final void Function(String pin)? onCompleted;
|
final void Function(String pin)? onCompleted;
|
||||||
|
final bool disableBiometric;
|
||||||
|
final String? customTitle;
|
||||||
|
final String? customConfirmTitle;
|
||||||
|
|
||||||
const MPinScreen({
|
const MPinScreen({
|
||||||
super.key,
|
super.key,
|
||||||
required this.mode,
|
required this.mode,
|
||||||
this.initialPin,
|
this.initialPin,
|
||||||
this.onCompleted,
|
this.onCompleted,
|
||||||
|
this.disableBiometric = false,
|
||||||
|
this.customTitle,
|
||||||
|
this.customConfirmTitle,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<MPinScreen> createState() => _MPinScreenState();
|
State<MPinScreen> createState() => _MPinScreenState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _MPinScreenState extends State<MPinScreen> {
|
class _MPinScreenState extends State<MPinScreen> with TickerProviderStateMixin {
|
||||||
List<String> mPin = [];
|
List<String> mPin = [];
|
||||||
String? errorText;
|
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
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.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();
|
_tryBiometricBeforePin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_bounceController.dispose();
|
||||||
|
_shakeController.dispose();
|
||||||
|
_waveController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _tryBiometricBeforePin() async {
|
Future<void> _tryBiometricBeforePin() async {
|
||||||
final storage = getIt<SecureStorage>();
|
final storage = getIt<SecureStorage>();
|
||||||
final enabled = await storage.read('biometric_enabled');
|
final enabled = await storage.read('biometric_enabled');
|
||||||
log('biometric_enabled: $enabled');
|
// log('biometric_enabled: $enabled');
|
||||||
if (enabled != null && enabled) {
|
if (enabled != null && enabled) {
|
||||||
final auth = LocalAuthentication();
|
final auth = LocalAuthentication();
|
||||||
if (await auth.canCheckBiometrics) {
|
if (await auth.canCheckBiometrics) {
|
||||||
final didAuth = await auth.authenticate(
|
final didAuth = await auth.authenticate(
|
||||||
|
// ignore: use_build_context_synchronously
|
||||||
localizedReason: AppLocalizations.of(context).authenticateToAccess,
|
localizedReason: AppLocalizations.of(context).authenticateToAccess,
|
||||||
options: const AuthenticationOptions(biometricOnly: true),
|
options: const AuthenticationOptions(biometricOnly: true),
|
||||||
);
|
);
|
||||||
@@ -61,11 +120,13 @@ class _MPinScreenState extends State<MPinScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void addDigit(String digit) {
|
void addDigit(String digit) {
|
||||||
|
if (_shakeController.isAnimating || _waveController.isAnimating) return;
|
||||||
if (mPin.length < 4) {
|
if (mPin.length < 4) {
|
||||||
setState(() {
|
setState(() {
|
||||||
mPin.add(digit);
|
mPin.add(digit);
|
||||||
errorText = null;
|
errorText = null;
|
||||||
});
|
});
|
||||||
|
_bounceController.forward(from: 0);
|
||||||
if (mPin.length == 4) {
|
if (mPin.length == 4) {
|
||||||
_handleComplete();
|
_handleComplete();
|
||||||
}
|
}
|
||||||
@@ -73,6 +134,7 @@ class _MPinScreenState extends State<MPinScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void deleteDigit() {
|
void deleteDigit() {
|
||||||
|
if (_shakeController.isAnimating || _waveController.isAnimating) return;
|
||||||
if (mPin.isNotEmpty) {
|
if (mPin.isNotEmpty) {
|
||||||
setState(() {
|
setState(() {
|
||||||
mPin.removeLast();
|
mPin.removeLast();
|
||||||
@@ -82,71 +144,148 @@ class _MPinScreenState extends State<MPinScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _handleComplete() async {
|
Future<void> _handleComplete() async {
|
||||||
|
if (_shakeController.isAnimating || _waveController.isAnimating) return;
|
||||||
|
|
||||||
final pin = mPin.join();
|
final pin = mPin.join();
|
||||||
final storage = SecureStorage();
|
final storage = SecureStorage();
|
||||||
|
|
||||||
switch (widget.mode) {
|
switch (widget.mode) {
|
||||||
case MPinMode.enter:
|
case MPinMode.enter:
|
||||||
final storedPin = await storage.read('mpin');
|
final storedPin = await storage.read('mpin');
|
||||||
log('storedPin: $storedPin');
|
// log('storedPin: $storedPin');
|
||||||
if (storedPin == int.tryParse(pin)) {
|
if (storedPin == int.tryParse(pin)) {
|
||||||
widget.onCompleted?.call(pin);
|
// Correct PIN
|
||||||
} else {
|
|
||||||
setState(() {
|
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;
|
errorText = AppLocalizations.of(context).incorrectMPIN;
|
||||||
|
});
|
||||||
|
await _shakeController.forward(from: 0);
|
||||||
|
setState(() {
|
||||||
mPin.clear();
|
mPin.clear();
|
||||||
|
_isError = false;
|
||||||
|
// Keep error text until next digit is entered
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MPinMode.set:
|
case MPinMode.set:
|
||||||
// propagate parent onCompleted into confirm step
|
// Navigate to confirm and wait for result
|
||||||
Navigator.push(
|
final result = await Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (_) => MPinScreen(
|
builder: (_) => MPinScreen(
|
||||||
mode: MPinMode.confirm,
|
mode: MPinMode.confirm,
|
||||||
initialPin: pin,
|
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;
|
break;
|
||||||
case MPinMode.confirm:
|
case MPinMode.confirm:
|
||||||
if (widget.initialPin == pin) {
|
if (widget.initialPin == pin) {
|
||||||
// 1) persist the pin
|
// 1) persist the pin
|
||||||
await storage.write('mpin', 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) {
|
if (mounted) {
|
||||||
Navigator.of(context, rootNavigator: true).pushAndRemoveUntil(
|
widget.onCompleted?.call(pin);
|
||||||
MaterialPageRoute(builder: (_) => const NavigationScaffold()),
|
|
||||||
(route) => false,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
setState(() {
|
setState(() {
|
||||||
|
_isError = true;
|
||||||
errorText = AppLocalizations.of(context).pinsDoNotMatch;
|
errorText = AppLocalizations.of(context).pinsDoNotMatch;
|
||||||
|
});
|
||||||
|
await _shakeController.forward(from: 0);
|
||||||
|
setState(() {
|
||||||
mPin.clear();
|
mPin.clear();
|
||||||
|
_isError = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget buildMPinDots() {
|
Widget buildMPinDots(BuildContext context) {
|
||||||
return Row(
|
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,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: List.generate(4, (index) {
|
children: List.generate(4, (index) {
|
||||||
return Container(
|
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),
|
margin: const EdgeInsets.all(8),
|
||||||
width: 15,
|
width: 25,
|
||||||
height: 15,
|
height: 25,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
shape: BoxShape.circle,
|
shape: BoxShape.circle,
|
||||||
color: index < mPin.length ? Colors.black : Colors.grey[400],
|
color: dotColor,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,9 +303,10 @@ class _MPinScreenState extends State<MPinScreen> {
|
|||||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
children: row.map((key) {
|
children: row.map((key) {
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(1.0),
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
|
HapticFeedback.lightImpact();
|
||||||
if (key == '<') {
|
if (key == '<') {
|
||||||
deleteDigit();
|
deleteDigit();
|
||||||
} else if (key == 'Enter') {
|
} else if (key == 'Enter') {
|
||||||
@@ -184,11 +324,10 @@ class _MPinScreenState extends State<MPinScreen> {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
width: 70,
|
width: 80,
|
||||||
height: 70,
|
height: 80,
|
||||||
decoration: BoxDecoration(
|
decoration: const BoxDecoration(
|
||||||
shape: BoxShape.circle,
|
shape: BoxShape.circle,
|
||||||
color: Colors.grey[200],
|
|
||||||
),
|
),
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
child: key == 'Enter'
|
child: key == 'Enter'
|
||||||
@@ -196,8 +335,10 @@ class _MPinScreenState extends State<MPinScreen> {
|
|||||||
: Text(
|
: Text(
|
||||||
key == '<' ? '⌫' : key,
|
key == '<' ? '⌫' : key,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 20,
|
fontSize: 30,
|
||||||
color: key == 'Enter' ? Theme.of(context).primaryColor : Colors.black,
|
color: key == 'Enter'
|
||||||
|
? Theme.of(context).primaryColor
|
||||||
|
: Theme.of(context).colorScheme.onSurface,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -210,6 +351,9 @@ class _MPinScreenState extends State<MPinScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String getTitle() {
|
String getTitle() {
|
||||||
|
if (widget.customTitle != null) {
|
||||||
|
return widget.customTitle!;
|
||||||
|
}
|
||||||
switch (widget.mode) {
|
switch (widget.mode) {
|
||||||
case MPinMode.enter:
|
case MPinMode.enter:
|
||||||
return AppLocalizations.of(context).enterMPIN;
|
return AppLocalizations.of(context).enterMPIN;
|
||||||
@@ -226,7 +370,7 @@ class _MPinScreenState extends State<MPinScreen> {
|
|||||||
body: SafeArea(
|
body: SafeArea(
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
const Spacer(),
|
const SizedBox(height: 50),
|
||||||
// Logo
|
// Logo
|
||||||
Image.asset('assets/images/logo.png', height: 100),
|
Image.asset('assets/images/logo.png', height: 100),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
@@ -234,19 +378,18 @@ class _MPinScreenState extends State<MPinScreen> {
|
|||||||
getTitle(),
|
getTitle(),
|
||||||
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.w500),
|
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.w500),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const Spacer(),
|
||||||
buildMPinDots(),
|
buildMPinDots(context),
|
||||||
if (errorText != null)
|
if (errorText != null)
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(top: 8.0),
|
padding: const EdgeInsets.only(top: 8.0),
|
||||||
child: Text(
|
child: Text(
|
||||||
errorText!,
|
errorText!,
|
||||||
style: const TextStyle(color: Colors.red),
|
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
buildNumberPad(),
|
buildNumberPad(),
|
||||||
const Spacer(),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
296
lib/features/auth/screens/set_password_screen.dart
Normal file
@@ -0,0 +1,296 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:kmobile/api/services/auth_service.dart';
|
||||||
|
import 'package:kmobile/di/injection.dart';
|
||||||
|
import 'package:kmobile/features/auth/screens/login_screen.dart';
|
||||||
|
|
||||||
|
import '../../../l10n/app_localizations.dart';
|
||||||
|
|
||||||
|
class SetPasswordScreen extends StatefulWidget {
|
||||||
|
final String customerNo;
|
||||||
|
const SetPasswordScreen({super.key, required this.customerNo});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<SetPasswordScreen> createState() => _SetPasswordScreenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
enum SetPasswordStep { initial, otp, setPassword, success }
|
||||||
|
|
||||||
|
class _SetPasswordScreenState extends State<SetPasswordScreen> {
|
||||||
|
final _authService = getIt<AuthService>();
|
||||||
|
SetPasswordStep _currentStep = SetPasswordStep.initial;
|
||||||
|
bool _isLoading = false;
|
||||||
|
String? _error;
|
||||||
|
String? _otpToken;
|
||||||
|
|
||||||
|
final _otpController = TextEditingController();
|
||||||
|
final _passwordController = TextEditingController();
|
||||||
|
final _confirmPasswordController = TextEditingController();
|
||||||
|
|
||||||
|
bool _obscurePassword = true;
|
||||||
|
bool _obscureConfirmPassword = true;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_otpController.dispose();
|
||||||
|
_passwordController.dispose();
|
||||||
|
_confirmPasswordController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _sendOtp() async {
|
||||||
|
setState(() {
|
||||||
|
_isLoading = true;
|
||||||
|
_error = null;
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
await _authService.sendOtpForSettingPassword(widget.customerNo);
|
||||||
|
setState(() {
|
||||||
|
_currentStep = SetPasswordStep.otp;
|
||||||
|
_isLoading = false;
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
setState(() {
|
||||||
|
_error = e.toString();
|
||||||
|
_isLoading = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _verifyOtp() async {
|
||||||
|
if (_otpController.text.isEmpty) {
|
||||||
|
setState(() {
|
||||||
|
_error = 'Please enter OTP';
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setState(() {
|
||||||
|
_isLoading = true;
|
||||||
|
_error = null;
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
final token = await _authService.verifyOtpForSettingPassword(
|
||||||
|
widget.customerNo, _otpController.text);
|
||||||
|
setState(() {
|
||||||
|
_otpToken = token;
|
||||||
|
_currentStep = SetPasswordStep.setPassword;
|
||||||
|
_isLoading = false;
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
setState(() {
|
||||||
|
_error = AppLocalizations.of(context).invalidOtp;
|
||||||
|
_isLoading = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _setPassword() async {
|
||||||
|
if (_passwordController.text.isEmpty ||
|
||||||
|
_confirmPasswordController.text.isEmpty) {
|
||||||
|
setState(() {
|
||||||
|
_error = 'Please fill both password fields';
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (_passwordController.text != _confirmPasswordController.text) {
|
||||||
|
setState(() {
|
||||||
|
_error = 'Passwords do not match';
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (_otpToken == null) {
|
||||||
|
setState(() {
|
||||||
|
_error = 'OTP token is missing. Please restart the process.';
|
||||||
|
_currentStep = SetPasswordStep.initial;
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
_isLoading = true;
|
||||||
|
_error = null;
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
await _authService.changePassword(_passwordController.text, _otpToken!);
|
||||||
|
setState(() {
|
||||||
|
_currentStep = SetPasswordStep.success;
|
||||||
|
_isLoading = false;
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
setState(() {
|
||||||
|
_error = e.toString();
|
||||||
|
_isLoading = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: const Text('Set New Password'),
|
||||||
|
),
|
||||||
|
body: Padding(
|
||||||
|
padding: const EdgeInsets.all(24.0),
|
||||||
|
child: Center(
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
if (_error != null) ...[
|
||||||
|
Text(
|
||||||
|
_error!,
|
||||||
|
style: const TextStyle(
|
||||||
|
color: Colors.red,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
fontSize: 20),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
],
|
||||||
|
if (_isLoading)
|
||||||
|
const CircularProgressIndicator()
|
||||||
|
else
|
||||||
|
_buildStepContent(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildStepContent() {
|
||||||
|
switch (_currentStep) {
|
||||||
|
case SetPasswordStep.initial:
|
||||||
|
return _buildInitialStep();
|
||||||
|
case SetPasswordStep.otp:
|
||||||
|
return _buildOtpStep();
|
||||||
|
case SetPasswordStep.setPassword:
|
||||||
|
return _buildSetPasswordStep();
|
||||||
|
case SetPasswordStep.success:
|
||||||
|
return _buildSuccessStep();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildInitialStep() {
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
const Text(
|
||||||
|
'You need to set a new password to continue. We will send an OTP to your registered mobile number.',
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: TextStyle(fontSize: 16),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 24),
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: _sendOtp,
|
||||||
|
child: const Text('Proceed'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildOtpStep() {
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
const Text(
|
||||||
|
'An OTP has been sent to your registered mobile number. Please enter it below.',
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 24),
|
||||||
|
TextField(
|
||||||
|
controller: _otpController,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
labelText: 'Enter OTP',
|
||||||
|
border: OutlineInputBorder(),
|
||||||
|
),
|
||||||
|
keyboardType: TextInputType.number,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 24),
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: _verifyOtp,
|
||||||
|
child: const Text('Verify OTP'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildSetPasswordStep() {
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
TextFormField(
|
||||||
|
controller: _passwordController,
|
||||||
|
obscureText: _obscurePassword,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
labelText: 'New Password',
|
||||||
|
border: const OutlineInputBorder(),
|
||||||
|
suffixIcon: IconButton(
|
||||||
|
icon: Icon(
|
||||||
|
_obscurePassword ? Icons.visibility : Icons.visibility_off,
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
_obscurePassword = !_obscurePassword;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 24),
|
||||||
|
TextFormField(
|
||||||
|
controller: _confirmPasswordController,
|
||||||
|
obscureText: _obscureConfirmPassword,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
labelText: 'Confirm New Password',
|
||||||
|
border: const OutlineInputBorder(),
|
||||||
|
suffixIcon: IconButton(
|
||||||
|
icon: Icon(
|
||||||
|
_obscureConfirmPassword
|
||||||
|
? Icons.visibility
|
||||||
|
: Icons.visibility_off,
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
_obscureConfirmPassword = !_obscureConfirmPassword;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 24),
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: _setPassword,
|
||||||
|
child: const Text('Set Password'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildSuccessStep() {
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
const Icon(Icons.check_circle, color: Colors.green, size: 80),
|
||||||
|
const SizedBox(height: 24),
|
||||||
|
const Text(
|
||||||
|
'Password set successfully!',
|
||||||
|
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
const Text(
|
||||||
|
'You can now log in with your new password.',
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 24),
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pushAndRemoveUntil(
|
||||||
|
MaterialPageRoute(builder: (_) => const LoginScreen()),
|
||||||
|
(route) => false,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: const Text('Back to Login'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
94
lib/features/auth/screens/splash_screen.dart
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
import 'package:package_info_plus/package_info_plus.dart';
|
||||||
|
|
||||||
|
import '../../../l10n/app_localizations.dart';
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class SplashScreen extends StatefulWidget {
|
||||||
|
const SplashScreen({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<SplashScreen> createState() => _SplashScreenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SplashScreenState extends State<SplashScreen> {
|
||||||
|
String _version = '';
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_loadVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _loadVersion() async {
|
||||||
|
final PackageInfo info = await PackageInfo.fromPlatform();
|
||||||
|
if (mounted) {
|
||||||
|
// Check if the widget is still in the tree
|
||||||
|
setState(() {
|
||||||
|
_version = 'Version ${info.version} (${info.buildNumber})';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
body: Stack(
|
||||||
|
fit: StackFit.expand,
|
||||||
|
children: <Widget>[
|
||||||
|
Positioned.fill(
|
||||||
|
child: Image.asset(
|
||||||
|
'assets/images/kconnect2.webp',
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
AppLocalizations.of(context).kccbMobile,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 36,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: Color(0xFFFFFFFF),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
Text(
|
||||||
|
AppLocalizations.of(context).kccBankFull,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 18,
|
||||||
|
color: Color(0xFFFFFFFF),
|
||||||
|
letterSpacing: 1.2,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const Positioned(
|
||||||
|
bottom: 40,
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
child: Center(
|
||||||
|
child: CircularProgressIndicator(color: Color(0xFFFFFFFF)),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Positioned(
|
||||||
|
bottom: 90,
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
child: Text(
|
||||||
|
_version,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: const TextStyle(
|
||||||
|
color: Color(0xFFFFFFFF),
|
||||||
|
fontSize: 14,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
58
lib/features/auth/screens/tnc_required_screen.dart
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class TncRequiredScreen extends StatelessWidget {
|
||||||
|
// Renamed class
|
||||||
|
const TncRequiredScreen({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
static const routeName = '/tnc-required';
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: const Text('Terms and Conditions'),
|
||||||
|
),
|
||||||
|
body: Stack(
|
||||||
|
children: [
|
||||||
|
Center(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(16.0),
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
const Text(
|
||||||
|
'You must accept the Terms and Conditions to use the application.',
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: TextStyle(fontSize: 18),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: () {
|
||||||
|
// This will take the user back to the previous screen
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
child: const Text('Go Back'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
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
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,141 +0,0 @@
|
|||||||
import '../../../l10n/app_localizations.dart';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'dart:async';
|
|
||||||
|
|
||||||
class WelcomeScreen extends StatefulWidget {
|
|
||||||
final VoidCallback onContinue;
|
|
||||||
|
|
||||||
const WelcomeScreen({super.key, required this.onContinue});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<WelcomeScreen> createState() => _WelcomeScreenState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _WelcomeScreenState extends State<WelcomeScreen> {
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
|
|
||||||
// Automatically go to logizn after 4 seconds
|
|
||||||
Timer(const Duration(seconds: 4), () {
|
|
||||||
|
|
||||||
widget.onContinue();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
body: Stack(
|
|
||||||
children: [
|
|
||||||
/// 🔹 Background Image
|
|
||||||
Positioned.fill(
|
|
||||||
child: Image.asset(
|
|
||||||
'assets/images/kconnect2.webp',
|
|
||||||
fit: BoxFit.cover,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
|
|
||||||
/// 🔹 Centered Text Overlay
|
|
||||||
Center(
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
AppLocalizations.of(context).kconnect,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 36,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: Theme.of(context).dialogBackgroundColor,
|
|
||||||
letterSpacing: 1.5,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
Text(
|
|
||||||
AppLocalizations.of(context).kccBankFull,
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 18,
|
|
||||||
color: Theme.of(context).dialogBackgroundColor,
|
|
||||||
letterSpacing: 1.2,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
|
|
||||||
/// 🔹 Loading Spinner at Bottom
|
|
||||||
Positioned(
|
|
||||||
bottom: 40,
|
|
||||||
left: 0,
|
|
||||||
right: 0,
|
|
||||||
child: Center(
|
|
||||||
child: CircularProgressIndicator(color: Theme.of(context).scaffoldBackgroundColor),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
class WelcomeScreen extends StatelessWidget {
|
|
||||||
final VoidCallback onContinue;
|
|
||||||
|
|
||||||
const WelcomeScreen({super.key, required this.onContinue});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: Colors.white,
|
|
||||||
body: Center(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(32.0),
|
|
||||||
child: Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
const Spacer(),
|
|
||||||
const Text(
|
|
||||||
'Welcome to',
|
|
||||||
style: TextStyle(fontSize: 28, color: Colors.black87),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 10),
|
|
||||||
const Text(
|
|
||||||
'KCCB',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 42,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: Colors.indigo,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 40),
|
|
||||||
Image.asset(
|
|
||||||
'assets/images/logo.png',
|
|
||||||
width: 150,
|
|
||||||
height: 150,
|
|
||||||
),
|
|
||||||
const Spacer(),
|
|
||||||
ElevatedButton(
|
|
||||||
onPressed: onContinue,
|
|
||||||
style: ElevatedButton.styleFrom(
|
|
||||||
backgroundColor: Colors.indigo,
|
|
||||||
foregroundColor: Colors.white,
|
|
||||||
padding:
|
|
||||||
const EdgeInsets.symmetric(horizontal: 28, vertical: 20),
|
|
||||||
),
|
|
||||||
child: const Text('Proceed to Login'),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 24),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
@@ -1,22 +1,20 @@
|
|||||||
|
import 'package:dio/dio.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_svg/svg.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:kmobile/api/services/beneficiary_service.dart';
|
import 'package:kmobile/api/services/beneficiary_service.dart';
|
||||||
import 'package:kmobile/data/models/ifsc.dart';
|
|
||||||
import 'package:kmobile/data/models/beneficiary.dart';
|
import 'package:kmobile/data/models/beneficiary.dart';
|
||||||
import 'package:kmobile/data/models/user.dart';
|
|
||||||
import 'beneficiary_result_page.dart';
|
|
||||||
import 'package:material_symbols_icons/material_symbols_icons.dart';
|
import 'package:material_symbols_icons/material_symbols_icons.dart';
|
||||||
|
import 'beneficiary_result_page.dart';
|
||||||
import '../../../di/injection.dart';
|
import '../../../di/injection.dart';
|
||||||
import '../../../l10n/app_localizations.dart';
|
import '../../../l10n/app_localizations.dart';
|
||||||
|
import 'package:kmobile/features/fund_transfer/screens/transaction_pin_screen.dart';
|
||||||
|
|
||||||
class AddBeneficiaryScreen extends StatefulWidget {
|
class AddBeneficiaryScreen extends StatefulWidget {
|
||||||
final List<User>? users;
|
final String customerName;
|
||||||
final int? selectedIndex;
|
|
||||||
|
|
||||||
const AddBeneficiaryScreen({
|
const AddBeneficiaryScreen({
|
||||||
super.key,
|
super.key,
|
||||||
this.users,
|
required this.customerName,
|
||||||
this.selectedIndex,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -25,8 +23,9 @@ class AddBeneficiaryScreen extends StatefulWidget {
|
|||||||
|
|
||||||
class _AddBeneficiaryScreen extends State<AddBeneficiaryScreen> {
|
class _AddBeneficiaryScreen extends State<AddBeneficiaryScreen> {
|
||||||
final _formKey = GlobalKey<FormState>();
|
final _formKey = GlobalKey<FormState>();
|
||||||
|
final _accountNumberFieldKey = GlobalKey<FormFieldState>();
|
||||||
late User selectedUser = (widget.users ?? [])[widget.selectedIndex!];
|
final _confirmAccountNumberFieldKey = GlobalKey<FormFieldState>();
|
||||||
|
final _ifscFieldKey = GlobalKey<FormFieldState>();
|
||||||
final TextEditingController accountNumberController = TextEditingController();
|
final TextEditingController accountNumberController = TextEditingController();
|
||||||
final TextEditingController confirmAccountNumberController =
|
final TextEditingController confirmAccountNumberController =
|
||||||
TextEditingController();
|
TextEditingController();
|
||||||
@@ -35,61 +34,84 @@ class _AddBeneficiaryScreen extends State<AddBeneficiaryScreen> {
|
|||||||
final TextEditingController branchNameController = TextEditingController();
|
final TextEditingController branchNameController = TextEditingController();
|
||||||
final TextEditingController ifscController = TextEditingController();
|
final TextEditingController ifscController = TextEditingController();
|
||||||
final TextEditingController phoneController = TextEditingController();
|
final TextEditingController phoneController = TextEditingController();
|
||||||
|
final _ifscFocusNode = FocusNode();
|
||||||
|
final service = getIt<BeneficiaryService>();
|
||||||
|
|
||||||
String? _beneficiaryName;
|
|
||||||
bool _isValidating = false;
|
bool _isValidating = false;
|
||||||
bool _isBeneficiaryValidated = false;
|
bool _isBeneficiaryValidated = false;
|
||||||
|
// ignore: unused_field
|
||||||
String? _validationError;
|
String? _validationError;
|
||||||
|
|
||||||
late String accountType;
|
late String accountType;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
_ifscFocusNode.addListener(() {
|
||||||
|
if (!_ifscFocusNode.hasFocus && ifscController.text.trim().length == 11) {
|
||||||
|
_validateIFSC();
|
||||||
|
}
|
||||||
|
});
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
setState(() {
|
setState(() {
|
||||||
accountType = AppLocalizations.of(context).savings;
|
accountType = 'Savings';
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
ifsc? _ifscData;
|
accountNumberController.dispose();
|
||||||
bool _isLoading = false; //for validateIFSC()
|
confirmAccountNumberController.dispose();
|
||||||
|
nameController.dispose();
|
||||||
|
bankNameController.dispose();
|
||||||
|
branchNameController.dispose();
|
||||||
|
ifscController.dispose();
|
||||||
|
phoneController.dispose();
|
||||||
|
_ifscFocusNode.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
void _validateIFSC() async {
|
void _validateIFSC() async {
|
||||||
var beneficiaryService = getIt<BeneficiaryService>();
|
var beneficiaryService = getIt<BeneficiaryService>();
|
||||||
final ifsc = ifscController.text.trim().toUpperCase();
|
final ifsc = ifscController.text.trim().toUpperCase();
|
||||||
if (ifsc.isEmpty) return;
|
if (ifsc.isEmpty) return;
|
||||||
setState(() {
|
|
||||||
_isLoading = true;
|
|
||||||
_ifscData = null;
|
|
||||||
});
|
|
||||||
|
|
||||||
|
try {
|
||||||
final result = await beneficiaryService.validateIFSC(ifsc);
|
final result = await beneficiaryService.validateIFSC(ifsc);
|
||||||
|
|
||||||
setState(() {
|
if (mounted) {
|
||||||
_isLoading = false;
|
if (result.bankName.isEmpty) {
|
||||||
_ifscData = result;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (result == null) {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(content: Text(AppLocalizations.of(context).invalidIfsc)),
|
SnackBar(content: Text(AppLocalizations.of(context).invalidIfsc)),
|
||||||
);
|
);
|
||||||
bankNameController.clear();
|
bankNameController.clear();
|
||||||
branchNameController.clear();
|
branchNameController.clear();
|
||||||
} else {
|
} else {
|
||||||
print("${AppLocalizations.of(context).validIfsc}: ${result.bankName}, ${result.branchName}");
|
|
||||||
bankNameController.text = result.bankName;
|
bankNameController.text = result.bankName;
|
||||||
branchNameController.text = result.branchName;
|
branchNameController.text = result.branchName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
if (mounted) {
|
||||||
|
final errorMessage = e.toString().toUpperCase();
|
||||||
|
String snackbarMessage =
|
||||||
|
AppLocalizations.of(context).somethingWentWrong;
|
||||||
|
|
||||||
|
if (errorMessage.contains('INVALID') && errorMessage.contains('IFSC')) {
|
||||||
|
snackbarMessage = AppLocalizations.of(context).invalidIfsc;
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _validateBeneficiary() async {
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
// start spinner / disable button
|
SnackBar(content: Text(snackbarMessage)),
|
||||||
|
);
|
||||||
|
bankNameController.clear();
|
||||||
|
branchNameController.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _validateBeneficiary() async {
|
||||||
|
FocusScope.of(context).unfocus();
|
||||||
setState(() {
|
setState(() {
|
||||||
_isValidating = true;
|
_isValidating = true;
|
||||||
_validationError = null;
|
_validationError = null;
|
||||||
@@ -99,61 +121,30 @@ Future<void> _validateBeneficiary() async {
|
|||||||
|
|
||||||
final String accountNo = accountNumberController.text.trim();
|
final String accountNo = accountNumberController.text.trim();
|
||||||
final String ifsc = ifscController.text.trim();
|
final String ifsc = ifscController.text.trim();
|
||||||
final String remitter = selectedUser.name ?? '';
|
final String remitter = widget.customerName;
|
||||||
|
|
||||||
final service = getIt<BeneficiaryService>();
|
final service = getIt<BeneficiaryService>();
|
||||||
try {
|
try {
|
||||||
// Step 1: call validate API -> get refNo
|
String beneficiaryName;
|
||||||
final String? refNo = await service.validateBeneficiary(
|
if (ifsc.toLowerCase().contains('kace')) {
|
||||||
|
beneficiaryName =
|
||||||
|
await service.validateBeneficiaryWithinBank(accountNo);
|
||||||
|
} else {
|
||||||
|
beneficiaryName = await service.validateBeneficiary(
|
||||||
accountNo: accountNo,
|
accountNo: accountNo,
|
||||||
ifscCode: ifsc,
|
ifscCode: ifsc,
|
||||||
remitterName: remitter,
|
remitterName: remitter,
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (refNo == null || refNo.isEmpty) {
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_validationError = 'Validation request failed. Please check details.';
|
nameController.text = beneficiaryName;
|
||||||
_isBeneficiaryValidated = false;
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Step 2: poll checkValidationStatus for up to 30 seconds
|
|
||||||
const int timeoutSeconds = 30;
|
|
||||||
const int intervalSeconds = 2;
|
|
||||||
int elapsed = 0;
|
|
||||||
String? foundName;
|
|
||||||
|
|
||||||
while (elapsed < timeoutSeconds) {
|
|
||||||
final String? name = await service.checkValidationStatus(refNo);
|
|
||||||
|
|
||||||
if (name != null && name.trim().isNotEmpty) {
|
|
||||||
foundName = name.trim();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
await Future.delayed(const Duration(seconds: intervalSeconds));
|
|
||||||
elapsed += intervalSeconds;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (foundName != null) {
|
|
||||||
setState(() {
|
|
||||||
nameController.text = foundName!;
|
|
||||||
_isBeneficiaryValidated = true;
|
_isBeneficiaryValidated = true;
|
||||||
_validationError = null;
|
_validationError = null;
|
||||||
});
|
});
|
||||||
} else {
|
} catch (e) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_validationError = 'Beneficiary not found within timeout.';
|
_validationError = e.toString();
|
||||||
_isBeneficiaryValidated = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (e, st) {
|
|
||||||
// handle unexpected errors
|
|
||||||
// print or log if you want
|
|
||||||
debugPrint('Error validating beneficiary: $e\n$st');
|
|
||||||
setState(() {
|
|
||||||
_validationError = 'Something went wrong. Please try again.';
|
|
||||||
_isBeneficiaryValidated = false;
|
_isBeneficiaryValidated = false;
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
@@ -163,20 +154,48 @@ Future<void> _validateBeneficiary() async {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void validateAndAddBeneficiary() async {
|
||||||
|
// First, validate the form fields (account number, confirm account, ifsc, etc.)
|
||||||
|
if (!_formKey.currentState!.validate()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure beneficiary is validated before proceeding to TPIN
|
||||||
|
if (!_isBeneficiaryValidated) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(AppLocalizations.of(context)
|
||||||
|
.pleaseValidateBeneficiaryDetailsFirst)),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
String _selectedAccountType = 'Savings'; // default value
|
// Create the beneficiary object without TPIN for now
|
||||||
|
final beneficiaryWithoutTpin = Beneficiary(
|
||||||
|
accountNo: accountNumberController.text.trim(),
|
||||||
|
accountType: accountType,
|
||||||
|
name: nameController.text.trim(),
|
||||||
|
ifscCode: ifscController.text.trim(),
|
||||||
|
bankName: bankNameController.text.trim(),
|
||||||
|
branchName: branchNameController.text.trim(),
|
||||||
|
);
|
||||||
|
|
||||||
void validateAndAddBeneficiary() async {
|
// Navigate to TPIN screen
|
||||||
// Show spinner and disable UI
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => TransactionPinScreen(
|
||||||
|
onPinCompleted: (pinScreenContext, tpin) async {
|
||||||
|
// Show loading spinner while processing
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: pinScreenContext,
|
||||||
barrierDismissible: false, // Prevent dismiss on tap outside
|
barrierDismissible: false,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext ctx) {
|
||||||
|
// ignore: deprecated_member_use
|
||||||
return WillPopScope(
|
return WillPopScope(
|
||||||
onWillPop: () async => false, // Disable back button
|
onWillPop: () async => false,
|
||||||
child: const Center(
|
child: const Center(
|
||||||
child: CircularProgressIndicator(),
|
child: CircularProgressIndicator(),
|
||||||
),
|
),
|
||||||
@@ -184,70 +203,70 @@ void validateAndAddBeneficiary() async {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
final beneficiary = Beneficiary(
|
// Create a new Beneficiary object with the TPIN
|
||||||
accountNo: accountNumberController.text.trim(),
|
final beneficiaryWithTpin = Beneficiary(
|
||||||
accountType: _selectedAccountType,
|
accountNo: beneficiaryWithoutTpin.accountNo,
|
||||||
name: nameController.text.trim(),
|
accountType: beneficiaryWithoutTpin.accountType,
|
||||||
ifscCode: ifscController.text.trim(),
|
name: beneficiaryWithoutTpin.name,
|
||||||
|
ifscCode: beneficiaryWithoutTpin.ifscCode,
|
||||||
|
bankName: beneficiaryWithoutTpin.bankName,
|
||||||
|
branchName: beneficiaryWithoutTpin.branchName,
|
||||||
|
tpin: tpin,
|
||||||
);
|
);
|
||||||
|
|
||||||
var service = getIt<BeneficiaryService>();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await service.sendForValidation(beneficiary);
|
final isSuccess =
|
||||||
bool isFound = await service.checkIfFound(beneficiary.accountNo);
|
await service.sendForValidation(beneficiaryWithTpin);
|
||||||
|
|
||||||
if (context.mounted) {
|
if (pinScreenContext.mounted) {
|
||||||
Navigator.pop(context); // Close the spinner
|
Navigator.pop(pinScreenContext); // Close the spinner
|
||||||
Navigator.push(
|
Navigator.pushReplacement(
|
||||||
context,
|
pinScreenContext,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => BeneficiaryResultPage(isSuccess: isFound),
|
builder: (ctx) =>
|
||||||
|
BeneficiaryResultPage(isSuccess: isSuccess),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} on DioException catch (e) {
|
||||||
Navigator.pop(context); // Close the spinner
|
if (pinScreenContext.mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
Navigator.pop(pinScreenContext); // Close the spinner
|
||||||
SnackBar(content: Text(AppLocalizations.of(context).somethingWentWrong)),
|
ScaffoldMessenger.of(pinScreenContext).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(e.response?.statusCode == 409
|
||||||
|
? 'Beneficiary already exists'
|
||||||
|
: 'Something went Wrong')),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
if (pinScreenContext.mounted) {
|
||||||
|
Navigator.pop(pinScreenContext); // Close the spinner
|
||||||
|
ScaffoldMessenger.of(pinScreenContext).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(
|
||||||
|
AppLocalizations.of(context).somethingWentWrong)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
leading: IconButton(
|
|
||||||
icon: const Icon(Symbols.arrow_back_ios_new),
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.pop(context);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
title: Text(
|
title: Text(
|
||||||
AppLocalizations.of(context).addBeneficiary,
|
AppLocalizations.of(context).addBeneficiary,
|
||||||
style: TextStyle(color: Colors.black, fontWeight: FontWeight.w500),
|
|
||||||
),
|
),
|
||||||
centerTitle: false,
|
centerTitle: false,
|
||||||
actions: [
|
|
||||||
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,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
body: SafeArea(
|
body: SafeArea(
|
||||||
child: Form(
|
child: Stack(
|
||||||
|
children: [
|
||||||
|
Form(
|
||||||
key: _formKey,
|
key: _formKey,
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
@@ -259,29 +278,25 @@ void validateAndAddBeneficiary() async {
|
|||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
TextFormField(
|
TextFormField(
|
||||||
|
key: _accountNumberFieldKey,
|
||||||
controller: accountNumberController,
|
controller: accountNumberController,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: AppLocalizations.of(
|
labelText: AppLocalizations.of(
|
||||||
context,
|
context,
|
||||||
).accountNumber,
|
).accountNumber,
|
||||||
// prefixIcon: Icon(Icons.person),
|
// prefixIcon: Icon(Icons.person),
|
||||||
border: OutlineInputBorder(),
|
border: const OutlineInputBorder(),
|
||||||
isDense: true,
|
isDense: true,
|
||||||
filled: true,
|
|
||||||
fillColor: Theme.of(context).scaffoldBackgroundColor,
|
|
||||||
enabledBorder: const OutlineInputBorder(
|
|
||||||
borderSide: BorderSide(color: Colors.black),
|
|
||||||
),
|
|
||||||
focusedBorder: const OutlineInputBorder(
|
|
||||||
borderSide: BorderSide(
|
|
||||||
color: Colors.black,
|
|
||||||
width: 2,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
obscureText: true,
|
obscureText: true,
|
||||||
keyboardType: TextInputType.number,
|
keyboardType: TextInputType.number,
|
||||||
textInputAction: TextInputAction.next,
|
textInputAction: TextInputAction.next,
|
||||||
|
onChanged: (value) {
|
||||||
|
nameController.clear();
|
||||||
|
setState(() {
|
||||||
|
_isBeneficiaryValidated = false;
|
||||||
|
});
|
||||||
|
},
|
||||||
validator: (value) {
|
validator: (value) {
|
||||||
if (value == null || value.length < 10) {
|
if (value == null || value.length < 10) {
|
||||||
return AppLocalizations.of(
|
return AppLocalizations.of(
|
||||||
@@ -294,25 +309,15 @@ void validateAndAddBeneficiary() async {
|
|||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
// Confirm Account Number
|
// Confirm Account Number
|
||||||
TextFormField(
|
TextFormField(
|
||||||
|
key: _confirmAccountNumberFieldKey,
|
||||||
controller: confirmAccountNumberController,
|
controller: confirmAccountNumberController,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: AppLocalizations.of(
|
labelText: AppLocalizations.of(
|
||||||
context,
|
context,
|
||||||
).confirmAccountNumber,
|
).confirmAccountNumber,
|
||||||
// prefixIcon: Icon(Icons.person),
|
// prefixIcon: Icon(Icons.person),
|
||||||
border: OutlineInputBorder(),
|
border: const OutlineInputBorder(),
|
||||||
isDense: true,
|
isDense: true,
|
||||||
filled: true,
|
|
||||||
fillColor: Theme.of(context).scaffoldBackgroundColor,
|
|
||||||
enabledBorder: const OutlineInputBorder(
|
|
||||||
borderSide: BorderSide(color: Colors.black),
|
|
||||||
),
|
|
||||||
focusedBorder: const OutlineInputBorder(
|
|
||||||
borderSide: BorderSide(
|
|
||||||
color: Colors.black,
|
|
||||||
width: 2,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
keyboardType: TextInputType.number,
|
keyboardType: TextInputType.number,
|
||||||
textInputAction: TextInputAction.next,
|
textInputAction: TextInputAction.next,
|
||||||
@@ -331,40 +336,35 @@ void validateAndAddBeneficiary() async {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
// 🔹 IFSC Code Field
|
|
||||||
TextFormField(
|
TextFormField(
|
||||||
|
focusNode: _ifscFocusNode,
|
||||||
|
key: _ifscFieldKey,
|
||||||
controller: ifscController,
|
controller: ifscController,
|
||||||
|
maxLength: 11,
|
||||||
|
inputFormatters: [
|
||||||
|
LengthLimitingTextInputFormatter(11),
|
||||||
|
],
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: AppLocalizations.of(context).ifscCode,
|
labelText:
|
||||||
|
AppLocalizations.of(context).ifscCode,
|
||||||
border: const OutlineInputBorder(),
|
border: const OutlineInputBorder(),
|
||||||
isDense: true,
|
isDense: true,
|
||||||
filled: true,
|
|
||||||
fillColor: Theme.of(context).scaffoldBackgroundColor,
|
|
||||||
enabledBorder: const OutlineInputBorder(
|
|
||||||
borderSide: BorderSide(color: Colors.black),
|
|
||||||
),
|
|
||||||
focusedBorder: const OutlineInputBorder(
|
|
||||||
borderSide: BorderSide(
|
|
||||||
color: Colors.black,
|
|
||||||
width: 2,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
textCapitalization: TextCapitalization.characters,
|
textCapitalization: TextCapitalization.characters,
|
||||||
textInputAction: TextInputAction.next,
|
textInputAction: TextInputAction.next,
|
||||||
onFieldSubmitted: (_) {
|
|
||||||
_validateIFSC();
|
|
||||||
},
|
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
|
setState(() {
|
||||||
final trimmed = value.trim().toUpperCase();
|
final trimmed = value.trim().toUpperCase();
|
||||||
if (trimmed.length < 11) {
|
if (trimmed.length < 11) {
|
||||||
// clear bank/branch if backspace or changed
|
// clear bank/branch if backspace or changed
|
||||||
bankNameController.clear();
|
bankNameController.clear();
|
||||||
branchNameController.clear();
|
branchNameController.clear();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
validator: (value) {
|
validator: (value) {
|
||||||
final pattern = RegExp(r'^[A-Z]{4}0[A-Z0-9]{6}$');
|
final pattern =
|
||||||
|
RegExp(r'^[A-Z]{4}0[A-Z0-9]{6}$');
|
||||||
if (value == null || value.trim().isEmpty) {
|
if (value == null || value.trim().isEmpty) {
|
||||||
return AppLocalizations.of(context).enterIfsc;
|
return AppLocalizations.of(context).enterIfsc;
|
||||||
} else if (!pattern.hasMatch(
|
} else if (!pattern.hasMatch(
|
||||||
@@ -377,129 +377,117 @@ void validateAndAddBeneficiary() async {
|
|||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
// 🔹 Bank Name (Disabled)
|
// Bank Name (Disabled)
|
||||||
TextFormField(
|
TextFormField(
|
||||||
controller: bankNameController,
|
controller: bankNameController,
|
||||||
enabled: false, // changed from readOnly to disabled
|
enabled:
|
||||||
|
false, // changed from readOnly to disabled
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: AppLocalizations.of(context).bankName,
|
labelText:
|
||||||
|
AppLocalizations.of(context).bankName,
|
||||||
border: const OutlineInputBorder(),
|
border: const OutlineInputBorder(),
|
||||||
isDense: true,
|
isDense: true,
|
||||||
filled: true,
|
|
||||||
fillColor: Theme.of(context).dialogBackgroundColor, // disabled color
|
|
||||||
enabledBorder: const OutlineInputBorder(
|
|
||||||
borderSide: BorderSide(color: Colors.black),
|
|
||||||
),
|
|
||||||
focusedBorder: const OutlineInputBorder(
|
|
||||||
borderSide: BorderSide(
|
|
||||||
color: Colors.black,
|
|
||||||
width: 2,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
),
|
|
||||||
|
|
||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
// 🔹 Branch Name (Disabled)
|
// 🔹 Branch Name (Disabled)
|
||||||
TextFormField(
|
TextFormField(
|
||||||
controller: branchNameController,
|
controller: branchNameController,
|
||||||
enabled: false, // changed from readOnly to disabled
|
enabled:
|
||||||
|
false, // changed from readOnly to disabled
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: AppLocalizations.of(context).branchName,
|
labelText:
|
||||||
|
AppLocalizations.of(context).branchName,
|
||||||
border: const OutlineInputBorder(),
|
border: const OutlineInputBorder(),
|
||||||
isDense: true,
|
isDense: true,
|
||||||
filled: true,
|
|
||||||
fillColor: Theme.of(context).dialogBackgroundColor,
|
|
||||||
enabledBorder: const OutlineInputBorder(
|
|
||||||
borderSide: BorderSide(color: Colors.black),
|
|
||||||
),
|
|
||||||
focusedBorder: const OutlineInputBorder(
|
|
||||||
borderSide: BorderSide(
|
|
||||||
color: Colors.black,
|
|
||||||
width: 2,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
if (_isBeneficiaryValidated)
|
||||||
|
Column(
|
||||||
|
children: [
|
||||||
|
const SizedBox(height: 24),
|
||||||
|
TextFormField(
|
||||||
|
controller: nameController,
|
||||||
|
enabled: false,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
suffixIcon: _isBeneficiaryValidated
|
||||||
|
? const Icon(
|
||||||
|
Symbols.verified,
|
||||||
|
size: 25,
|
||||||
|
fill: 1,
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
suffixIconColor:
|
||||||
|
Theme.of(context).colorScheme.primary,
|
||||||
|
labelText: AppLocalizations.of(context)
|
||||||
|
.beneficiaryName,
|
||||||
|
border: const OutlineInputBorder(),
|
||||||
|
isDense: true,
|
||||||
),
|
),
|
||||||
|
textInputAction: TextInputAction.next,
|
||||||
|
validator: (value) =>
|
||||||
|
value == null || value.isEmpty
|
||||||
|
? AppLocalizations.of(context)
|
||||||
|
.nameRequired
|
||||||
|
: null,
|
||||||
),
|
),
|
||||||
//Validate Beneficiary Name
|
],
|
||||||
if (!_isBeneficiaryValidated)
|
),
|
||||||
|
const SizedBox(height: 24),
|
||||||
|
if (!_isBeneficiaryValidated)
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(top: 12.0),
|
padding: const EdgeInsets.only(bottom: 24),
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed: _isValidating
|
onPressed: _isValidating ||
|
||||||
|
ifscController.text.length != 11
|
||||||
? null
|
? null
|
||||||
: () {
|
: () {
|
||||||
if (
|
final isAccountValid =
|
||||||
confirmAccountNumberController.text ==
|
_accountNumberFieldKey
|
||||||
accountNumberController.text) {
|
.currentState!
|
||||||
|
.validate();
|
||||||
|
final isConfirmAccountValid =
|
||||||
|
_confirmAccountNumberFieldKey
|
||||||
|
.currentState!
|
||||||
|
.validate();
|
||||||
|
final isIfscValid = _ifscFieldKey
|
||||||
|
.currentState!
|
||||||
|
.validate();
|
||||||
|
|
||||||
|
if (isAccountValid &&
|
||||||
|
isConfirmAccountValid &&
|
||||||
|
isIfscValid) {
|
||||||
_validateBeneficiary();
|
_validateBeneficiary();
|
||||||
} else {
|
|
||||||
setState(() {
|
|
||||||
_validationError =
|
|
||||||
'Please enter a valid and matching account number.';
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: _isValidating
|
child: _isValidating
|
||||||
? const SizedBox(
|
? const SizedBox(
|
||||||
width: 20,
|
width: 20,
|
||||||
height: 20,
|
height: 20,
|
||||||
child: CircularProgressIndicator(strokeWidth: 2),
|
child: CircularProgressIndicator(
|
||||||
|
strokeWidth: 2),
|
||||||
)
|
)
|
||||||
: const Text('Validate Beneficiary'),
|
: Text(AppLocalizations.of(context)
|
||||||
|
.validateBeneficiary),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
//Beneficiary Name (Disabled)
|
//Beneficiary Name (Disabled)
|
||||||
TextFormField(
|
|
||||||
controller: nameController,
|
|
||||||
enabled: false,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
labelText: AppLocalizations.of(context).beneficiaryName,
|
|
||||||
border: const OutlineInputBorder(),
|
|
||||||
isDense: true,
|
|
||||||
filled: true,
|
|
||||||
fillColor: Theme.of(context).dialogBackgroundColor,
|
|
||||||
enabledBorder: const OutlineInputBorder(
|
|
||||||
borderSide: BorderSide(color: Colors.black),
|
|
||||||
),
|
|
||||||
focusedBorder: const OutlineInputBorder(
|
|
||||||
borderSide: BorderSide(color: Colors.black, width: 2),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
textInputAction: TextInputAction.next,
|
|
||||||
validator: (value) => value == null || value.isEmpty
|
|
||||||
? AppLocalizations.of(context).nameRequired
|
|
||||||
: null,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 24),
|
|
||||||
// 🔹 Account Type Dropdown
|
// 🔹 Account Type Dropdown
|
||||||
DropdownButtonFormField<String>(
|
DropdownButtonFormField<String>(
|
||||||
value: accountType,
|
value: accountType,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: AppLocalizations.of(context).accountType,
|
labelText:
|
||||||
|
AppLocalizations.of(context).accountType,
|
||||||
border: const OutlineInputBorder(),
|
border: const OutlineInputBorder(),
|
||||||
isDense: true,
|
isDense: true,
|
||||||
filled: true,
|
|
||||||
fillColor: Theme.of(context).scaffoldBackgroundColor,
|
|
||||||
enabledBorder: const OutlineInputBorder(
|
|
||||||
borderSide: BorderSide(color: Colors.black),
|
|
||||||
),
|
),
|
||||||
focusedBorder: const OutlineInputBorder(
|
items: [
|
||||||
borderSide: BorderSide(
|
'Savings',
|
||||||
color: Colors.black,
|
'Current',
|
||||||
width: 2,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
items:
|
|
||||||
[
|
|
||||||
AppLocalizations.of(context).savings,
|
|
||||||
AppLocalizations.of(context).current,
|
|
||||||
]
|
]
|
||||||
.map(
|
.map(
|
||||||
(type) => DropdownMenuItem(
|
(type) => DropdownMenuItem(
|
||||||
@@ -524,21 +512,10 @@ if (!_isBeneficiaryValidated)
|
|||||||
prefixIcon: const Icon(Icons.phone),
|
prefixIcon: const Icon(Icons.phone),
|
||||||
border: const OutlineInputBorder(),
|
border: const OutlineInputBorder(),
|
||||||
isDense: true,
|
isDense: true,
|
||||||
filled: true,
|
|
||||||
fillColor: Theme.of(context).scaffoldBackgroundColor,
|
|
||||||
enabledBorder: const OutlineInputBorder(
|
|
||||||
borderSide: BorderSide(color: Colors.black),
|
|
||||||
),
|
|
||||||
focusedBorder: const OutlineInputBorder(
|
|
||||||
borderSide: BorderSide(
|
|
||||||
color: Colors.black,
|
|
||||||
width: 2,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
textInputAction: TextInputAction.done,
|
textInputAction: TextInputAction.done,
|
||||||
validator: (value) =>
|
validator: (value) => value == null ||
|
||||||
value == null || value.length != 10
|
value.length != 10
|
||||||
? AppLocalizations.of(context).enterValidPhone
|
? AppLocalizations.of(context).enterValidPhone
|
||||||
: null,
|
: null,
|
||||||
),
|
),
|
||||||
@@ -549,25 +526,45 @@ if (!_isBeneficiaryValidated)
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: 250,
|
width: 250,
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed:
|
onPressed: validateAndAddBeneficiary,
|
||||||
validateAndAddBeneficiary,
|
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
shape: const StadiumBorder(),
|
shape: const StadiumBorder(),
|
||||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||||
backgroundColor: Theme.of(context).primaryColorDark,
|
backgroundColor:
|
||||||
foregroundColor: Theme.of(context).scaffoldBackgroundColor,
|
Theme.of(context).colorScheme.primaryContainer,
|
||||||
|
foregroundColor: Theme.of(context)
|
||||||
|
.colorScheme
|
||||||
|
.onPrimaryContainer),
|
||||||
|
child: Text(
|
||||||
|
AppLocalizations.of(context).validateAndAdd,
|
||||||
|
style: const TextStyle(fontSize: 16),
|
||||||
),
|
),
|
||||||
child: Text(AppLocalizations.of(context).validateAndAdd),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
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
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,182 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:kmobile/data/models/beneficiary.dart';
|
||||||
|
import 'package:kmobile/di/injection.dart';
|
||||||
|
import 'package:kmobile/widgets/bank_logos.dart';
|
||||||
|
import 'package:kmobile/api/services/beneficiary_service.dart';
|
||||||
|
|
||||||
|
import '../../../l10n/app_localizations.dart';
|
||||||
|
|
||||||
|
class BeneficiaryDetailsScreen extends StatelessWidget {
|
||||||
|
final Beneficiary beneficiary;
|
||||||
|
|
||||||
|
BeneficiaryDetailsScreen({super.key, required this.beneficiary});
|
||||||
|
|
||||||
|
final service = getIt<BeneficiaryService>();
|
||||||
|
|
||||||
|
void _deleteBeneficiary(BuildContext context) async {
|
||||||
|
try {
|
||||||
|
await service.deleteBeneficiary(beneficiary.accountNo);
|
||||||
|
if (!context.mounted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_showSuccessDialog(context);
|
||||||
|
} catch (e) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text('${AppLocalizations.of(context).failedToDeleteBeneficiary} : $e')),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _showSuccessDialog(BuildContext context) {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: Text(AppLocalizations.of(context).success),
|
||||||
|
content: Text(AppLocalizations.of(context).beneficiaryDeletedSuccessfully),
|
||||||
|
actions: <Widget>[
|
||||||
|
TextButton(
|
||||||
|
child: Text(AppLocalizations.of(context).ok),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).popUntil((route) => route.isFirst);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _showDeleteConfirmationDialog(BuildContext context) {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: Text(AppLocalizations.of(context).deleteBeneficiary),
|
||||||
|
content:
|
||||||
|
Text(AppLocalizations.of(context).areYouSureYouWantToDeleteThisBeneficiary),
|
||||||
|
actions: <Widget>[
|
||||||
|
TextButton(
|
||||||
|
child: Text(AppLocalizations.of(context).cancel),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
child: Text(AppLocalizations.of(context).delete),
|
||||||
|
onPressed: () {
|
||||||
|
_deleteBeneficiary(context);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: Text(AppLocalizations.of(context).beneficiarydetails),
|
||||||
|
),
|
||||||
|
body: SafeArea(
|
||||||
|
child: Stack(
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(16.0),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
CircleAvatar(
|
||||||
|
radius: 24,
|
||||||
|
backgroundColor: Colors.transparent,
|
||||||
|
child: getBankLogo(beneficiary.bankName, context),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 16),
|
||||||
|
Text(
|
||||||
|
beneficiary.name,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 20, fontWeight: FontWeight.bold),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 24),
|
||||||
|
_buildDetailRow('${AppLocalizations.of(context).bankName} ',
|
||||||
|
beneficiary.bankName ?? 'N/A'),
|
||||||
|
_buildDetailRow(
|
||||||
|
'${AppLocalizations.of(context).accountNumber} ',
|
||||||
|
beneficiary.accountNo),
|
||||||
|
_buildDetailRow(
|
||||||
|
'${AppLocalizations.of(context).accountType} ',
|
||||||
|
beneficiary.accountType),
|
||||||
|
_buildDetailRow('${AppLocalizations.of(context).ifscCode} ',
|
||||||
|
beneficiary.ifscCode),
|
||||||
|
_buildDetailRow('${AppLocalizations.of(context).branchName} ',
|
||||||
|
beneficiary.branchName ?? 'N/A'),
|
||||||
|
const Spacer(),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
|
children: [
|
||||||
|
// ElevatedButton.icon(
|
||||||
|
// onPressed: () {
|
||||||
|
// // Set Transaction Limit for this beneficiary
|
||||||
|
// },
|
||||||
|
// icon: const Icon(Icons.currency_rupee),
|
||||||
|
// label: const Text('Set Limit'),
|
||||||
|
// ),
|
||||||
|
ElevatedButton.icon(
|
||||||
|
onPressed: () {
|
||||||
|
// Delete beneficiary option
|
||||||
|
_showDeleteConfirmationDialog(context);
|
||||||
|
},
|
||||||
|
icon: const Icon(Icons.delete),
|
||||||
|
label: Text(AppLocalizations.of(context).delete),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
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.spaceBetween,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(label, style: const TextStyle(fontWeight: FontWeight.bold)),
|
||||||
|
const SizedBox(width: 16),
|
||||||
|
Flexible(
|
||||||
|
child: Text(
|
||||||
|
value,
|
||||||
|
textAlign: TextAlign.end,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||