From 26de41f96b0af00186c09af29d9a0a54c8d2b8e9 Mon Sep 17 00:00:00 2001 From: Yasien Mac Mini Date: Wed, 5 Mar 2025 13:08:46 +0200 Subject: [PATCH 1/5] remove simple barcode scanner --- Frontend/ios/Podfile.lock | 12 ---- Frontend/pubspec.lock | 64 ------------------- Frontend/pubspec.yaml | 2 +- .../flutter/generated_plugin_registrant.cc | 6 -- .../windows/flutter/generated_plugins.cmake | 2 - 5 files changed, 1 insertion(+), 85 deletions(-) diff --git a/Frontend/ios/Podfile.lock b/Frontend/ios/Podfile.lock index 8a14a1cb..ccb1a848 100644 --- a/Frontend/ios/Podfile.lock +++ b/Frontend/ios/Podfile.lock @@ -98,8 +98,6 @@ PODS: - "no_screenshot (0.0.1+4)": - Flutter - ScreenProtectorKit (~> 1.3.1) - - permission_handler_apple (9.3.0): - - Flutter - printing (1.0.0): - Flutter - PromisesObjC (2.4.0) @@ -110,8 +108,6 @@ PODS: - shared_preferences_foundation (0.0.1): - Flutter - FlutterMacOS - - simple_barcode_scanner (0.1.7): - - Flutter - SwiftyGif (5.4.5) - syncfusion_flutter_pdfviewer (0.0.1): - Flutter @@ -132,10 +128,8 @@ DEPENDENCIES: - local_auth_darwin (from `.symlinks/plugins/local_auth_darwin/darwin`) - mobile_scanner (from `.symlinks/plugins/mobile_scanner/ios`) - no_screenshot (from `.symlinks/plugins/no_screenshot/ios`) - - permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`) - printing (from `.symlinks/plugins/printing/ios`) - shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`) - - simple_barcode_scanner (from `.symlinks/plugins/simple_barcode_scanner/ios`) - syncfusion_flutter_pdfviewer (from `.symlinks/plugins/syncfusion_flutter_pdfviewer/ios`) - url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`) - webview_flutter_wkwebview (from `.symlinks/plugins/webview_flutter_wkwebview/darwin`) @@ -180,14 +174,10 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/mobile_scanner/ios" no_screenshot: :path: ".symlinks/plugins/no_screenshot/ios" - permission_handler_apple: - :path: ".symlinks/plugins/permission_handler_apple/ios" printing: :path: ".symlinks/plugins/printing/ios" shared_preferences_foundation: :path: ".symlinks/plugins/shared_preferences_foundation/darwin" - simple_barcode_scanner: - :path: ".symlinks/plugins/simple_barcode_scanner/ios" syncfusion_flutter_pdfviewer: :path: ".symlinks/plugins/syncfusion_flutter_pdfviewer/ios" url_launcher_ios: @@ -218,13 +208,11 @@ SPEC CHECKSUMS: mobile_scanner: af8f71879eaba2bbcb4d86c6a462c3c0e7f23036 nanopb: fad817b59e0457d11a5dfbde799381cd727c1275 no_screenshot: 6d183496405a3ab709a67a54e5cd0f639e94729e - permission_handler_apple: 4ed2196e43d0651e8ff7ca3483a069d469701f2d printing: 54ff03f28fe9ba3aa93358afb80a8595a071dd07 PromisesObjC: f5707f49cb48b9636751c5b2e7d227e43fba9f47 ScreenProtectorKit: 83a6281b02c7a5902ee6eac4f5045f674e902ae4 SDWebImage: 73c6079366fea25fa4bb9640d5fb58f0893facd8 shared_preferences_foundation: 9e1978ff2562383bd5676f64ec4e9aa8fa06a6f7 - simple_barcode_scanner: f1217b91fbad5848d37fa6d794f443416fd3e44d SwiftyGif: 706c60cf65fa2bc5ee0313beece843c8eb8194d4 syncfusion_flutter_pdfviewer: dfb514751af5b6b71e504c9c04a2e4ddbc1dd895 url_launcher_ios: 694010445543906933d732453a59da0a173ae33d diff --git a/Frontend/pubspec.lock b/Frontend/pubspec.lock index c39e76f4..8294055c 100644 --- a/Frontend/pubspec.lock +++ b/Frontend/pubspec.lock @@ -904,54 +904,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.4" - permission_handler: - dependency: transitive - description: - name: permission_handler - sha256: "18bf33f7fefbd812f37e72091a15575e72d5318854877e0e4035a24ac1113ecb" - url: "https://pub.dev" - source: hosted - version: "11.3.1" - permission_handler_android: - dependency: transitive - description: - name: permission_handler_android - sha256: "71bbecfee799e65aff7c744761a57e817e73b738fedf62ab7afd5593da21f9f1" - url: "https://pub.dev" - source: hosted - version: "12.0.13" - permission_handler_apple: - dependency: transitive - description: - name: permission_handler_apple - sha256: e6f6d73b12438ef13e648c4ae56bd106ec60d17e90a59c4545db6781229082a0 - url: "https://pub.dev" - source: hosted - version: "9.4.5" - permission_handler_html: - dependency: transitive - description: - name: permission_handler_html - sha256: "38f000e83355abb3392140f6bc3030660cfaef189e1f87824facb76300b4ff24" - url: "https://pub.dev" - source: hosted - version: "0.1.3+5" - permission_handler_platform_interface: - dependency: transitive - description: - name: permission_handler_platform_interface - sha256: e9c8eadee926c4532d0305dff94b85bf961f16759c3af791486613152af4b4f9 - url: "https://pub.dev" - source: hosted - version: "4.2.3" - permission_handler_windows: - dependency: transitive - description: - name: permission_handler_windows - sha256: "1a790728016f79a41216d88672dbc5df30e686e811ad4e698bfc51f76ad91f1e" - url: "https://pub.dev" - source: hosted - version: "0.2.1" petitparser: dependency: transitive description: @@ -1120,14 +1072,6 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.1" - simple_barcode_scanner: - dependency: "direct main" - description: - name: simple_barcode_scanner - sha256: "2b6ec05e10fbf4f07687f3687c5cf46d3dcf873492e0a5758211bd957c854113" - url: "https://pub.dev" - source: hosted - version: "0.3.0" simple_gesture_detector: dependency: transitive description: @@ -1493,14 +1437,6 @@ packages: url: "https://pub.dev" source: hosted version: "3.18.1" - webview_windows: - dependency: transitive - description: - name: webview_windows - sha256: "47fcad5875a45db29dbb5c9e6709bf5c88dcc429049872701343f91ed7255730" - url: "https://pub.dev" - source: hosted - version: "0.4.0" win32: dependency: transitive description: diff --git a/Frontend/pubspec.yaml b/Frontend/pubspec.yaml index 0c09137d..a6301b84 100644 --- a/Frontend/pubspec.yaml +++ b/Frontend/pubspec.yaml @@ -59,7 +59,7 @@ dependencies: table_calendar: ^3.1.2 flutter_swipe_detector: ^2.0.0 youtube_player_iframe: ^5.2.0 - simple_barcode_scanner: ^0.3.0 + # simple_barcode_scanner: ^0.3.0 mobile_scanner: ^6.0.6 flutter_launcher_icons: ^0.13.1 # flutter_barcode_scanner: ^2.0.0 diff --git a/Frontend/windows/flutter/generated_plugin_registrant.cc b/Frontend/windows/flutter/generated_plugin_registrant.cc index 47f41a76..67aa4f33 100644 --- a/Frontend/windows/flutter/generated_plugin_registrant.cc +++ b/Frontend/windows/flutter/generated_plugin_registrant.cc @@ -10,11 +10,9 @@ #include #include #include -#include #include #include #include -#include void RegisterPlugins(flutter::PluginRegistry* registry) { FlDownloaderPluginCApiRegisterWithRegistrar( @@ -25,14 +23,10 @@ void RegisterPlugins(flutter::PluginRegistry* registry) { registry->GetRegistrarForPlugin("GeolocatorWindows")); LocalAuthPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("LocalAuthPlugin")); - PermissionHandlerWindowsPluginRegisterWithRegistrar( - registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin")); PrintingPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("PrintingPlugin")); SyncfusionPdfviewerWindowsPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("SyncfusionPdfviewerWindowsPlugin")); UrlLauncherWindowsRegisterWithRegistrar( registry->GetRegistrarForPlugin("UrlLauncherWindows")); - WebviewWindowsPluginRegisterWithRegistrar( - registry->GetRegistrarForPlugin("WebviewWindowsPlugin")); } diff --git a/Frontend/windows/flutter/generated_plugins.cmake b/Frontend/windows/flutter/generated_plugins.cmake index 3deed762..524b0632 100644 --- a/Frontend/windows/flutter/generated_plugins.cmake +++ b/Frontend/windows/flutter/generated_plugins.cmake @@ -7,11 +7,9 @@ list(APPEND FLUTTER_PLUGIN_LIST flutter_tts geolocator_windows local_auth_windows - permission_handler_windows printing syncfusion_pdfviewer_windows url_launcher_windows - webview_windows ) list(APPEND FLUTTER_FFI_PLUGIN_LIST From 41e4b6ae689e71054c27dbdb02d7278fee4c5470 Mon Sep 17 00:00:00 2001 From: Yasien Mac Mini Date: Wed, 5 Mar 2025 13:09:27 +0200 Subject: [PATCH 2/5] remove code for simple barcode scanner --- .../lib/mih_packages/mih_home/mih_home.dart | 42 +++---------- .../mzansi_wallet/loyalty_cards.dart | 63 +++++++++---------- 2 files changed, 39 insertions(+), 66 deletions(-) diff --git a/Frontend/lib/mih_packages/mih_home/mih_home.dart b/Frontend/lib/mih_packages/mih_home/mih_home.dart index 2e4f0ab3..5392d4d7 100644 --- a/Frontend/lib/mih_packages/mih_home/mih_home.dart +++ b/Frontend/lib/mih_packages/mih_home/mih_home.dart @@ -8,7 +8,6 @@ import 'package:flutter/services.dart'; import 'package:flutter_swipe_detector/flutter_swipe_detector.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:google_nav_bar/google_nav_bar.dart'; -import 'package:simple_barcode_scanner/simple_barcode_scanner.dart'; import '../../main.dart'; import 'package:supertokens_flutter/http.dart' as http; import "package:universal_html/html.dart" as html; @@ -607,42 +606,17 @@ class _MIHHomeState extends State { s: getSec(), )); tileList.add(MIHTile( - onTap: () async { - if (MzanziInnovationHub.of(context)!.theme.getPlatform() == "Web") { - print("================ Web ===================="); - print("here 1"); - try { - String? res = await SimpleBarcodeScanner.scanBarcode( - context, - barcodeAppBar: const BarcodeAppBar( - appBarTitle: 'Scan Barcode', - centerTitle: true, - enableBackButton: true, - backButtonIcon: Icon(Icons.arrow_back), - ), - isShowFlashIcon: true, - delayMillis: 500, - cameraFace: CameraFace.back, - scanFormat: ScanFormat.ONLY_BARCODE, - ); - if (res != null) { - print(res); - } - } catch (error) { - print(error); - } - } else { - TextEditingController cardNumberController = - TextEditingController(); - Navigator.of(context).pushNamed( - '/scanner', - arguments: cardNumberController, - ); - } + onTap: () { + TextEditingController cardNumberController = TextEditingController(); + Navigator.of(context).pushNamed( + '/scanner', + arguments: cardNumberController, + ); + print(cardNumberController.text); }, tileName: "Scanner - Dev", tileIcon: Icon( - Icons.scanner, + Icons.camera_alt_outlined, color: getSec(), size: 230, ), diff --git a/Frontend/lib/mih_packages/mzansi_wallet/loyalty_cards.dart b/Frontend/lib/mih_packages/mzansi_wallet/loyalty_cards.dart index 49288792..072f6b96 100644 --- a/Frontend/lib/mih_packages/mzansi_wallet/loyalty_cards.dart +++ b/Frontend/lib/mih_packages/mzansi_wallet/loyalty_cards.dart @@ -13,7 +13,6 @@ import 'package:Mzansi_Innovation_Hub/mih_packages/mzansi_wallet/builder/build_l import 'package:Mzansi_Innovation_Hub/mih_packages/mzansi_wallet/components/mih_card_display.dart'; import 'package:flutter/material.dart'; import 'package:mobile_scanner/mobile_scanner.dart'; -import 'package:simple_barcode_scanner/simple_barcode_scanner.dart'; class LoyaltyCards extends StatefulWidget { final AppUser signedInUser; @@ -53,37 +52,37 @@ class _LoyaltyCardsState extends State { } void openscanner() async { - if (MzanziInnovationHub.of(context)!.theme.getPlatform() == "Web") { - print("================ Web ===================="); - print("here 1"); - try { - String? res = await SimpleBarcodeScanner.scanBarcode( - context, - barcodeAppBar: const BarcodeAppBar( - appBarTitle: 'Scan Barcode', - centerTitle: true, - enableBackButton: true, - backButtonIcon: Icon(Icons.arrow_back), - ), - isShowFlashIcon: true, - delayMillis: 500, - cameraFace: CameraFace.back, - scanFormat: ScanFormat.ONLY_BARCODE, - ); - if (res != null) { - setState(() { - cardNumberController.text = res; - }); - } - } catch (error) { - print(error); - } - } else { - Navigator.of(context).pushNamed( - '/scanner', - arguments: cardNumberController, - ); - } + // if (MzanziInnovationHub.of(context)!.theme.getPlatform() == "Web") { + // print("================ Web ===================="); + // print("here 1"); + // try { + // String? res = await SimpleBarcodeScanner.scanBarcode( + // context, + // barcodeAppBar: const BarcodeAppBar( + // appBarTitle: 'Scan Barcode', + // centerTitle: true, + // enableBackButton: true, + // backButtonIcon: Icon(Icons.arrow_back), + // ), + // isShowFlashIcon: true, + // delayMillis: 500, + // cameraFace: CameraFace.back, + // scanFormat: ScanFormat.ONLY_BARCODE, + // ); + // if (res != null) { + // setState(() { + // cardNumberController.text = res; + // }); + // } + // } catch (error) { + // print(error); + // } + // } else { + Navigator.of(context).pushNamed( + '/scanner', + arguments: cardNumberController, + ); + // } } void addCardWindow(BuildContext ctxt) { From fd7a3dd64e9f0c6a0f7dc313be24aee925358173 Mon Sep 17 00:00:00 2001 From: Yasien Mac Mini Date: Wed, 5 Mar 2025 13:09:49 +0200 Subject: [PATCH 3/5] enhance scanner with correewct state management --- .../mzansi_wallet/mih_barcode_scanner.dart | 63 +++++++++++++++++-- 1 file changed, 57 insertions(+), 6 deletions(-) diff --git a/Frontend/lib/mih_packages/mzansi_wallet/mih_barcode_scanner.dart b/Frontend/lib/mih_packages/mzansi_wallet/mih_barcode_scanner.dart index e98efec0..08ef651e 100644 --- a/Frontend/lib/mih_packages/mzansi_wallet/mih_barcode_scanner.dart +++ b/Frontend/lib/mih_packages/mzansi_wallet/mih_barcode_scanner.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:Mzansi_Innovation_Hub/main.dart'; import 'package:Mzansi_Innovation_Hub/mih_components/mih_inputs_and_buttons/mih_button.dart'; import 'package:flutter/material.dart'; @@ -14,22 +16,70 @@ class MihBarcodeScanner extends StatefulWidget { State createState() => _MihBarcodeScannerState(); } -class _MihBarcodeScannerState extends State { - final MobileScannerController scannerController = MobileScannerController( +class _MihBarcodeScannerState extends State + with WidgetsBindingObserver { + final MobileScannerController _scannerController = MobileScannerController( detectionSpeed: DetectionSpeed.normal, ); + StreamSubscription? _subscription; + bool _isScannerStarting = false; void foundCode(BarcodeCapture bcode) { - if (bcode.barcodes.first.rawValue != null) { + if (bcode.barcodes.isNotEmpty && bcode.barcodes.first.rawValue != null) { setState(() { widget.cardNumberController.text = bcode.barcodes.first.rawValue!; }); - //print(bcode.barcodes.first.rawValue); - scannerController.stop(); + print(bcode.barcodes.first.rawValue); + _scannerController.stop(); Navigator.of(context).pop(); } } + @override + void didChangeAppLifecycleState(AppLifecycleState state) { + if (!_scannerController.value.hasCameraPermission) { + return; + } + switch (state) { + case AppLifecycleState.detached: + case AppLifecycleState.hidden: + case AppLifecycleState.paused: + return; + case AppLifecycleState.resumed: + if (!_scannerController.value.isRunning && !_isScannerStarting) { + _isScannerStarting = true; + _subscription = _scannerController.barcodes.listen(foundCode); + unawaited(_scannerController.start().then((_) { + _isScannerStarting = false; + })); + } + case AppLifecycleState.inactive: + unawaited(_subscription?.cancel()); + _subscription = null; + unawaited(_scannerController.stop().then((_) { + _isScannerStarting = false; + })); + } + } + + @override + Future dispose() async { + // TODO: implement dispose + WidgetsBinding.instance.removeObserver(this); + unawaited(_subscription?.cancel()); + _subscription = null; + super.dispose(); + await _scannerController.dispose(); + } + + @override + void initState() { + super.initState(); + WidgetsBinding.instance.addObserver(this); + _subscription = _scannerController.barcodes.listen(foundCode); + unawaited(_scannerController.start()); + } + @override Widget build(BuildContext context) { return SafeArea( @@ -37,6 +87,7 @@ class _MihBarcodeScannerState extends State { body: Stack( children: [ MobileScanner( + controller: _scannerController, onDetect: foundCode, ), Align( @@ -66,7 +117,7 @@ class _MihBarcodeScannerState extends State { padding: const EdgeInsets.all(10.0), child: MIHButton( onTap: () { - scannerController.stop(); + _scannerController.stop(); Navigator.of(context).pop(); }, buttonText: "Cancel", From 05aabec4ade095faf2d1afd1cddbb5749ff5e3af Mon Sep 17 00:00:00 2001 From: Yasien Mac Mini Date: Wed, 5 Mar 2025 13:33:39 +0200 Subject: [PATCH 4/5] android build fix --- Frontend/android/app/build.gradle | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Frontend/android/app/build.gradle b/Frontend/android/app/build.gradle index 794f7bdb..0ce8babc 100644 --- a/Frontend/android/app/build.gradle +++ b/Frontend/android/app/build.gradle @@ -83,7 +83,8 @@ flutter { } dependencies { - implementation("com.google.android.material:material:") + // implementation("com.google.android.material:material:") + implementation("com.google.android.material:material:1.12.0") // implementation 'com.huawei.agconnect:agconnect-core:1.5.2.300' } From 887881bb849c0b976ad33805ef6ae5bf3a957683 Mon Sep 17 00:00:00 2001 From: Yasien Mac Mini Date: Wed, 5 Mar 2025 13:49:31 +0200 Subject: [PATCH 5/5] remove multiple foundcode calls --- .../mih_packages/mzansi_wallet/mih_barcode_scanner.dart | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Frontend/lib/mih_packages/mzansi_wallet/mih_barcode_scanner.dart b/Frontend/lib/mih_packages/mzansi_wallet/mih_barcode_scanner.dart index 08ef651e..e510d9cc 100644 --- a/Frontend/lib/mih_packages/mzansi_wallet/mih_barcode_scanner.dart +++ b/Frontend/lib/mih_packages/mzansi_wallet/mih_barcode_scanner.dart @@ -23,10 +23,15 @@ class _MihBarcodeScannerState extends State ); StreamSubscription? _subscription; bool _isScannerStarting = false; + bool barcodeScanned = false; void foundCode(BarcodeCapture bcode) { - if (bcode.barcodes.isNotEmpty && bcode.barcodes.first.rawValue != null) { + if (mounted && + barcodeScanned == false && + bcode.barcodes.isNotEmpty && + bcode.barcodes.first.rawValue != null) { setState(() { + barcodeScanned = true; widget.cardNumberController.text = bcode.barcodes.first.rawValue!; }); print(bcode.barcodes.first.rawValue);