Home > Software engineering >  Correct TabBarView usage
Correct TabBarView usage

Time:09-27

my code getting 32x tabs from JSON and putting them to Appbar as scrollable. Now I am looking for a way to execute a categoryListTile according to selection Tab and send correct id number to categoryListTile widget on another page.

unfortunately I cannot find a correct way to do this.

List<Tab> tabs = <Tab>[];
            for (int i = 0; i < snapshot.data!.data!.length; i  ) {
              tabs.add(
                Tab(
                  child: Text(' ${name?[i].name}'.toUpperCase()),
                ),
              );
            }
            return DefaultTabController(
              length: snapshot.data!.data!.length,
              child: Scaffold(
                appBar: AppBar(
                  centerTitle: true,
                  title: Image.asset("assets/images/logo.png",
                      fit: BoxFit.contain, height: 22),
                  bottom: TabBar(
                      indicatorColor: Colors.black,
                      isScrollable: true,
                      tabs: tabs),
                ),
                body: TabBarView(
                  children: categoryListTile(name!, id!, context),
                ),
              ),
            );
          }

I am pretty sure this is completely wrong but how can I to do this

CodePudding user response:

try replace body:

body: TabBarView(
              children:  [for (final tab in snapshot.data!.data!) categoryListTile(tab.name!, tab.id!, context)],
            ),
  • Related