I often see people trying to execute an asyncronous operation in the render method of a widget. This doesn't work, but is also bad because it gets called every time the state or properties get updated. It can lead to a lot of unneccessary work. A StatefulWidget needs to be used to do this properly.

main.dart

class MyWidget extends StatefulWidget { @override State createState ( ) = > new MyWidgetState ( ) ; } class MyWidgetState extends State < MyWidget > { var _result ; @override void initState ( ) { loadAsyncData ( ) . then ( ( result ) { setState ( ( ) { _result = result ; } ) ; } ) ; } @override Widget build ( BuildContext context ) { if ( _result == null ) { return new Container ( ) ; } return new ResultWidget ( _result ) ; } }

In summary,