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.
Recommended Free Tools
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().
#1 Best Overall
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.
Rank #2
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.
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.
Rank #3
- 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
SharedMapCacheto 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.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.
Rank #4
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.
Quick Recap
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.




