【发布时间】:2021-02-17 11:48:59
【问题描述】:
我一直在尝试在列表视图构建器的末尾添加一个按钮。我试图做这个问题中建议的事情:Flutter: How to add a button widget at the end of a ListView.builder that contains other type of widgets?。但如果我这样做,我会得到:“RangeError (index): Invalid value: Not inclusive range 0..49: 50
我尝试查看也有此问题的问题,但我找不到修复它的答案。
List<Anime> animeList = animeData.animeList;
print(animeList.length);
return ListView.builder(
padding: EdgeInsets.only(bottom: 30, top: 10),
itemBuilder: (context, index) {
Anime anime = animeList[index];
if (index == animeList.length) {
return ThinOutlineBtn(
primaryColor: themeWizard.getPrimaryColor(),
darkColor: themeWizard.getBackgroundColor(),
text: "More",
highlightedBorderColor: themeWizard.getPrimaryColor(),
ontap: () {
AnilistApi.followUpQuery(AnilistApi.animeQuery, animeData,
animeData.animePage.currentPage + 1);
},
);
}
return AnimeCard(
anime: anime,
darkMode: themeWizard.getCurrentMode(),
activeIcon: themeWizard.getPrimaryColor(),
background: themeWizard.getCardColor(),
btnHighlightColor: themeWizard.getBackgroundColor(),
textColor: themeWizard.getCardTextColor(),
inActiveIcon: themeWizard.getIconColor(),
);
},
itemCount: animeList.length + 1,
);
【问题讨论】: