cross_isolate_messenger 0.0.1 copy "cross_isolate_messenger: ^0.0.1" to clipboard
cross_isolate_messenger: ^0.0.1 copied to clipboard

A lightweight utility for message passing between Dart isolates with persistent storage using SharedPreferences. Designed for native Flutter apps.

๐Ÿ“จ Cross Isolate Messenger #

januscaler

pub package

All Contributors

Cross Isolate Messenger is a lightweight Dart utility for message passing and persistence across multiple Dart isolates in Flutter applications.

It uses SharedPreferences under the hood for durability, making it ideal for native platforms (Android, iOS, macOS) where isolates might need to resume processing messages after being restarted or delayed.


โœจ Features #

  • ๐Ÿ”„ Message persistence: Messages are stored in SharedPreferences until acknowledged.
  • ๐Ÿšฆ Isolate communication: Broadcast messages across Dart isolates using named channels.
  • ๐Ÿง  LRU cache-based deduplication: Prevents duplicate processing across restarts or replay.
  • ๐Ÿงฑ Generic and extensible: Supports custom classes via decoders and multiple message streams via unique portNames.

๐Ÿงฉ Requirements #

โœ… Native platforms only โ€“ This package relies on SharedPreferences, so it will not function on web or unsupported platforms like Windows or Linux (without SharedPreferences support).

๐Ÿ›  Usage #

1. Create an instance (per channel) #

final queue = CrossIsolateQueue<Map<String, dynamic>>.getInstance('chat_channel');
await queue.initialize();

queue.stream.listen((msg) {
  print('Received message: $msg');
});

2. Send a message from another isolate #

await CrossIsolateQueue.send('chat_channel', {
  'id': 'message-001',
  'content': 'Hello from another isolate!',
});

3. Acknowledge a message #

await queue.ack('message-001');

๐Ÿ” Custom Message Types #

Define a class and a decoder:

class MyMessage {
  final String id;
  final String content;

  MyMessage(this.id, this.content);

  factory MyMessage.fromJson(Map<String, dynamic> json) =>
      MyMessage(json['id'], json['content']);
}

Use the decoder when creating the queue:

final customQueue = CrossIsolateQueue<MyMessage>.getInstance(
  'custom_channel',
  decoder: (json) => MyMessage.fromJson(json),
);
await customQueue.initialize();

๐Ÿงผ Clean Up #

await queue.dispose();

โš  Limitations #

  • โŒ Not supported on web or desktop platforms without SharedPreferences.


๐Ÿ“„ License #

MIT

๐Ÿ‘ท TODO #

  • โŒ Add fallback for unsupported platforms
  • โŒ Add testing harness for isolate message passing
1
likes
155
points
43
downloads

Documentation

API reference

Publisher

verified publisherjanuscaler.com

Weekly Downloads

A lightweight utility for message passing between Dart isolates with persistent storage using SharedPreferences. Designed for native Flutter apps.

Homepage

License

MIT (license)

Dependencies

flutter, shared_preferences

More

Packages that depend on cross_isolate_messenger