flutter_webhid 0.2.0 copy "flutter_webhid: ^0.2.0" to clipboard
flutter_webhid: ^0.2.0 copied to clipboard

Platformweb

WebHID API bindings for Dart and Flutter. Access HID devices from web applications using the modern WebHID standard.

flutter_webhid #

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+).

Installation #

dependencies:
  flutter_webhid: ^0.1.0

Usage #

import '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.

API #

WebHID #

  • WebHID.isSupported - Check if WebHID is available
  • WebHID.instance - Get the WebHID interface
  • requestDevice(options) - Request user permission for devices
  • getDevices() - Get previously authorized devices
  • onConnect / onDisconnect - Device connection events

Device #

  • open() / close() / forget() - Device lifecycle
  • sendReport(reportId, data) - Send output report
  • sendFeatureReport(reportId, data) - Send feature report
  • receiveFeatureReport(reportId) - Receive feature report
  • onInputReport - Stream of input reports
  • vendorId, productId, productName - Device info
  • collections - HID collection descriptors

Types #

  • RequestOptions - Device request options with filters
  • DeviceFilter - Filter by vendorId, productId, usagePage, usage
  • ConnectionEvent - Device connection/disconnection event
  • InputReportEvent - Input report with data
  • CollectionInfo, ReportInfo, ReportItem - HID descriptors

License #

MIT

1
likes
140
points
64
downloads

Documentation

API reference

Publisher

verified publisherphdesign.cc

Weekly Downloads

WebHID API bindings for Dart and Flutter. Access HID devices from web applications using the modern WebHID standard.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

web

More

Packages that depend on flutter_webhid