FakeUsbPlatform class

In-memory UsbPlatform for tests.

Tests configure devices, toggles, and delays; then construct the class under test with UsbConnection.withPlatform or UsbDiscovery.enumerateWith.

Exposed under package:flutter_zpl_printer/flutter_zpl_printer_testing.dart so consumer apps can reuse it in their own widget/integration tests.

Implemented types

Constructors

FakeUsbPlatform()

Properties

devices → List<UsbDeviceRecord>
Devices that enumerate returns (filtered by VID when filter.vendorId != null).
final
enumerateError ↔ Object?
If set, enumerate throws this instead of returning a list.
getter/setter pair
hashCode → int
The hash code for this object.
no setterinherited
isSupportedResult ↔ bool
Value returned from isSupported.
getter/setter pair
openDelay ↔ Duration
Artificial delay applied inside openForFfi — useful for cancellation tests.
getter/setter pair
openError ↔ Object?
If set, openForFfi throws this instead of returning a handle.
getter/setter pair
permissionGrantResult ↔ bool
Value returned from requestPermission. Default: granted.
getter/setter pair
readError ↔ Object?
If set, readBytes throws this on every call.
getter/setter pair
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
writeError ↔ Object?
If set, writeBytes throws this on every call.
getter/setter pair

Methods

clearHalt({required int handleId, required int endpoint}) → Future<void>
libusb_clear_halt on the given endpoint. Used after LIBUSB_ERROR_PIPE to recover a stalled endpoint.
override
closeAfterFfi(String path) → Future<void>
override
closeHandle({required int handleId}) → Future<void>
Releases the claimed interface and closes the libusb device handle. Also terminates the worker isolate that owned the handle.
override
enumerate(UsbEnumerateFilter filter) → Future<List<UsbDeviceRecord>>
override
hasPermission(String path) → Future<bool>
override
isHandleOpen(int handleId) → bool
isSupported() → Future<bool>
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
openForFfi(String path) → Future<UsbOpenResult>
override
queueRead(int handleId, Uint8List data) → void
Queue a byte buffer that will be returned by the next readBytes call on handleId.
readBytes({required int handleId, required int maxBytes, required int timeoutMs}) → Future<Uint8List>
Reads up to maxBytes from the bulk-IN endpoint. Returns the actual bytes read (may be 0). Throws UsbTransferTimeoutException on timeout.
override
readStringDescriptor({required int handleId, required int index}) → Future<String?>
Reads an ASCII string descriptor at index via libusb_get_string_descriptor_ascii. Returns null on read failure.
override
requestPermission(String path) → Future<bool>
override
resetDevice({required int handleId}) → Future<void>
libusb_reset_device. Caller must treat the handle as invalid after this — typically followed by close + re-open.
override
toString() → String
A string representation of this object.
inherited
writeBytes({required int handleId, required Uint8List data, required int timeoutMs}) → Future<void>
Writes data via libusb_bulk_transfer on the bulk-OUT endpoint associated with the handle. The handle is the UsbOpenResult.platformHandle returned by openForFfi.
override
writesFor(int handleId) → List<Uint8List>
Writes recorded for an open handle. Empty after closeHandle.

Operators

operator ==(Object other) → bool
The equality operator.
inherited