I am new to Flutter and I am trying to get familiar with the flutter_midi_command package. I have an ElevatedButton
and I want to print the list of available MIDI devices on click.
ElevatedButton(
onPressed: () => MidiCommand().devices.then((MidiDevice midiDevice) => print(midiDevice)),
child: const Text('Show available MIDI devices'),
)
But in the .then
part, I am getting the following error as soon as I define the type of the returned value from the callback:
The argument type 'void Function(MidiDevice)' can't be assigned to the parameter type 'FutureOr<dynamic> Function(List<MidiDevice>?)'.
And but when I remove the type (MidiDevice
), the error is removed. I believe I am missing a core concept from Dart/Flutter. My question is, how I am able to simply make this callback function to work when I have the type of the returned value defined?
CodePudding user response:
Try:
ElevatedButton(
onPressed: () {
MidiCommand().devices.then((MidiDevice midiDevice) {
print(midiDevice);
});
},
child: const Text('Show available MIDI devices'),
)
CodePudding user response:
I managed to solve my question. The type of the returned value is not MidiDevice
, its List<MidiDevice>
.
The following is the correct implementation:
ElevatedButton(
onPressed: () => MidiCommand().devices.then((List<MidiDevice>? midiDevice) => print(midiDevice)),
child: const Text('Show available MIDI devices'),
)