File tree 1 file changed +7
-3
lines changed
1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ import 'package:flutter/services.dart';
9
9
import 'package:image/image.dart' as image;
10
10
import 'package:loading_indicator/loading_indicator.dart' ;
11
11
12
+ typedef SpawnFunction = Uint8List Function ();
13
+
12
14
void main () {
13
15
runApp (const MyApp ());
14
16
}
@@ -87,15 +89,17 @@ class _MyHomePageState extends State<MyHomePage> {
87
89
setState (() {
88
90
_loading = true ;
89
91
});
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! ));
93
93
setState (() {
94
94
_image = encoded;
95
95
_loading = false ;
96
96
});
97
97
}
98
98
99
+ static SpawnFunction _spawn (Uint8List image) {
100
+ return () => _applySepiaFilter (image);
101
+ }
102
+
99
103
void _reset () {
100
104
setState (() {
101
105
_image = _originalImage;
You can’t perform that action at this time.
0 commit comments