mobile scanner used

This commit is contained in:
2024-11-25 17:23:48 +02:00
parent 3afec7ca1c
commit 7ecf338c6c
5 changed files with 112 additions and 64 deletions

View File

@@ -5,8 +5,9 @@ import 'package:flutter/services.dart';
import 'package:flutter_swipe_detector/flutter_swipe_detector.dart'; import 'package:flutter_swipe_detector/flutter_swipe_detector.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:google_nav_bar/google_nav_bar.dart'; import 'package:google_nav_bar/google_nav_bar.dart';
import 'package:simple_barcode_scanner/screens/web.dart'; import 'package:mobile_scanner/mobile_scanner.dart';
import 'package:simple_barcode_scanner/simple_barcode_scanner.dart'; // import 'package:simple_barcode_scanner/screens/web.dart';
// import 'package:simple_barcode_scanner/simple_barcode_scanner.dart';
import '../../main.dart'; import '../../main.dart';
//import 'package:supertokens_flutter/http.dart' as http; //import 'package:supertokens_flutter/http.dart' as http;
import "package:universal_html/html.dart" as html; import "package:universal_html/html.dart" as html;
@@ -78,6 +79,9 @@ class _MIHHomeState extends State<MIHHome> {
String appSearch = ""; String appSearch = "";
int amount = 10; int amount = 10;
final baseAPI = AppEnviroment.baseApiUrl; final baseAPI = AppEnviroment.baseApiUrl;
final MobileScannerController scannerController = MobileScannerController(
// required options for the scanner
);
void setAppsNewPersonal(List<MIHTile> tileList) { void setAppsNewPersonal(List<MIHTile> tileList) {
if (widget.signedInUser.fname == "") { if (widget.signedInUser.fname == "") {
@@ -333,6 +337,14 @@ class _MIHHomeState extends State<MIHHome> {
)); ));
} }
void foundCode(BarcodeCapture bcode) {
if (bcode.barcodes.first.rawValue != null) {
print(bcode.barcodes.first.rawValue);
scannerController.stop();
Navigator.of(context).pop();
}
}
void setAppsDev(List<MIHTile> tileList) { void setAppsDev(List<MIHTile> tileList) {
if (AppEnviroment.getEnv() == "Dev") { if (AppEnviroment.getEnv() == "Dev") {
tileList.add(MIHTile( tileList.add(MIHTile(
@@ -350,24 +362,15 @@ class _MIHHomeState extends State<MIHHome> {
// return const MIHErrorMessage(errorType: "Invalid Credentials"); // return const MIHErrorMessage(errorType: "Invalid Credentials");
return MIHWindow( return MIHWindow(
fullscreen: false, fullscreen: false,
windowTitle: windowTitle: "Scanner",
"Test Window title that is too large for mobile devices",
windowBody: [ windowBody: [
SizedBox( SizedBox(
height: 700, height: 1000,
child: BarcodeScanner( child: MobileScanner(
lineColor: "#ff6666", controller: scannerController,
cancelButtonText: "Cancel", onDetect: foundCode,
isShowFlashIcon: false,
scanType: ScanType.qr,
cameraFace: CameraFace.back,
//barcodeAppBar: barcodeAppBar,
delayMillis: 500,
scanFormat: ScanFormat.ALL_FORMATS,
onScanned: (res) => Navigator.pop(context, res),
//child: child,
),
), ),
)
], ],
windowTools: [], windowTools: [],
onWindowTapClose: () { onWindowTapClose: () {

View File

@@ -4,14 +4,15 @@ import 'package:Mzansi_Innovation_Hub/mih_components/mih_inputs_and_buttons/mih_
import 'package:Mzansi_Innovation_Hub/mih_components/mih_inputs_and_buttons/mih_dropdown_input.dart'; import 'package:Mzansi_Innovation_Hub/mih_components/mih_inputs_and_buttons/mih_dropdown_input.dart';
import 'package:Mzansi_Innovation_Hub/mih_components/mih_inputs_and_buttons/mih_text_input.dart'; import 'package:Mzansi_Innovation_Hub/mih_components/mih_inputs_and_buttons/mih_text_input.dart';
import 'package:Mzansi_Innovation_Hub/mih_components/mih_layout/mih_window.dart'; import 'package:Mzansi_Innovation_Hub/mih_components/mih_layout/mih_window.dart';
import 'package:Mzansi_Innovation_Hub/mih_components/mih_pop_up_messages/mih_error_message.dart';
import 'package:Mzansi_Innovation_Hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart'; import 'package:Mzansi_Innovation_Hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart';
import 'package:Mzansi_Innovation_Hub/mih_objects/app_user.dart'; import 'package:Mzansi_Innovation_Hub/mih_objects/app_user.dart';
import 'package:Mzansi_Innovation_Hub/mih_objects/loyalty_card.dart'; import 'package:Mzansi_Innovation_Hub/mih_objects/loyalty_card.dart';
import 'package:Mzansi_Innovation_Hub/mih_packages/mzansi_wallet/builder/build_loyalty_card_list.dart'; import 'package:Mzansi_Innovation_Hub/mih_packages/mzansi_wallet/builder/build_loyalty_card_list.dart';
import 'package:Mzansi_Innovation_Hub/mih_packages/mzansi_wallet/components/mih_card_display.dart'; import 'package:Mzansi_Innovation_Hub/mih_packages/mzansi_wallet/components/mih_card_display.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:qr_bar_code_scanner_dialog/qr_bar_code_scanner_dialog.dart'; import 'package:mobile_scanner/mobile_scanner.dart';
import 'package:simple_barcode_scanner/simple_barcode_scanner.dart'; // import 'package:simple_barcode_scanner/simple_barcode_scanner.dart';
class LoyaltyCards extends StatefulWidget { class LoyaltyCards extends StatefulWidget {
final AppUser signedInUser; final AppUser signedInUser;
@@ -30,8 +31,45 @@ class _LoyaltyCardsState extends State<LoyaltyCards> {
late Future<List<MIHLoyaltyCard>> cardList; late Future<List<MIHLoyaltyCard>> cardList;
//bool showSelectedCardType = false; //bool showSelectedCardType = false;
final ValueNotifier<String> shopName = ValueNotifier(""); final ValueNotifier<String> shopName = ValueNotifier("");
final _qrBarCodeScannerDialogPlugin = QrBarCodeScannerDialog(); final MobileScannerController scannerController = MobileScannerController();
String? code;
void foundCode(BarcodeCapture bcode) {
if (bcode.barcodes.first.rawValue != null) {
setState(() {
cardNumberController.text = bcode.barcodes.first.rawValue!;
});
//print(bcode.barcodes.first.rawValue);
scannerController.stop();
Navigator.of(context).pop();
}
}
void openscanner() {
showDialog(
barrierDismissible: false,
context: context,
builder: (context) {
return MIHWindow(
fullscreen: false,
windowTitle: "Scanner",
windowBody: [
SizedBox(
height: 1000,
child: MobileScanner(
controller: scannerController,
onDetect: foundCode,
),
)
],
windowTools: [],
onWindowTapClose: () {
scannerController.stop();
Navigator.pop(context);
},
);
},
);
}
void addCardWindow(BuildContext ctxt) { void addCardWindow(BuildContext ctxt) {
showDialog( showDialog(
@@ -104,26 +142,29 @@ class _LoyaltyCardsState extends State<LoyaltyCards> {
), ),
const SizedBox(width: 10), const SizedBox(width: 10),
MIHButton( MIHButton(
onTap: () async { onTap: () {
String? res = await SimpleBarcodeScanner.scanBarcode( openscanner();
context,
barcodeAppBar: const BarcodeAppBar(
appBarTitle: 'Test',
centerTitle: false,
enableBackButton: true,
backButtonIcon: Icon(Icons.arrow_back_ios),
),
isShowFlashIcon: true,
delayMillis: 500,
cameraFace: CameraFace.back,
scanFormat: ScanFormat.ONLY_BARCODE,
);
if (res != null) {
setState(() {
cardNumberController.text = res;
});
}
}, },
// () async {
// String? res = await SimpleBarcodeScanner.scanBarcode(
// context,
// barcodeAppBar: const BarcodeAppBar(
// appBarTitle: 'Scan Bardcode',
// 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;
// });
// }
// },
buttonText: "Scan", buttonText: "Scan",
buttonColor: buttonColor:
MzanziInnovationHub.of(context)!.theme.secondaryColor(), MzanziInnovationHub.of(context)!.theme.secondaryColor(),
@@ -138,6 +179,15 @@ class _LoyaltyCardsState extends State<LoyaltyCards> {
height: 50, height: 50,
child: MIHButton( child: MIHButton(
onTap: () { onTap: () {
if (shopController.text == "" ||
cardNumberController.text == "") {
showDialog(
context: context,
builder: (context) {
return const MIHErrorMessage(errorType: "Input Error");
},
);
} else {
MIHMzansiWalletApis.addLoyaltyCardAPICall( MIHMzansiWalletApis.addLoyaltyCardAPICall(
widget.signedInUser, widget.signedInUser,
widget.signedInUser.app_id, widget.signedInUser.app_id,
@@ -145,6 +195,7 @@ class _LoyaltyCardsState extends State<LoyaltyCards> {
cardNumberController.text, cardNumberController.text,
context, context,
); );
}
}, },
buttonText: "Add", buttonText: "Add",
buttonColor: buttonColor:

View File

@@ -9,6 +9,7 @@ import app_links
import device_info_plus import device_info_plus
import firebase_core import firebase_core
import geolocator_apple import geolocator_apple
import mobile_scanner
import no_screenshot import no_screenshot
import path_provider_foundation import path_provider_foundation
import printing import printing
@@ -22,6 +23,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin")) DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
FLTFirebaseCorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCorePlugin")) FLTFirebaseCorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCorePlugin"))
GeolocatorPlugin.register(with: registry.registrar(forPlugin: "GeolocatorPlugin")) GeolocatorPlugin.register(with: registry.registrar(forPlugin: "GeolocatorPlugin"))
MobileScannerPlugin.register(with: registry.registrar(forPlugin: "MobileScannerPlugin"))
NoScreenshotPlugin.register(with: registry.registrar(forPlugin: "NoScreenshotPlugin")) NoScreenshotPlugin.register(with: registry.registrar(forPlugin: "NoScreenshotPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
PrintingPlugin.register(with: registry.registrar(forPlugin: "PrintingPlugin")) PrintingPlugin.register(with: registry.registrar(forPlugin: "PrintingPlugin"))

View File

@@ -720,6 +720,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.0.5" version: "1.0.5"
mobile_scanner:
dependency: "direct main"
description:
name: mobile_scanner
sha256: "728828a798d1a2ee506beb652ca23d974c542c96ed03dcbd5eaf97bef96cdaad"
url: "https://pub.dev"
source: hosted
version: "6.0.2"
mutex: mutex:
dependency: transitive dependency: transitive
description: description:
@@ -960,22 +968,6 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "3.0.2" version: "3.0.2"
qr_bar_code_scanner_dialog:
dependency: "direct main"
description:
name: qr_bar_code_scanner_dialog
sha256: dcb937816d4e562141530265bd1ca39fe00f57000fd79e26c163c957d443e9e4
url: "https://pub.dev"
source: hosted
version: "0.0.5"
qr_code_scanner:
dependency: transitive
description:
name: qr_code_scanner
sha256: f23b68d893505a424f0bd2e324ebea71ed88465d572d26bb8d2e78a4749591fd
url: "https://pub.dev"
source: hosted
version: "1.0.1"
realtime_client: realtime_client:
dependency: transitive dependency: transitive
description: description:

View File

@@ -63,7 +63,7 @@ dependencies:
youtube_player_iframe: ^5.2.0 youtube_player_iframe: ^5.2.0
syncfusion_flutter_barcodes: ^26.2.10 syncfusion_flutter_barcodes: ^26.2.10
simple_barcode_scanner: ^0.2.5 simple_barcode_scanner: ^0.2.5
qr_bar_code_scanner_dialog: ^0.0.5 mobile_scanner: ^6.0.2
dev_dependencies: dev_dependencies:
flutter_test: flutter_test: