FlSerial class
Asynchronous serial port driver for Flutter — web implementation.
Uses the Web Serial API
via dart:js_interop. Requires Chrome 89+ or Edge 89+.
Basic usage
final serial = FlSerial();
serial.events.listen((event) {
if (event.type == SerialEventType.data) {
print(String.fromCharCodes(event.data as Uint8List));
}
});
// "Web Serial Port" is always listed; opening it shows the port picker.
final ports = await FlSerial.availablePorts();
await serial.open(ports.first.path, SerialConfig(baudRate: 115200));
serial.write(Uint8List.fromList('hello\n'.codeUnits));
await serial.close();
await serial.dispose();
Port picker
availablePorts always returns a single synthetic entry with path
web:request. Passing it to open triggers navigator.serial.requestPort()
which shows the browser's native device-picker dialog. This requires a
user gesture — a button tap qualifies.
Properties
-
dataStream
→ Stream<
Uint8List> -
Convenience stream that emits only raw received bytes.
no setter
-
events
→ Stream<
SerialEvent> -
Broadcast stream of all port events (connect, disconnect, data).
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
close(
) → Future< void> - Closes the currently open port and emits SerialEventType.disconnected.
-
dispose(
) → Future< void> - Closes the port and releases all resources.
-
getModemStatus(
) → Map< String, bool> - Always returns all-false on web — modem control lines are not accessible via the Web Serial API.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
open(
String path, SerialConfig config) → Future< bool> - Opens a Web Serial port selected via the browser's port-picker dialog.
-
setDTR(
bool active) → void - No-op on web — the Web Serial API does not expose DTR.
-
setRTS(
bool active) → void - No-op on web — the Web Serial API does not expose RTS.
-
toString(
) → String -
A string representation of this object.
inherited
-
write(
Uint8List data) → void -
Sends
datato the open port (fire-and-forget).
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
availablePorts(
) → Future< List< SerialPortInfo> > - Returns all serial ports currently visible on this device.