pub repository
mirror.p-hatan.comisolate_channel
0.6.1Communication channels for isolates based on Flutter's platform channels
Cached in Iran · Upstream SHA-256 matched
Readme
isolate_channel
PubStats Popularity PubStats Rank PubStats Dependents
Communication channels for isolates based on Flutter's platform channels
Features
- Helper functions to spawn, setup, and connect to isolates
- Method channels for making method calls to an isolate and receiving the result
- Event channels for receiving streamed events from an isolate
Usage
In the parent isolate, use the spawnIsolate function to spawn a new isolate and connect to it
final connection = await spawnIsolate(isolateEntryPoint);
In the newly spawned isolate, use the setupIsolate function to set up the isolate for channel communication
void isolateEntryPoint(SendPort? send) {
final connection = setupIsolate(send);
}
Now create communication channels in both isolates
final methodChannel = IsolateMethodChannel('method_channel', connection);
final eventChannel = IsolateEventChannel('event_channel', connection);
Set up handlers for the channels in the newly spawned isolate
methodChannel.setMethodCallHandler((call) {
switch (call.method) {
case 'example_method':
print(call.arguments);
return 'World!';
default:
return call.notImplemented();
}
});
eventChannel.setStreamHandler(
IsolateStreamHandler.inline(
onListen: (arguments, sink) {
sink.success(arguments);
sink.error(
code: 'error',
message: 'Something went wrong',
details: 1234,
);
sink.endOfStream();
},
onCancel: (arguments) => print('Canceled: $arguments'),
),
);
Now you can use the channels to communicate
final result = await methodChannel.invokeMethod('example_method', 'Hello');
final stream = eventChannel.receiveBroadcastStream();
And close the connection when you're done
connection.close();
Connect to a running isolate
Pass an isolate's send port to the connectToIsolate function to connect to it. A send port can be retrieved from an IsolateNameServer.
final connection = await connectToIsolate(send);
Changelog
0.6.1
- Fixes README
0.6.0
- Adds
onSendPortReadyinsetupIsolateto support headless restarts - The
IsolateEntryPointandsetupIsolatefunctions now accept a nullablesendparameter to support headless restarts - The
connectToIsolatefunction now supportsonExitandonErrorcallback setup
0.5.0
- Exposes the
spawnIsolateConnectionfunction that allows connecting to custom isolates - Removes the
spawnparameters from thespawnIsolateandspawnUriIsolatefunctions
0.4.2
- Updates README to reflect that
connectToIsolatereturns aFuture
0.4.1
- Loosens constraint on
meta
0.4.0
- Allows passing an
IsolateSpawnerto support custom isolate implementations such asFlutterIsolate - Makes
connectToIsolatereturn aFutureso that connection failure can be handled
0.3.0
- Removes unnecessary type parameters from spawn methods
0.2.2+1
- Adds README badges
0.2.2
- Handles more edge cases in
IsolateEventChannel
0.2.1
- Does not cancel handler subscription when
onCancelis called inIsolateEventChannel
0.2.0
- BREAKING: Refactors
IsolateException.notImplemented(...)intocall.notImplemented() - Supports communication between isolates spawned with
Isolate.spawnUri - EventChannel optimizations
0.1.1
- Handles exceptions thrown in method call handlers
0.1.0
- Initial release
Installing
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.com
flutter pub add isolate_channelpubspec.yaml
name: isolate_channel
description: Communication channels for isolates based on Flutter's platform channels
homepage: https://github.com/IO-Design-Team/isolate_channel
version: 0.6.1
environment:
sdk: ^3.0.0
dependencies:
meta: ^1.14.0
dev_dependencies:
test: ^1.24.0
rexios_lints: ^17.0.2
mockito: ^5.4.5
build_runner: ^2.4.15
isolate_name_server: ^1.1.0
Version history
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 0.1.0 | 2025-03-12T20:14:29.517097Z | Cached | 4aef81d4fb8fa36d59821914d4f763471877acb80e748c88095e9b33036b9848 |
| 0.1.1 | 2025-03-12T23:43:42.024086Z | Cached | 5c8795d36a25c31448e2a479861eb28afa3e95906f6bc1c62184af29cfe691f3 |
| 0.2.0 | 2025-03-17T23:40:13.967232Z | Cached | b667af2d970626e9df41fcddcdd4fedae009e1148f79e10674b1572e73b6b17f |
| 0.2.1 | 2025-03-23T15:16:24.922896Z | Cached | 70f80485767374a8c61c6fbde8cc014a7f401915d9ec72d916a077f2fd86bc1c |
| 0.2.2 | 2025-03-25T12:20:51.755705Z | Cached | bafedfbcc1e9796ada179b5dac7043b33eb85d35204b089ca37d480d9c0068df |
| 0.2.2+1 | 2025-05-22T19:09:54.952244Z | Cached | f3d36f783b301e6b312c3450eeb2656b0e7d1db81331af2a151d9083a3f6b18d |
| 0.3.0 | 2026-01-13T13:58:13.278991Z | Cached | 68191008e3a219bc87cc8cddbcd1e29810bd9f3a0fdc2108b574ccbd9aafda08 |
| 0.4.0 | 2026-01-21T19:47:00.376423Z | Cached | ef888e59c2b471033f6154ccf54e9f40712c7646ef101f6f91fe55c7d6f1f073 |
| 0.4.1 | 2026-01-21T19:56:09.600880Z | Cached | 000d617d021a608186b468584bbc6df2509ecba048f08510f832fdb9cf7aafbe |
| 0.4.2 | 2026-01-27T17:23:36.810700Z | Cached | d9e706ce2b0d871c9e05dcdf6fc0e35b0ce90c59ebfcdb3aba5d221ba228a087 |
| 0.5.0 | 2026-02-02T15:55:15.118785Z | Cached | 99f991fbfd915017bc99df5fa06fdb70648d977fd2712bcca1527c7609f050a4 |
| 0.6.0 | 2026-02-02T23:25:51.053139Z | Cached | 30116dae19310e3d31706adc5a185070d42ade3fc7ea411b6069df3dc18a1284 |
| 0.6.1 | 2026-02-06T03:09:16.323997Z | Cached | a9d3d620695bc984244dafae00b95e4319d6974b2d77f4b9e1eb4f2efe099094 |
Dependencies
meta "^1.14.0"