initialize method
初始化相机控制器
Implementation
Future<void> initialize() async {
if (_isDisposed) return Future<void>.value();
_creatingCompleter = Completer();
try {
final Map<String, dynamic> reply = await (RBarcode._initialize(
value.description!.name,
_serializeResolutionPreset(value.resolutionPreset),
value.isDebug) as FutureOr<Map<String, dynamic>>);
_textureId = reply['textureId'];
await setBarcodeFormats(value.formats ?? RBarcode._globalFormat!);
value = value.copyWith(
isInitialized: true,
previewSize: Size(reply['previewWidth'].toDouble(),
reply['previewHeight'].toDouble()),
formats: value.formats ?? RBarcode._globalFormat);
_resultSubscription = EventChannel('${_kPluginType}_$_textureId/event')
.receiveBroadcastStream()
.listen(_handleResult);
isScanning = true;
} on PlatformException catch (e) {
//当发生权限问题的异常时会抛出
throw RBarcodeException(e.code, e.message);
}
_creatingCompleter!.complete();
return _creatingCompleter!.future;
}