Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic Tabs inside TabBar Widget rather than static ones

Context: I have the current design -shown in a screenshot below - where I implemented the Tabs statically,

Tab Bars

Question: How can we create Tabs on the fly with dynamic values from a server?

For example, a server sends more than 5 Tabs.

My current implementation contains an AppBar that supports a TabBar with Tabs as a list of Widgets

Here's the code snippet for the tab bar:

 bottom: TabBar(
        labelPadding: EdgeInsets.symmetric(horizontal: 20),
        indicatorColor: kDarkColor,
        labelColor: kDarkColor,
        indicatorWeight: 2,
        unselectedLabelColor: Colors.black,
        isScrollable: true,
        tabs: [
          Tab(child: Text('Timeline.mostPopularTab'.tr())),
          Tab(child: Text('Timeline.menTab'.tr())),
          Tab(child: Text('Timeline.womenTab'.tr())),
          Tab(child: Text('Timeline.kidsTab'.tr())),
        ],
      ),
like image 575
Waleed Alrashed Avatar asked Nov 07 '22 07:11

Waleed Alrashed


1 Answers

TabBar(
tabs: _tabsListFromServer.map((serverTab) => Tab(child: Text(serverTab.title))).toList(),
)
like image 112
Muhammad Adam Avatar answered Nov 16 '22 10:11

Muhammad Adam