Skip to content

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.


How Data Moves

Native (Isolates)

The Dart VM uses SendPort.send().

  • Most objects are copied (deep cloned).
  • Some objects (like String or TransferableTypedData) are transferred efficiently.
  • The type system is preserved. A DateTime arrives as a DateTime.

Web (Web Workers)

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.

Supported Types (Out of the Box)

  • Null (null)
  • Booleans (bool)
  • Numbers (int, double - see Converters for Web caveats)
  • Strings (String)
  • Collections (List, Map, Set) of the above.
  • Uint8List and other TypedData.
  • SendPort (Native only, for direct isolate comms).

Custom Types

To send a custom class (e.g., User, Product), you must use a Marshaler.

Next Step: Learn more about Marshaling.

Clone this wiki locally