Skip to content

requestDevices very unreliable with newest Flutter #15

@iKK001

Description

@iKK001

Updating to Flutter 3.24.5 leads to new errors:

The biggest problem of your library seems the usbDevice.requestDevices([]) cmd !

It is very error prone.

Below is how I use it.

In debug-mode it leads to the error:

"TypeError: Instance of '_USBDevice': type '_USBDevice' is not a subtype of type 'UsbDevice?'"

In release-mode on my local machine it actually works !!

In release-mode on a remote server it leads to the error:

Null check operator used on a null value

Here is my code :
(again, it all happens at the step requestDevices !!!)

UsbDevice? _pairedDevice;
final UsbDevice usbDevice = UsbDevice();

Future<void> _connectToDevice() async {
  try {
    _pairedDevice = await usbDevice.requestDevices(
      [DeviceFilter(vendorId: 0x303a, productId: 0x1001)],
    );

    final deviceInfo = await usbDevice.getPairedDeviceInfo(_pairedDevice!);
    setState(() {
      _status = 'Connected to ${deviceInfo.productName}';
    });
  } catch (e) {
    Utils.showSnackBar(e.toString(), Colors.red);
    setState(() => _status = 'Error: $e');
  }
}

There is so much hiddenly going on with the requestDevices method. Is there any way to somehow debug this on the remote server ? Or can you explain what it does exactly ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions