upgradeFirmware method

  1. @override
void upgradeFirmware({
  1. WriteMode? mode,
  2. required FirmwareUpdate firmwareUpdate,
  3. required BleDeviceCall<String> call,
})
override

Implementation

@override
void upgradeFirmware(
    {WriteMode? mode,
    required FirmwareUpdate firmwareUpdate,
    required BleDeviceCall<String> call}) {
  _channel.setMethodCallHandler(null);
  _channel.setMethodCallHandler((channelCall) {
    if (channelCall.method == "upgradeFirmwareProgress") {
      if (call.otaProgress != null) {
        call.otaProgress!(channelCall.arguments["current"]);
      }
    }
    return Future.value(null);
  });
  _channel.invokeMethod<String>("upgradeFirmware", {
    "mode": mode?.name,
    "firmwareUpdate": json.encode(firmwareUpdate.toMap())
  }).then((version) {
    _channel.setMethodCallHandler(null);
    call.success(version ?? "");
  }).onError((PlatformException error, stackTrace) {
    _channel.setMethodCallHandler(null);
    call.fail(error);
  });
}