您好,登錄后才能下訂單哦!
今天就跟大家聊聊有關flutter中怎么實現多布局列表,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。
多布局功能代碼:
@override void initState() { // TODO: implement initState super.initState(); // 獲取網絡數據 一個banner 一個列表 initBannerData(); initHomeList(); } @override Widget build(BuildContext context) { Widget itemColor = Divider( color: Colors.blue, ); Widget nullColor = Divider( color: Colors.white, ); return ListView.separated( itemCount: _homeListBeanEntity.data.datas.length, itemBuilder: (BuildContext context, int index) { // 根據規則,抽取banner方法和listitem return _bannerBeanData != null && _bannerBeanData.data.length > 0&&index==0 ? bannerItem(_bannerBeanData) : listItem(_homeListBeanEntity, index); }, separatorBuilder: (BuildContext context, int index) { return index > 0 ? itemColor : nullColor; }, ); }
void initBannerData() async { result = await getNetWorkData("https://www.wanandroid.com/banner/json"); print("list=" + result); if (result.toString().length > 0) { BannerBeanEntity bannerBeanEntity = BannerBeanEntity.fromJson(json.decode(result)); if (bannerBeanEntity != null) { setState(() { _bannerBeanData = bannerBeanEntity; }); } } }getNetWorkData(String url) async { var uri = Uri.parse(url); HttpClient httpClient = new HttpClient(); HttpClientRequest request = await httpClient.getUrl(uri); HttpClientResponse httpClientResponse = await request.close(); var str = await httpClientResponse.transform(utf8.decoder).join(); print(httpClientResponse.toString()); return str; } void initHomeList() async { result =await getNetWorkData("https://www.wanandroid.com/article/list/0/json"); print("list=" + result); if (result.toString().length > 0) { HomeListBeanEntity homeListBeanEntity = HomeListBeanEntity.fromJson(json.decode(result)); if (homeListBeanEntity != null) { setState(() { _homeListBeanEntity = homeListBeanEntity; }); } } }
看完上述內容,你們對flutter中怎么實現多布局列表有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業資訊頻道,感謝大家的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。