Skip to content

Instantly share code, notes, and snippets.

@rodydavis
Last active February 2, 2023 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodydavis/4256d0e54a0ad491c1ff6a34969d6186 to your computer and use it in GitHub Desktop.
Save rodydavis/4256d0e54a0ad491c1ff6a34969d6186 to your computer and use it in GitHub Desktop.
Cross platform Flutter compute method
export 'run.io.dart' if (dart.library.html) 'run.web.dart';
import 'dart:io';
import 'package:flutter/foundation.dart';
Future<T> run<T, R>(Future<T> Function(R args) callback, R args) async {
final testing = Platform.environment.containsKey('FLUTTER_TEST');
if (testing) return callback(args);
return compute(callback, args);
}
Future<T> run<T, R>(Future<T> Function(R args) callback, R args) async {
return callback(args);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment