Tabbarview inside a Slivertoboxadapter

Asked

Viewed 21 times

0

I need to add a tabbarview inside the Slivertoboxadapter, but nothing I try works. I want to generate a chart for each tab, but I can’t even insert any message. Below is my code:

inserir a descrição da imagem aqui

class StatsScreen extends StatefulWidget {
  @override
  _StatsScreenState createState() => _StatsScreenState();
}

class _StatsScreenState extends State<StatsScreen> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Palette.primaryColor,
      appBar: CustomAppBar(),
      // design barra superior
      body: CustomScrollView(
        physics: ClampingScrollPhysics(),
        slivers: <Widget>[
          _buildHeader(),
          _buildRegionTabBar(),
        ],
      ),
    );
  }

  SliverPadding _buildHeader() {
    return SliverPadding(
      padding: const EdgeInsets.all(20.0),
      sliver: SliverToBoxAdapter(
          child: Text(
        'Estatisticas',
        style: const TextStyle(
          color: Colors.white,
          fontSize: 25.0,
          fontWeight: FontWeight.bold,
        ),
      )),
    );
  }

  SliverToBoxAdapter _buildRegionTabBar() {
    return SliverToBoxAdapter(
      child: DefaultTabController(
        length: 2,
          child: TabBar(
            tabs:[
              Tab(text: 'Brasil'),
              Tab(text: 'Mundo'),    
            ],
          ),
          
      ),
      );
      
  }
}

1 answer

0

According to the documentation

Now that you have tabs, display content when a tab is Selected. For this purpose, use the Tabbarview widget.

Now that you have tabs, display the content when a tab is selected. To do this, use the Tabbarview widget.

TabBarView(
  children: [
    Icon(Icons.directions_car),
    Icon(Icons.directions_transit),
    Icon(Icons.directions_bike),
  ],
);

Examples:

https://flutter.dev/docs/cookbook/design/tabs

http://www.macoratti.net/19/10/flut_tabbar1.htm

Browser other questions tagged

You are not signed in. Login or sign up in order to post.