compute 0.1.0 copy "compute: ^0.1.0" to clipboard
compute: ^0.1.0 copied to clipboard

outdated

Flutter's compute function made available for all non-Flutter Dart programs

compute #

Flutter's compute function made available for all non-Flutter Dart programs

The compute package takes Flutter's compute function and makes it available for all Dart programs.

Continuous Integration codecov compute Published by dartside.dev GitHub Stars Count

**If you enjoy using this package, a thumbs-up on pub.dev would be highly appreciated! 👍💙

Motivation #

Working with isolates, wiring up the SendPorts, the ReceivePorts is a lot of boilerplate code just to spawn an isolate, compute something, and use the computed value.

The compute function is a very useful abstraction over isolates that can be useful in all kinds of Dart apps.

This package addresses this issue. It extracts the compute function from Flutter and makes it available for all Dart projects, so if you wish to perform some computation on a separate isolate and use its return value in a Dart web app, command line tool, or any kind of non-Flutter Dart project, now you can!

Keep in mind, that by using compute, you lose some flexibility that working directly with isolates would enable you. Please also keep in mind that you should benchmark your Dart applications with and without the compute function, and only switch to using compute if it really speeds up your application.

Usage #

Dart #

This package works everywhere and doesn't have any Flutter-specific dependency.

import 'package:compute/compute.dart';

int square(int a) => a * a;

Future<void> main() async {
  final squared = await compute(square, 5);
  print('5^2=$squared');
}

Flutter #

If you are on a Flutter project, you don't need this package. This package should only be used in environments where you cannot use Flutter's compute function.

For your Flutter project, use the compute function directly from Flutter's foundation.

22
likes
0
pub points
88%
popularity

Publisher

verified publisherdartside.dev

Flutter's compute function made available for all non-Flutter Dart programs

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

meta

More

Packages that depend on compute