for循环列表,如果有相同就不添加,但不是说不相同就添加
showLiveTab() {
print('是否显示直播tab$canShowLiveTab');
bool isExistence = false;
for (int i = 0; i < itemNames.length; i++) {
if (itemNames[i].name == '直播1') {
isExistence = true;//有不相同的就标记,下面就不添加,而不是else语句,不相同就添加上去,记住这个是遍历语句
}
}
if (!isExistence) {
itemNames.insert(
1,
_Item('直播1', 'assets/images/icon_direct_seeding_tap.png',
'assets/images/icon_direct_seeding_tap_normal.png'),
);
pages.insert(1, DirectSeedingPage());
}
itemWidth = Global.screenWidth / 5;
canShowLiveTab = true;
mySetState(() {
});
}