在颤抖中动态制作TabBarView

时间:2020-08-13 19:03:38

标签: list flutter tabs tabbar

情况:

我有两个列表,tabsTextmainListAllPlantDetailsList1
tabsText

  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;
      }
    }
  }
}

在这里,我已经检查了tabsTextmainListAllPlantDetailsList1。如果tabsText的特定索引的字符串等于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循环或随意提出任何建议来实现所需的功能?

0 个答案:

没有答案