Skip to content

Commit e36c311

Browse files
committed
move to isolate.run
1 parent 8d82e73 commit e36c311

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

isoimg/lib/main.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import 'package:flutter/services.dart';
99
import 'package:image/image.dart' as image;
1010
import 'package:loading_indicator/loading_indicator.dart';
1111

12+
typedef SpawnFunction = Uint8List Function();
13+
1214
void main() {
1315
runApp(const MyApp());
1416
}
@@ -87,15 +89,17 @@ class _MyHomePageState extends State<MyHomePage> {
8789
setState(() {
8890
_loading = true;
8991
});
90-
final Uint8List encoded = await compute(_applySepiaFilter, _image!);
91-
// Alternative with Isolate.run (currently crashes).
92-
// final Uint8List encoded = await Isolate.run(() => _applySepiaFilter(_image!));
92+
final Uint8List encoded = await Isolate.run(_spawn(_image!));
9393
setState(() {
9494
_image = encoded;
9595
_loading = false;
9696
});
9797
}
9898

99+
static SpawnFunction _spawn(Uint8List image) {
100+
return () => _applySepiaFilter(image);
101+
}
102+
99103
void _reset() {
100104
setState(() {
101105
_image = _originalImage;

0 commit comments

Comments
 (0)