Merge pull request #94 from yaso-meth/BUG--Web-Scanner-not-working

BUG--Web-Scanner-not-working
This commit is contained in:
yaso-meth
2025-03-05 13:50:55 +02:00
committed by GitHub
9 changed files with 104 additions and 158 deletions

View File

@@ -83,7 +83,8 @@ flutter {
}
dependencies {
implementation("com.google.android.material:material:<version>")
// implementation("com.google.android.material:material:<version>")
implementation("com.google.android.material:material:1.12.0")
// implementation 'com.huawei.agconnect:agconnect-core:1.5.2.300'
}

View File

@@ -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

View File

@@ -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<MIHHome> {
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,
),

View File

@@ -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<LoyaltyCards> {
}
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) {

View File

@@ -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,75 @@ class MihBarcodeScanner extends StatefulWidget {
State<MihBarcodeScanner> createState() => _MihBarcodeScannerState();
}
class _MihBarcodeScannerState extends State<MihBarcodeScanner> {
final MobileScannerController scannerController = MobileScannerController(
class _MihBarcodeScannerState extends State<MihBarcodeScanner>
with WidgetsBindingObserver {
final MobileScannerController _scannerController = MobileScannerController(
detectionSpeed: DetectionSpeed.normal,
);
StreamSubscription<Object>? _subscription;
bool _isScannerStarting = false;
bool barcodeScanned = false;
void foundCode(BarcodeCapture bcode) {
if (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);
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<void> 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 +92,7 @@ class _MihBarcodeScannerState extends State<MihBarcodeScanner> {
body: Stack(
children: [
MobileScanner(
controller: _scannerController,
onDetect: foundCode,
),
Align(
@@ -66,7 +122,7 @@ class _MihBarcodeScannerState extends State<MihBarcodeScanner> {
padding: const EdgeInsets.all(10.0),
child: MIHButton(
onTap: () {
scannerController.stop();
_scannerController.stop();
Navigator.of(context).pop();
},
buttonText: "Cancel",

View File

@@ -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:

View File

@@ -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

View File

@@ -10,11 +10,9 @@
#include <flutter_tts/flutter_tts_plugin.h>
#include <geolocator_windows/geolocator_windows.h>
#include <local_auth_windows/local_auth_plugin.h>
#include <permission_handler_windows/permission_handler_windows_plugin.h>
#include <printing/printing_plugin.h>
#include <syncfusion_pdfviewer_windows/syncfusion_pdfviewer_windows_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>
#include <webview_windows/webview_windows_plugin.h>
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"));
}

View File

@@ -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