-
-
Notifications
You must be signed in to change notification settings - Fork 7
Data Transfer and Types
d-markey edited this page Jan 22, 2026
·
5 revisions
When a method is called on a Worker, arguments are passed from the Main Thread to the Worker Thread, and results are passed back. Unlike standard function calls, this involves crossing thread boundaries.
The Dart VM uses SendPort.send().
- Most objects are copied (deep cloned).
- Some objects (like
StringorTransferableTypedData) are transferred efficiently. - The type system is preserved. A
DateTimearrives as aDateTime.
The Browser uses worker.postMessage().
- Data is serialized using the Structured Clone Algorithm.
-
Type Erasure: Dart objects effectively lose their class identity.
-
List<int>might arrive as a generic Array. -
Map<String, int>might arrive as a generic Object or Map. - Custom classes (e.g.
Person) cannot be sent directly without marshaling.
-
- Null (
null) - Booleans (
bool) - Numbers (
int,double- see Converters for Web caveats) - Strings (
String) - Collections (
List,Map,Set) of the above. -
Uint8Listand other TypedData. -
SendPort(Native only, for direct isolate comms).
To send a custom class (e.g., User, Product), you must use a Marshaler.
Next Step: Learn more about Marshaling.
💖 Support the project! Sponsor d-markey on GitHub.