关于Future的问题
来源:9-2 基于Http实现网络操作
Eric_Guoyh
2019-04-19
老师想问下,fetchpost方法里返回的是CommonModel类,怎么方法名前面的返回值是Future,难道是dart可以自动把CommonModel转化为Future?
写回答
1回答
-
CrazyCodeBoy
2019-04-21
fetchpost 返回的是Future如果要获取CommonModel可以用async await:
Future<Null> _handleRefresh() async { try { HomeModel model = await HomeDao.fetch(); setState(() { localNavList = model.localNavList; subNavList = model.subNavList; gridNavModel = model.gridNav; salesBoxModel = model.salesBox; bannerList = model.bannerList; _loading = false; }); } catch (e) { print(e); setState(() { _loading = false; }); } return null; }
122019-04-23
相似问题