I'm trying to execute heavy method by compute()
.
I tried like so.
After loop
executed, Text
widget update but result
returns 0 almost right after button was pressed.
Does anyone know what am I missing?
int _counter;
static int loop(int val) {
int count = 0;
for (int i = 1; i <= val; i++) {
count += i;
}
return count;
}
Future<void> _onPressed() async {
int result = await compute(loop, 1000000000000000000);
setState(() {
_counter = result;
});
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…