Last active
February 2, 2023 15:51
-
-
Save rodydavis/4256d0e54a0ad491c1ff6a34969d6186 to your computer and use it in GitHub Desktop.
Cross platform Flutter compute method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export 'run.io.dart' if (dart.library.html) 'run.web.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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