addBleDevice method

dynamic addBleDevice(
  1. String deviceId,
  2. String deviceName, {
  3. dynamic waitSettingsState(
    1. String deviceId
    )?,
})

添加 waitSettingsState 等待设备进入设置状态

Implementation

addBleDevice(String deviceId, String deviceName,
    {Function(String deviceId)? waitSettingsState}) async {
  if (waitSettingsState != null) {
    methodChannel.setMethodCallHandler((call) {
      if (call.method == "waitSettingsState") {
        waitSettingsState(call.arguments);
        methodChannel.setMethodCallHandler(null);
      }
      return Future.value("SUCCESS");
    });
  }
  final map = {"deviceId": deviceId, "deviceName": deviceName};
  try {
    return await methodChannel.invokeMethod(MethodName.addBleDevice, map);
  } catch (e) {
    methodChannel.setMethodCallHandler(null);
    rethrow;
  }
}