Home > Software engineering >  Why is my SliverAppBar not responding at all?
Why is my SliverAppBar not responding at all?

Time:10-20

I'm trying to implement a sliver app bar in my flutter app but it just won't respond at all

 Widget build(BuildContext context) {
    return const MaterialApp(
        home: Scaffold(
      body: CustomScrollView(
        
        slivers: [
          SliverAppBar(
            expandedHeight: 200,
            flexibleSpace: FlexibleSpaceBar(
              title: Text("title"),
            ),
          ),
        ],
      ),
    ));
  }
}

CodePudding user response:

You need to add more slivers on CustomScrollView, when the viewport is bigger than slivers height, you will get the effect. Try adding SliverList or other sliver,

body: CustomScrollView(
  slivers: [
    SliverAppBar(
      expandedHeight: 200,
      flexibleSpace: FlexibleSpaceBar(
        title: Text("title"),
      ),
    ),
    SliverToBoxAdapter(
      child: SizedBox(
        height: 3333,
      ),
    )
  ],
),

You can check this video

CodePudding user response:

You can change it to this.

Widget build(BuildContext context) { return const MaterialApp( home: Scaffold( body: CustomScrollView(

    slivers: [
      SliverAppBar(
        expandedHeight: 200,
        flexibleSpace: FlexibleSpaceBar(
          title: Text("title"),
        ),
        expanded: true,
      ),
    ],
  ),
));
}}
  • Related