prefer_compute_over_isolate_run
v0.4.0 Warning Fix Testing Rules
Flags uses of Isolate.run() from dart:isolate, which is not supported on the web platform. Flutter’s compute() function from package:flutter/foundation.dart provides the same background execution capability while working across all platforms including web.
Why use this rule
Section titled “Why use this rule”Isolate.run() throws at runtime on web targets because web browsers do not support Dart isolates. By using compute() instead, your code works on mobile, desktop, and web without any platform-specific conditional logic.
See also: Flutter - compute() | Dart - Isolate.run()
import 'dart:isolate';
final result = await Isolate.run(() => expensiveWork());final result2 = await Isolate.run(() async => expensiveWork());final result3 = await Isolate.run(expensiveWork);final result4 = await Isolate.run<int>(() => expensiveWork());import 'package:flutter/foundation.dart';
final result = await compute((_) => expensiveWork(), null);Configuration
Section titled “Configuration”To disable this rule:
plugins: many_lints: diagnostics: prefer_compute_over_isolate_run: false