0

I am currently working with SliverAppBar and i am facing problem while Scrolling the sliverList.

enter image description here

In the Picture above, my TabBar is going all the way up to the notification bar. When sliverAppBar collapse, I want my Tabbar to stick to the bottom of the AppBar.

Here is my Code that i am trying...

    return Scaffold(
  body: CustomScrollView(

    slivers: <Widget>[
      SliverAppBar(
        //backgroundColor: Colors.transparent,
        actions: <Widget>[
          IconButton(icon: Icon(Icons.favorite), onPressed: () {}),
          IconButton(icon: Icon(Icons.share), onPressed: () {})
        ],
        floating: false,
        pinned: true,
        expandedHeight: getHeight(context),
        flexibleSpace: FlexibleSpaceBar(
          title: Text("text"),
          background: Container(
            height: double.infinity,
            width: double.infinity,
            decoration: BoxDecoration(
                image: DecorationImage(
                    image: AssetImage(currentImage),
                    fit: BoxFit.cover)),
          ),
        ),
      ),
      SliverList(
        delegate: SliverChildListDelegate(bottomListView),
      ),
    ],
  )
  ,
);
2
  • Do you want TabBar to always be under the appbar? Nov 20, 2019 at 14:21
  • @IgorKharakhordin Yes... Nov 20, 2019 at 14:43

2 Answers 2

1

Just use bottom parameter of SliverAppBar and pass TabBar to it. In FlexibleSpaceBar add titlePadding to add padding from the TabBar. If you need to change TabBar colour, you can check this question.

Be careful with a title inside FlexibleSpaceBar and action icons in AppBar, because long title will cause overlapping in minimized appbar.

    child: CustomScrollView(
      slivers: <Widget>[
        SliverAppBar(
          //backgroundColor: Colors.transparent,
          actions: <Widget>[
            IconButton(icon: Icon(Icons.favorite), onPressed: () {}),
            IconButton(icon: Icon(Icons.share), onPressed: () {})
          ],
          floating: false,
          pinned: true,
          expandedHeight: getHeight(context),
          flexibleSpace: FlexibleSpaceBar(
            title: Text("text"),
            // Adding padding from TabBar
            titlePadding: EdgeInsets.only(bottom: 64, left: 60),
            background: Container(
              height: double.infinity,
              width: double.infinity,
              decoration: BoxDecoration(
                  image: DecorationImage(
                      image: AssetImage(currentImage),
                      fit: BoxFit.cover)),
            ),
          ),
          // Adding TabBar to the bottom of SliverAppBar
          bottom: TabBar(
            tabs: [
              for (var i = 0; i < 3; i++)
                Tab(
                  text: 'test $i',
                ),
            ]
          ),
        ),
        SliverList(
          delegate: SliverChildListDelegate(bottomListView),
        ),
      ],
    ),
1
  • I wrapped TabBarVIew with Container and gave it white color. So, i dont have to change the primary color of whole app. It's an alternate way... But, it works thanks... Nov 21, 2019 at 9:55
0

its maybe a bug:

https://github.com/flutter/flutter/issues/22393

so you can use this package,it solved this problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.