【问题标题】:how to populate flutter tabBar using an api response如何使用 api 响应填充颤振 tabBar
【发布时间】:2020-01-26 15:25:00
【问题描述】:

如何使用 api 响应(字符串数组)在颤振中填充 TabBar,而不是像这样的硬编码文本..

TabBar(
            isScrollable: true,
            tabs: [
              Tab(
                text: 'text1',
              ),
              Tab(
                text: 'text2',
              ),
              Tab(
                text: 'text3',
              ),

            ],

【问题讨论】:

标签: api flutter backend flutter-layout tabbar


【解决方案1】:

动态TabBar可以使用下面的代码

TabBar(
  isScrollable: true,
  tabs: List<Widget>.generate(
    apiResponse.length,
    (int index) {
      return Container(
        child: new Tab(
          child: Text("Api Response $index"),
        ),
      );
    },
  ),
);

【讨论】:

  • 非常感谢,我会尝试您的解决方案,但是如何将静态选项卡附加到动态选项卡列表?
  • 创建一个类似这样的列表 List apiResponse = new List();并为该列表分配一个响应。例如,apiResponse = getData["results"][index]["text"];.
猜你喜欢
  • 2018-11-07
  • 1970-01-01
  • 2020-09-01
  • 2021-04-12
  • 2016-02-14
  • 2022-01-01
  • 2018-10-10
  • 1970-01-01
  • 2021-10-28
相关资源
最近更新 更多