PythonBridge class
An in-process Dart ↔ Python byte channel, backed by the dart_bridge
native library.
Each PythonBridge owns a ReceivePort whose native port doubles as the channel key in both directions:
- Python → Dart: when Python calls
dart_bridge.send_bytes(port, payload), the payload arrives on this bridge's messages stream. - Dart → Python: send hands bytes to the Python handler registered for
this port via
dart_bridge.set_enqueue_handler_func(port, handler).
Multiple bridges (UI channel, logging channel, future camera-stream channel, ...) can coexist in a single app — each bridge has its own port and its own Python-side handler.
Typical use:
final ui = PythonBridge();
final logs = PythonBridge();
ui.messages.listen((Uint8List bytes) { /* UI events */ });
logs.messages.listen((Uint8List bytes) { /* log lines */ });
await SeriousPython.run('app/main.py', environmentVariables: {
'MY_APP_UI_PORT': '${ui.port}',
'MY_APP_LOGS_PORT': '${logs.port}',
});
ui.send(Uint8List.fromList([1, 2, 3]));
The Python side reads the chosen env-var names to discover its port numbers — no convention is baked in here.
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
-
messages
→ Stream<
Uint8List> -
Bytes pushed by Python via
dart_bridge.send_bytes(port, payload).no setter - port → int
-
Dart native port acting as this channel's key. Pass it to the Python
program (typically via an environment variable) so Python knows where
to send messages and which port to register its handler under.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
close(
) → void - Release this bridge's ReceivePort. After closing, send throws and the messages stream emits done.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
send(
Uint8List bytes) → bool -
Send
bytesto the Python handler registered for this bridge's port. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited