import 'package:isolate/isolate.dart'; import 'dart:async'; Future runInBackground( FutureOr Function(U arg) function, U arg) async { final isolate = await IsolateRunner.spawn(); try { return await isolate.run(function, arg); } finally { await isolate.close(); } }