Want to use async/HTTP data to return child widgets in an IndexedWidgetBuilder? You can wait for asynchronous computations using a FutureBuilder. I’d probably change your PostPreview to take a Future as a constructor argument and put the FutureBuilder there, but if you want to leave PostPreview as-is, here’s how to modify your itemBuilder.
1 2 3 4 5 6 7 8 9 10 11 12 | var index = new ListView.builder( controller: _scrollController, itemBuilder: (ctx, i) { return new FutureBuilder( future: _posts[i], builder: (context, snapshot) { return snapshot.connectionState == ConnectionState.done ? new PostPreview(snapshot.data) : new Container(); // maybe a show placeholder widget? ); }, ); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.