0
There is how to thread using the flutter and return the processing result on the screen?
I have the following code. In the main class _Myhomepagestate I have the layout and function _process(). The idea is to start the function _process(), create the Isolaterunner, the Runner will call the function _sue, that will do a procedure and return, while the user can access the app and call other threads.
My problem is in the return, because I can’t display this return on the screen, for example, I’ve tried to return in the variable status and directly in function _process(). From what I understood the return could only occur once, taking into account that only asynchronous functions are accepted.
Future<String> _processar(String foto) async {
for (var i = 0; i < 10; i++) {
sleep(const Duration(seconds:5));
print('Thread - '+i.toString());
}
return 'Ok';
}
class _MyHomePageState extends State<MyHomePage> {
Future<String> status;
final String ass = 'asd';
..<código>..
void _processo() async {
final runner = await IsolateRunner.spawn();
status = runner
.run(_processar, 'foto')
.whenComplete(() => (){
runner.close();
setState(() {
this.ass = status;
});
return this.status;
});
}
..<código>..
}
Why is it being done on a flat? Any particular reason?
– Miguel Ruivo