initByCustom static method

Future<void> initByCustom(
  1. String action,
  2. String label, {
  3. PdaDataType dataType = PdaDataType.STRING,
})

自定义初始化扫码枪 action: 广播行为 label: 获取数据的标签

Implementation

static Future<void> initByCustom(
  String action,
  String label, {
  PdaDataType dataType = PdaDataType.STRING,
}) async {
  WidgetsFlutterBinding.ensureInitialized();
  if (!Platform.isAndroid) {
    throw Exception(['PDA插件只支持安卓系统设备!']);
  }
  // 设置通道回调
  _setMethodCallback();
  // 调用安卓初始化PDA方法 标记PDA已进行过初始化
  bool? initSuccess = await _methodChannel.invokeMethod<bool>(
    'initScannerCustom',
    {
      'action': action,
      'label': label,
      'dataType':dataType.name
    },
  );
  if (initSuccess ?? false) {
    _initFlag = true;
    log('PDA扫码器初始化完成', name: logTag);
  }
  // 设置音频
  _loadScanAudioPlayer();
}