Dart Isolate Error: Illegal argument in isolate message: object is unsendable
14:26 26 Mar 2025

I'm trying to use Dart isolates to offload JSON parsing in my Flutter package. However, when I run the following function, I get an error about an "unsendable object" in isolate messages.

Future?> _extractResponse(String url) async {
  try {
    final response = await fetchWithRetry(url, maxAttempts: maxAttempts ?? 3);
    if (response.statusCode == 200) {
      print('fetching result');
      final jsonMap = await Isolate.run(() {
        return _requestAndContent(response.body);
      });...

Error

Invalid argument(s): Illegal argument in isolate message: object is unsendable 
- Library:'dart:async' Class: _Future@4048458
(see restrictions listed at `SendPort.send()` documentation for more information)
 <- _streamFuture in Instance of '_HttpClientConnection' (from dart:_http)
 <- hashCode in Instance of '_HashSetEntry<_HttpClientConnection>' (from dart:collection)
 <- _List len:8 (from dart:core)
 <- _buckets in Instance of '_HashSet<_HttpClientConnection>' (from dart:collection)
 <- _idle in Instance of '_ConnectionTarget' (from dart:_http)
 <- value in Instance of '_HashMapEntry' (from dart:collection)
 <- _List len:8 (from dart:core)...
  • Changing _requestAndContent to be synchronous instead of async
  • response.body.toString()
dart dart-isolates dart-async