From ae0928d9142832591e1694142f9b7a60a0c5678d Mon Sep 17 00:00:00 2001 From: "Raj.Ghag" Date: Mon, 27 Apr 2026 13:34:02 +0530 Subject: [PATCH] bugs solved and more fixes --- lib/login/blocs/login/login_bloc.dart | 8 ++++ lib/login/blocs/login/login_event.dart | 4 ++ lib/login/views/login_page.dart | 10 +++-- .../api_urls/api_urls.dart | 4 +- lib/profile/views/profile_page.dart | 2 + .../submit_qr_code/submit_qr_code_bloc.dart | 1 + lib/scan/view/qr_scan_screen.dart | 37 +++++++++++-------- 7 files changed, 45 insertions(+), 21 deletions(-) diff --git a/lib/login/blocs/login/login_bloc.dart b/lib/login/blocs/login/login_bloc.dart index dc0d587..3af1d23 100644 --- a/lib/login/blocs/login/login_bloc.dart +++ b/lib/login/blocs/login/login_bloc.dart @@ -18,6 +18,7 @@ class LoginBloc extends Bloc { on(_onRememberMeToggled); on(_onEmailErrorToggled); on(_onPasswordErrorToggled); + on(_onReset); } // ================= LOGIN SUBMITTED ================= @@ -87,4 +88,11 @@ class LoginBloc extends Bloc { ) { emit(state.copyWith(showPasswordError: event.show)); } + + void _onReset( + LoginReset event, + Emitter emit, + ) { + emit(const LoginState()); + } } \ No newline at end of file diff --git a/lib/login/blocs/login/login_event.dart b/lib/login/blocs/login/login_event.dart index 05f5356..cdacc58 100644 --- a/lib/login/blocs/login/login_event.dart +++ b/lib/login/blocs/login/login_event.dart @@ -42,6 +42,10 @@ class LoginEmailErrorToggled extends LoginEvent { List get props => [show]; } +class LoginReset extends LoginEvent { + const LoginReset(); +} + class LoginPasswordErrorToggled extends LoginEvent { final bool show; const LoginPasswordErrorToggled(this.show); diff --git a/lib/login/views/login_page.dart b/lib/login/views/login_page.dart index 6d4c432..7b0bdb5 100644 --- a/lib/login/views/login_page.dart +++ b/lib/login/views/login_page.dart @@ -22,6 +22,12 @@ class _LoginPageState extends State { final _emailFocusNode = FocusNode(); final _passwordFocusNode = FocusNode(); + @override + void initState() { + super.initState(); + context.read().add(const LoginReset()); + } + @override void dispose() { _emailController.dispose(); @@ -32,9 +38,7 @@ class _LoginPageState extends State { } bool _isEmailValid(String email) { - return RegExp( - r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$') - .hasMatch(email); + return RegExp(r'^[\w-\.]+@([\w-]+\.)+[a-zA-Z]{2,4}$').hasMatch(email); } void _onLoginPressed(BuildContext context) { diff --git a/lib/network_api_service/api_urls/api_urls.dart b/lib/network_api_service/api_urls/api_urls.dart index 1c45d37..569cb39 100644 --- a/lib/network_api_service/api_urls/api_urls.dart +++ b/lib/network_api_service/api_urls/api_urls.dart @@ -1,8 +1,8 @@ class ApiUrls { // static const baseUrl = "https://devapi.citycards.betadelivery.com"; // Normal API - static const baseUrl = "https://testingapi.citycards.betadelivery.com"; // Test API - // static const baseUrl = "https://uatapi.citycard.betadelivery.com"; // Production Lvl API + // static const baseUrl = "https://testingapi.citycards.betadelivery.com"; // Test API + static const baseUrl = "https://uatapi.citycard.betadelivery.com"; // Production Lvl API static const refreshToken = "$baseUrl/partner/auth/refresh"; diff --git a/lib/profile/views/profile_page.dart b/lib/profile/views/profile_page.dart index 1abefcc..4b79460 100644 --- a/lib/profile/views/profile_page.dart +++ b/lib/profile/views/profile_page.dart @@ -7,6 +7,7 @@ import '../blocs/profile/profile_bloc.dart'; import '../blocs/profile/profile_event.dart'; import '../blocs/profile/profile_state.dart'; import '../models/profile_model.dart'; // Import UserDetails model +import '../../login/blocs/login/login_bloc.dart'; class ProfileScreen extends StatelessWidget { const ProfileScreen({super.key}); @@ -192,6 +193,7 @@ class ProfileScreen extends StatelessWidget { child: ElevatedButton( onPressed: () { LocalPreference.clearAllExceptOnBoarding(); + context.read().add(const LoginReset()); Navigator.pushNamedAndRemoveUntil( context, AppRouter.login, diff --git a/lib/scan/bloc/submit_qr_code/submit_qr_code_bloc.dart b/lib/scan/bloc/submit_qr_code/submit_qr_code_bloc.dart index 02a5a85..b41d216 100644 --- a/lib/scan/bloc/submit_qr_code/submit_qr_code_bloc.dart +++ b/lib/scan/bloc/submit_qr_code/submit_qr_code_bloc.dart @@ -21,6 +21,7 @@ class SubmitQrCodeBloc SubmitQrCodeEventTriggered event, Emitter emit, ) async { + if (state is SubmitQrCodeLoading) return; if (event.qrCode.trim().isEmpty) { emit(const SubmitQrCodeFailure( errorMessage: 'QR code cannot be empty')); diff --git a/lib/scan/view/qr_scan_screen.dart b/lib/scan/view/qr_scan_screen.dart index a4c70ca..fda2c55 100644 --- a/lib/scan/view/qr_scan_screen.dart +++ b/lib/scan/view/qr_scan_screen.dart @@ -24,6 +24,7 @@ class _QrScanScreenState extends State late MobileScannerController _cameraController; final ValueNotifier _isTorchOn = ValueNotifier(false); bool _cameraAvailable = true; + bool _isScanProcessing = false; final sheetContentKey = GlobalKey(); final ValueNotifier sheetExtent = ValueNotifier(0.5); @@ -85,6 +86,7 @@ class _QrScanScreenState extends State if (!mounted || !_cameraAvailable) return; try { + _isScanProcessing = false; // Reset flag when camera starts if (!_cameraController.value.isStarting) { await _cameraController.start(); } @@ -179,22 +181,25 @@ class _QrScanScreenState extends State /// 📷 QR Scanner MobileScanner( - controller: _cameraController, - fit: BoxFit.cover, - onDetect: (capture) { - final barcode = - capture.barcodes.first.rawValue ?? ''; - if (barcode.isNotEmpty && - state is! SubmitQrCodeLoading && - state is SubmitQrCodeInitial) { - final extractedCode = _extractQrCode(barcode); - _cameraController.stop(); - context.read().add( - SubmitQrCodeEventTriggered( - qrCode: extractedCode)); - } - }, - ), + controller: _cameraController, + fit: BoxFit.cover, + onDetect: (capture) { + if (_isScanProcessing) return; + + final barcode = + capture.barcodes.first.rawValue ?? ''; + if (barcode.isNotEmpty && + state is! SubmitQrCodeLoading && + state is SubmitQrCodeInitial) { + _isScanProcessing = true; + final extractedCode = _extractQrCode(barcode); + _cameraController.stop(); + context.read().add( + SubmitQrCodeEventTriggered( + qrCode: extractedCode)); + } + }, + ), /// 🔲 Scanner Frame if (_cameraAvailable)