October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

Share State Across Dart Isolates with shared_map: How It Works

Dart isolates do not share ordinary mutable objects. shared_map offers a map-like client that sends requests to an owning isolate, with important performance and platform limits.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

shared_map lets Dart isolates access map-like state through messages to an owning isolate; it does not make a mutable Map directly shareable between heaps. Create the map in the owner, pass its shared reference to another isolate, and construct a client-side SharedMap there. This approach is for Dart Native: isolates are unavailable on Flutter web.

Can Dart isolates share a Map?

Not as an ordinary live mutable object. Dart gives each isolate its own memory and event loop, and isolates communicate by message passing. As Dart’s concurrency guide puts it, “Each isolate has its own global fields, ensuring that none of the state in an isolate is accessible from any other isolate.”

As an Amazon Associate I earn from qualifying purchases.

shared_map provides a map-like interface over that boundary. One isolate owns the map; client instances in other isolates send requests to it. A client’s get or put therefore involves a message to the owner rather than direct reads or writes to the same in-memory Map.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How do you pass a SharedMap to another isolate?

The package documentation’s workflow is to create a SharedStore and map in the owning isolate, obtain a shared reference, send that reference to the worker, then build a client facade there. This is a shape of the documented example, not independently tested code. Confirm the method names against the package version pinned in your project: the documentation prose uses shareReference(), while the visible example and API reference use sharedReference().

final store = SharedStore('store-id');
final map = await store.getSharedMap<String, int>('map-id');
final reference = map!.sharedReference();

final result = await Isolate.run(() async {
  final client = SharedMap<String, int>.fromSharedReference(reference);
  return client.get('key');
});

See the package documentation for setup and the SharedMap API reference for the current class API. The example assumes the map exists and is non-null; handle a missing map according to your application’s needs rather than relying on the null assertion in production code.

What happens to reads and writes?

The owner remains the authoritative map instance. Auxiliary-isolate clients use the package’s API to request operations; they do not gain direct access to the owner’s heap. The package documentation says each auxiliary get or put triggers an isolate message to the server-side map.

The API also documents update(key, updater) as running the updater in the same memory context or isolate as the main instance. That can keep mutation logic with the owner while callers use the client abstraction. The documentation does not establish a broader lock-free sharing model or specify consistency guarantees beyond the described behavior, so do not treat the API as a substitute for understanding ownership and operation ordering.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When does shared_map make sense?

Choose the communication model to fit the work. Dart’s concurrency guide recommends Isolate.run() for a single computation and Isolate.spawn() for a worker that handles multiple messages over time. shared_map is an option when multiple isolates need map-like access routed through an owner.

  • One-off work: use a single computation and pass the needed input, then use its returned result.
  • Repeated worker tasks: consider a long-lived worker rather than repeatedly starting short-lived isolates.
  • Repeated map operations: account for the messages involved in client access. The package suggests SharedMapCache to avoid unnecessary isolate requests, but publishes no quantified performance guarantee or benchmark in the cited documentation.

Flutter’s isolate guide cautions that starting short-lived isolates and copying objects has overhead; a long-lived worker may suit repeated work. Whether this package or another design performs better depends on the actual workload, so benchmark your application rather than assuming a speedup.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What are the platform limits?

dart:isolate is a Dart Native capability; the dart:isolate API documentation describes isolates as workers that do not share memory and communicate by messages. Flutter web does not support isolates: compute() runs on the web main thread, according to the Flutter guide. A design built around isolate references therefore needs a separate web-compatible path.

Flutter isolates also cannot perform widget/UI work or use rootBundle. Background isolates can make platform-channel requests and receive responses, but cannot receive unsolicited host-platform messages, as described in the same Flutter guide.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.