# isolate_channel 0.6.1

Communication channels for isolates based on Flutter's platform channels




## Installing
```
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add isolate_channel
```
Published: 2026-02-06T03:09:16.323997Z
Expected archive SHA-256: a9d3d620695bc984244dafae00b95e4319d6974b2d77f4b9e1eb4f2efe099094

Available in cache; verification: upstream_checksum
## Direct dependencies
- meta: ^1.14.0

## Package README (untrusted upstream documentation)
# isolate_channel

[![PubStats Popularity](https://pubstats.dev/badges/packages/isolate_channel/popularity.svg)](https://pubstats.dev/packages/isolate_channel)
[![PubStats Rank](https://pubstats.dev/badges/packages/isolate_channel/rank.svg)](https://pubstats.dev/packages/isolate_channel)
[![PubStats Dependents](https://pubstats.dev/badges/packages/isolate_channel/dependents.svg)](https://pubstats.dev/packages/isolate_channel)

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

```dart
final connection = await spawnIsolate(isolateEntryPoint);
```

In the newly spawned isolate, use the `setupIsolate` function to set up the isolate for channel communication

```dart
void isolateEntryPoint(SendPort? send) {
  final connection = setupIsolate(send);
}
```

Now create communication channels in both isolates

```dart
final methodChannel = IsolateMethodChannel('method_channel', connection);
final eventChannel = IsolateEventChannel('event_channel', connection);
```

Set up handlers for the channels in the newly spawned isolate

```dart
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

```dart
final result = await methodChannel.invokeMethod('example_method', 'Hello');
final stream = eventChannel.receiveBroadcastStream();
```

And close the connection when you're done

```dart
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](https://api.flutter.dev/flutter/dart-ui/IsolateNameServer-class.html).

```dart
final connection = await connectToIsolate(send);
```

## Changelog
## 0.6.1

- Fixes README

## 0.6.0

- Adds `onSendPortReady` in `setupIsolate` to support headless restarts
- The `IsolateEntryPoint` and `setupIsolate` functions now accept a nullable `send` parameter to support headless restarts
- The `connectToIsolate` function now supports `onExit` and `onError` callback setup

## 0.5.0

- Exposes the `spawnIsolateConnection` function that allows connecting to custom isolates
- Removes the `spawn` parameters from the `spawnIsolate` and `spawnUriIsolate` functions

## 0.4.2

- Updates README to reflect that `connectToIsolate` returns a `Future`

## 0.4.1

- Loosens constraint on `meta`

## 0.4.0

- Allows passing an `IsolateSpawner` to support custom isolate implementations such as `FlutterIsolate`
- Makes `connectToIsolate` return a `Future` so 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 `onCancel` is called in `IsolateEventChannel`

## 0.2.0

- BREAKING: Refactors `IsolateException.notImplemented(...)` into `call.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







 
