You should use FutureBuilder widget.
Future<String> _runLongRunningFunction() async {
String result;
for (int i = 0; i < 100000; i++) {
...
}
return result;
}
FutureBuilder<String>(
future: runLongRunningFunction(),
builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
Widget child;
if (snapshot.hasData) {
child = Text(snapshot.data);
} else if (snapshot.hasError) {
child = Text('${snapshot.error}');
} else {
child = CircularProgressIndicator();
}
return Center(
child: child
);
},
);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…