setState() doesn't execute until the enclosing function returns
问题 So I was trying this code in flutter: void main() => runApp(MyApp()); class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State<MyApp> { int _i = 1; @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: Center( child: MaterialButton( child: Text('You Pressed Me $_i'), onPressed: () { setState(() { _i++; print('inside i = $_i'); }); sleep(Duration(seconds: 10)); _i++; print('outside i = $_i');