I am using this Flutter package: usb_device 1.0.2
In debug mode, my Flutter Web Application successfully connects to my USB-Device.
My USB-device is an ESP32-S3.
And I am on Flutter version 3.24.4 • channel stable • https://github.com/flutter/flutter.git
(Dart 3.5.4 • DevTools 2.37.3)
I tried in Chrome, Edge and Safari Browsers.
I am able to successfully connect my USB-device
with the usbDevice.requestDevices(...) cmd inside the browser.
However, if I run my Flutter Web Application in release mode, then the device connection-popup does not show up and an error occurs.
i.e. if I try to run my Flutter Web app with the following cmd (i.e. in release mode), then the device-connection code crashes:
flutter run -d chrome –release
Here is my call of the connect method inside Flutter Web:
Future<void> _connectToDevice() async {
try {
pairedDevice = await usbDevice
.requestDevices([DeviceFilter(vendorId: 0x303a, productId: 0x1001)]);
} catch (e) {
Utils.showSnackBar(e.toString(), Colors.red);
setState(() => _status = 'Error: $e');
}
}
And the following error message is shown:
Invalid argument: Instance of 'minified:UK'
Again, in debug-mode, the very same code works. Its only if I run the Flutter Web App in release mode (i.e. flutter run -d chrome --release
where things crash at that connection-request – i.e. right at the moment when calling pairedDevice = await usbDevice.requestDevices(...)
What can I do to make my Flutter Web application run in release mode ??
2
Answers
In the meantime, I have found a workaround:
I now use this Flutter package, called web_usb
And with some modifications to fit my device (especially concerning the endpoint-addressing), I have a working solution now that fully works also if running in
release
mode:As of the other library usb_device I did not understand the described security issue from the answers and how to circumvent it. Maybe you can show a concrete example ?
FYI as of 2024.12.30 web_usb 0.2.0 example does not compile. install instructions way too simple and no troubleshooting provided. expect to see:
"Error: Type ‘EventListener’ not found"
Target of URI doesn’t exist: ‘ledger_nano_s_page. dart’.
etc..