How to use the Flutter StreamBuilder for async data?

This Article is posted by niebin312 at 12/15/2018 5:38:31 PM



<p List="" menus=>When you create a list with async data, you may need the StreamBuilder 1. How to use the stream and StreamController.there is the Link: <a href=>https://medium.com/@ayushpguptaapg/using-streams-in-flutter-62fed41662e4</a><a href="https://medium.com/@ayushpguptaapg/using-streams-in-flutter-62fed41662e4">https://medium.com/@ayushpguptaapg/using-streams-in-flutter-62fed41662e4</a>2.create a controller with data >()color:#cc7832;](; color:#cc7832;]( color:#cc7832;]( Stream> color:#cc7832;font-weight:bold;](get color:#9876aa;](menuItems => color:#9876aa;](controller.color:#9876aa;](streamcolor:#cc7832;](; color:#cc7832;]( color:#cc7832;]( MenuController() { color:#9876aa;](controller.add(menus ?? _defaultMenus())color:#cc7832;](; color:#cc7832;]( }</p> <p>color:#cc7832;font-weight:bold;](static String color:#ffc66d;font-style:italic;](_title(index) { color:#cc7832;font-weight:bold;](return _MENU_STRINGS[index % _MENU_STRINGS.color:#9876aa;](length][color:#6a8759;]('title']color:#cc7832;](; color:#cc7832;]( }</p> <p>color:#cc7832;font-weight:bold;](static List color:#ffc66d;font-style:italic;](_items(index) { color:#cc7832;font-weight:bold;](return _MENU_STRINGS[index % _MENU_STRINGS.color:#9876aa;](length][color:#6a8759;]('items']color:#cc7832;](; color:#cc7832;]( }</p> <p>List color:#ffc66d;](_defaultMenus() { color:#cc7832;font-weight:bold;](var list = color:#ffc66d;](List()color:#cc7832;](; color:#cc7832;]( color:#cc7832;font-weight:bold;](for (int i = color:#6897bb;](0color:#cc7832;](; i 3. Use the StreamBuilder [_topBar()color:#cc7832;](, _gridView(shot.color:#9876aa;](data)]color:#cc7832;](, color:#cc7832;]( ) : color:#ffc66d;](Center( child: color:#ffc66d;](CircularProgressIndicator()color:#cc7832;](, color:#cc7832;]( )color:#cc7832;](; color:#cc7832;]( }color:#cc7832;](, color:#cc7832;]( stream: controller.color:#9876aa;](menuItemscolor:#cc7832;](, color:#cc7832;]( )color:#cc7832;](; } you can see the StreamBuilder hold and listen to data for complying the async purpose. You can use the Future, but this is convenience.Whole project: <a href="https://github.com/nb312/flutter_ui_app">https://github.com/nb312/flutter_ui_app</a> ![](../../Uploads/4c840c7c-3451-4c2c-bde4-178490970b8f.pngwidth="50%height="auto](</p>


Tags:








0 Comments
Login to comment.
Recent Comments