forked from yaso_meth/mih-project
add android and IOS check before scanner
This commit is contained in:
@@ -11,8 +11,6 @@ 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/components/mih_card_display.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
// import 'package:flutter/services.dart';
|
||||
// import 'package:flutter_barcode_scanner/flutter_barcode_scanner.dart';
|
||||
import 'package:mobile_scanner/mobile_scanner.dart';
|
||||
import 'package:simple_barcode_scanner/simple_barcode_scanner.dart';
|
||||
|
||||
@@ -33,7 +31,10 @@ class _LoyaltyCardsState extends State<LoyaltyCards> {
|
||||
late Future<List<MIHLoyaltyCard>> cardList;
|
||||
//bool showSelectedCardType = false;
|
||||
final ValueNotifier<String> shopName = ValueNotifier("");
|
||||
final MobileScannerController scannerController = MobileScannerController();
|
||||
final MobileScannerController scannerController = MobileScannerController(
|
||||
detectionSpeed: DetectionSpeed.unrestricted,
|
||||
);
|
||||
final boxFit = BoxFit.contain;
|
||||
|
||||
void foundCode(BarcodeCapture bcode) {
|
||||
if (bcode.barcodes.first.rawValue != null) {
|
||||
@@ -46,30 +47,38 @@ class _LoyaltyCardsState extends State<LoyaltyCards> {
|
||||
}
|
||||
}
|
||||
|
||||
void openscanner() {
|
||||
showDialog(
|
||||
barrierDismissible: false,
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return MIHWindow(
|
||||
fullscreen: false,
|
||||
windowTitle: "Scanner",
|
||||
windowBody: [
|
||||
Expanded(
|
||||
child: MobileScanner(
|
||||
controller: scannerController,
|
||||
onDetect: foundCode,
|
||||
),
|
||||
),
|
||||
],
|
||||
windowTools: [],
|
||||
onWindowTapClose: () {
|
||||
scannerController.stop();
|
||||
Navigator.pop(context);
|
||||
},
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void addCardWindow(BuildContext ctxt) {
|
||||
@@ -145,48 +154,8 @@ class _LoyaltyCardsState extends State<LoyaltyCards> {
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
MIHButton(
|
||||
onTap:
|
||||
// () async {
|
||||
// String bcodeScanResults;
|
||||
// try {
|
||||
// bcodeScanResults = await FlutterBarcodeScanner.scanBarcode(
|
||||
// '#ff6666',
|
||||
// 'Cancel',
|
||||
// true,
|
||||
// ScanMode.BARCODE,
|
||||
// );
|
||||
// } on PlatformException {
|
||||
// bcodeScanResults = "Platform not supported";
|
||||
// }
|
||||
|
||||
// if (!mounted) return;
|
||||
// setState(() {
|
||||
// cardNumberController.text = bcodeScanResults;
|
||||
// });
|
||||
// },
|
||||
// () {
|
||||
// openscanner();
|
||||
// },
|
||||
() async {
|
||||
print("here");
|
||||
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;
|
||||
});
|
||||
}
|
||||
onTap: () async {
|
||||
openscanner();
|
||||
},
|
||||
buttonText: "Scan",
|
||||
buttonColor:
|
||||
|
||||
Reference in New Issue
Block a user