Is there a way to make a thread using the flutter and return the result of the processing on the screen?
I have the following code. In the main class _MyHomePageState I have the layout and function _processo () . The idea is to start the _process () function, create the IsolateRunner , Runner will call the _processar which will do a procedure and return, meanwhile the user can access the app and call other threads.
My problem is in the return, because I can not display this return on the screen, for example, I tried to return in the status variable and directly in the _process () function. 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>..
}