startScan static method
扫码 isContinuousClick 是否连续点击 true-是 isToastDebug 是否toast 用于测试 true-是
Implementation
static Future<ScanResult?> startScan({
bool isContinuousClick = true,
bool isToastDebug = false,
}) async {
if (isContinuousClick) {
if (isClick) return null;
isClick = true;
Future.delayed(Duration(milliseconds: 500), () => isClick = false);
}
if (isToastDebug) ToastUtils.showLong("调起原生扫码");
Map<String, Object> map = {"isToast": isToastDebug};
try {
var result = await _channel.invokeMethod('startScan', map) as Map;
final scanType = result['scanType'] as int;
final scanTypeForm = result['scanTypeForm'] as int;
final value = result['value'] != null ? result['value'] as String : null;
final valueByte =
result['valueByte'] != null ? result['valueByte'] as List<int> : null;
print("========> scanType: $scanType");
print("========> scanTypeForm: $scanTypeForm");
print("========> value: $value");
print("========> valueByte: $valueByte");
ScanResult scanResult = ScanResult();
scanResult.scanType = getScanType(scanType);
scanResult.scanTypeForm = getScanTypeFormat(scanTypeForm);
scanResult.value = value;
scanResult.valueByte = valueByte;
if (isToastDebug) ToastUtils.showLong("扫码成功:$value");
return scanResult;
} catch (e) {
print(e);
ToastUtils.showLong("调起扫码失败:$e");
return null;
}
}