Search code examples
flutterflutter-sliverflutter-sliverappbar

Sliver appbar not stretching flutter


Im so confuse why my sliverappbar doesnt stretch and zoom when I reach the top list. I following the flutter video

https://youtu.be/mSc7qFzxHDw

I tried the following code

class AppBar5 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: CustomScrollView(
        slivers: [
          SliverAppBar(
            title: Text("title"),
            expandedHeight: 200,
            stretch: true,

            flexibleSpace: FlexibleSpaceBar(
              background: Container(
                  width: MediaQuery.of(context).size.width,
                  height: 200,
                  child: Image.asset("assets/images/hot.jpg", fit: BoxFit.cover)
              ),
            )
          ),
          SliverList(
            delegate: SliverChildBuilderDelegate(
                  (_, index) => ListTile(
                title: Text("Index: $index"),
              ),
            ),
          )
        ],
      ),
    );
  }
}

Solution

  • Add Bouncing ScrollPhysics to CustomScrollView

    CustomScrollView( 
          physics: BouncingScrollPhysics(),
          ...
    ),