I'm working on an app that captures and processes an image. A simplified version of the code is:
build() {
return FloatingActionButton(
onPressed: processImage,
child: Icon(
Icons.camera_alt,
color: color,
),
);
}
processImage(Camera image) async {
await image.process();
}
And in another class:
Future<image> process() {
return Future(() {
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
//process image
}
}
});
}
But when process()
is running, the UI freezes.
Why is this happening? Isn't that function passed to Future constructor running in the background?
compute()
function? – Apiarist"The callback argument must be a top-level function, not a closure or an instance or static method of a class"
, and you can only pass one parameter, so I had to convert all my params to aMap<String, dynamic>
, create a top-level function that receives the map, and destructure to original variables. – Epergnecompute()
function or at lower level Isolate stuff – Apiaristcompute()
documentation: > The content of message can be: primitive values (null, num, bool, double, String), instances of SendPort, and lists and maps whose elements are any of these. List and maps are also allowed to be cyclic. – Epergne