Skip to content

Instantly share code, notes, and snippets.

@prof3ssorSt3v3
Last active March 21, 2025 19:09
Show Gist options
  • Save prof3ssorSt3v3/09803df696fe6a1b45f03c3611654ce1 to your computer and use it in GitHub Desktop.
Save prof3ssorSt3v3/09803df696fe6a1b45f03c3611654ce1 to your computer and use it in GitHub Desktop.
Flutter example of a collapsing AppBar
import 'package:flutter/material.dart';
class CollapsingImageAppBar extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
expandedHeight: 250.0, // Adjust this height as needed
floating: false,
pinned: true,
flexibleSpace: FlexibleSpaceBar(
title: Text('Collapsing Image'),
background: Stack(
fit: StackFit.expand,
children: <Widget>[
Image.network(
'https://picsum.photos/500/200', // Replace with your image URL
fit: BoxFit.cover,
),
const DecoratedBox(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: <Color>[Colors.transparent, Colors.black45],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
stops: <double>[0.6, 1.0],
),
),
),
],
),
),
),
SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return ListTile(
title: Text('Item $index'),
);
},
childCount: 50, // Replace with your item count
),
),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment