简体   繁体   中英

Flutter how to add a tabbarview using SliverToBoxAdapter?

i trying to use tabbarview to see a new bar on my application, but nothing im trying worked, someone can help me?

this is my code:

SliverToBoxAdapter _buildRegionTabBar() { //brasil e mundo
    return SliverToBoxAdapter(
      child: DefaultTabController(
        length: 2,
        child: Container(
          margin: const EdgeInsets.symmetric(horizontal: 20.0),
          height: 50.0,
          decoration: BoxDecoration(
            color: Colors.white24,
            borderRadius: BorderRadius.circular(25.0),
          ),
          child: TabBar(
            indicator: BubbleTabIndicator(
              tabBarIndicatorSize: TabBarIndicatorSize.tab,
              indicatorHeight: 40.0,
              indicatorColor: Colors.white,
            ),
            labelStyle: Styles.tabTextStyle,
            labelColor: Colors.black,
            unselectedLabelColor: Colors.white,
            tabs: <Widget>[
              Tab (text:'Brasil'),
              Tab (text:'Mundo'),
            ],
            onTap: (index) {},
          ),
        ),
      ),
    );
  }
class ExampleTabbar extends StatelessWidget {
  const ExampleTabbar({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Material(
      child: DefaultTabController(
          length: 2,
          child: NestedScrollView(
              key: PageStorageKey<String>('keepTabScroll'),
              headerSliverBuilder: (context, _) {
                return [
                  SliverOverlapAbsorber(
                    handle: NestedScrollView.sliverOverlapAbsorberHandleFor(
                        context),
                    sliver: SliverAppBar(
                      title: Text("Tabbar"),
                      forceElevated: _,
                      bottom: TabBar(tabs: [
                        Tab(
                          text: 'Tab A',
                        ),
                        Tab(
                          text: 'Tab B',
                        ),
                      ]),
                    ),
                  )
                ];
              },
              body: TabBarView(
                children: [
                  TabA(),
                  TabB(),
                ],
              ))),
    );
  }
}

class TabA extends StatelessWidget {
  const TabA({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return CustomScrollView(
      slivers: [
        SliverOverlapInjector(
            handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context)),
        SliverPadding(
          padding: EdgeInsets.symmetric(vertical: 24, horizontal: 16),
          sliver: SliverToBoxAdapter(
            child: Text("Tab A"),
          ),
        )
      ],
    );
  }
}

class TabB extends StatelessWidget {
  const TabB({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return CustomScrollView(
      slivers: [
        SliverOverlapInjector(
            handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context)),
        SliverPadding(
          padding: EdgeInsets.symmetric(vertical: 24, horizontal: 16),
          sliver: SliverToBoxAdapter(
            child: Text("Tab B"),
          ),
        )
      ],
    );
  }
}



The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM