startBarcodeScannerInternal static method
Future<BarcodeScanningResult>
startBarcodeScannerInternal(
- MethodChannel channel,
- BarcodeScannerConfiguration config
Starts the Ready-to-Use Barcode Scanner UI as full-screen modal UI dialog. The Barcode Scanner is able to recognize 1D- and 2D-barcodes (QR codes, etc).
Implementation
static Future<BarcodeScanningResult> startBarcodeScannerInternal(
MethodChannel channel, BarcodeScannerConfiguration config) async {
try {
Logger.root.log(Level.INFO, "BARCODE init formats");
if (config.barcodeFormats == null) {
config.barcodeFormats = PredefinedBarcodes.allBarcodeTypes();
} else if (config.barcodeFormats!.isEmpty) {
config.barcodeFormats = PredefinedBarcodes.allBarcodeTypes();
}
Logger.root.log(Level.INFO, "BARCODE config to JSON");
var updatedParameters = config.toJson();
const defaultJsonName = "BarcodeScreen";
Logger.root.log(Level.INFO, "BARCODE update default JSON");
var configuration = await applyParametersOnDefaultJson(
defaultJsonName, updatedParameters);
Logger.root.log(Level.INFO, "BARCODE run scanner");
var result = await invoke(channel, 'startBarcodeScanner', configuration);
Logger.root.log(Level.INFO, "BARCODE scanner canceled");
if (wasCanceled(result)) {
return BarcodeScanningResult.canceled();
}
return BarcodeScanningResult.fromJson(jsonDecode(result));
} catch (e) {
Logger.root.severe(e);
return BarcodeScanningResult.error(e.toString());
}
}