InvisibleWrench/FlutterMidiCommand

Failed `disconnectDevice`

Closed this issue · 2 comments

I called MidiCommand.disconnectDevice after MidiCommand.connectToDevice.
But I had the following error. (I use a physical iPod touch device.)

[VERBOSE-2:ui_dart_state.cc(186)] Unhandled Exception: PlatformException(MESSAGEERROR, Could not parse device id, {id: D567BA7A-A04C-5A5C-828B-307783CC07CB, name: TD-07 MIDI, type: BLE, connected: false}, null)
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:581:7)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:158:18)

I thought,

if let deviceInfo = call.arguments as? Dictionary<String, String> {
cast to Dictionary<String, String>.
But the argument has boolean connected.
So you may change like connectToDevice.

        case "disconnectDevice":
            if let deviceInfo = call.arguments as? Dictionary<String, Any> {
                if let deviceId = deviceInfo["id"] as? String {
                    disconnectDevice(deviceId: deviceId)
                } else {
                    result(FlutterError.init(code: "MESSAGEERROR", message: "No device Id", details: call.arguments))
                }
                result(nil)
            } else {
                result(FlutterError.init(code: "MESSAGEERROR", message: "Could not parse device id", details: call.arguments))
            }
            result(nil)
            break

Using:
flutter_midi_command: 0.3.0
flutter: 2.0.4
Xcode: 12.4

Thank you for reporting this. I will fix it shortly