list - 在颤动中动态制作 TabBarView
问题描述
情况:
我有两个列表,tabsText
并且mainListAllPlantDetailsList1
.
选项卡文本
List<String> tabsText = ["Top","Outdoor","Indoor", "Seeds", "Flowers"];
mainListAllPlantDetailsList1
List<PlantDetails> mainListAllPlantDetailsList1 = [
PlantDetails(
indexNumber: 0,
category: "flower",
plantName: "Lamb's Ear",
price: 147,
description: "This is the Lamb's Ear flower"
),
PlantDetails(
indexNumber: 1,
category: "seeds",
plantName: "Lotus",
price: 120,
description: "This is the lotus seeds"
),
PlantDetails(
indexNumber: 2,
category: "indoor",
plantName: "Hughusi Yoon",
price: 147,
description: "This is the Hughusi Yoon indoor"
),
PlantDetails(
indexNumber: 3,
category: "outdoor",
plantName: "lily",
price: 120,
description: "This is the lily outdoor"
),
];
细节:
我在tabsText
列表中使用 for 循环制作了 TabBar。现在我再次TabBarView
使用 for 循环,我尝试过这样
tabViewerMaker(){
List<Widget> tabBarView = List();
for(var i = 0; i<tabsText.length;i++){
for( var j =0; j<mainListAllPlantDetailsList1.length;j++){
if(tabsText[i] == mainListAllPlantDetailsList1[j].ca){
tabBarView.add(
Text("We found category"+tabsText[i])
);
}
else{
continue;
}
}
}
}
在这里,我检查了tabsText
and mainListAllPlantDetailsList1
。如果特定索引的 StringtabsText
等于 then 的特定索引,mainListAllPlantDetailsList1
则生成一个小部件,
Text("We found category"+tabsText[i])
否则继续。而且我已经列出了类型小部件并添加了所有文本小部件,但是在调用函数时tabViewerMaker
为什么会出错?
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following NoSuchMethodError was thrown building Container(bg: BoxDecoration(color:
Color(0xffffffff)), constraints: BoxConstraints(w=Infinity, h=317.0)):
The getter 'key' was called on null.
问题:
如何使用 for 循环实现所需的功能或随意提出任何建议?
解决方案
推荐阅读
- c++ - MFC、CMap 类迭代器
- android - android PIE中的电话权限
- sql-server - 启用 TR 快照复制时如何识别死锁?
- sql-server - 使用 SQL Server 更新引用的聚合失败并显示“无法插入 ...当 IDENTITY_INSERT 设置为 OFF”
- javascript - 使用 event.target 时,它可以在网站上运行,但代码有错误
- angular - 在 Angular 6 上的库中创建画布
- windows - 在 Windows 操作系统中使用 julia 语言的文本编辑器
- javascript - 我如何动态生成一个完整的 reactJS 应用程序
- vue.js - 如何使用 npm 包依赖
- c++ - 使用线程池并行化函数会使其变慢:为什么?