Dart bindings for the WebHID API using modern dart:js_interop.
This package has been tested and used in production environments. It provides access to HID devices from web browsers that support the WebHID standard (Chrome/Edge 89+).
dependencies:
flutter_webhid: ^0.1.0import 'package:flutter_webhid/flutter_webhid.dart';
void main() async {
// Check if WebHID is supported
if (!WebHID.isSupported) {
print('WebHID not supported');
return;
}
final webHid = WebHID.instance;
if (webHid == null) return;
// Request device access
final devices = await webHid.requestDevice(
RequestOptions(
filters: [
DeviceFilter(vendorId: 0x1234),
],
),
);
if (devices.isEmpty) return;
final device = devices.first;
// Open and use device
await device.open();
// Listen for input reports
device.onInputReport.listen((event) {
print('Report ${event.reportId}: ${event.data}');
});
// Send output report
await device.sendReport(0, Uint8List.fromList([0x01, 0x02]));
await device.close();
}See example/basic_example.dart for more.
WebHID.isSupported- Check if WebHID is availableWebHID.instance- Get the WebHID interfacerequestDevice(options)- Request user permission for devicesgetDevices()- Get previously authorized devicesonConnect/onDisconnect- Device connection events
open()/close()/forget()- Device lifecyclesendReport(reportId, data)- Send output reportsendFeatureReport(reportId, data)- Send feature reportreceiveFeatureReport(reportId)- Receive feature reportonInputReport- Stream of input reportsvendorId,productId,productName- Device infocollections- HID collection descriptors
RequestOptions- Device request options with filtersDeviceFilter- Filter by vendorId, productId, usagePage, usageConnectionEvent- Device connection/disconnection eventInputReportEvent- Input report with dataCollectionInfo,ReportInfo,ReportItem- HID descriptors
MIT