Last active
March 21, 2025 19:09
-
-
Save prof3ssorSt3v3/09803df696fe6a1b45f03c3611654ce1 to your computer and use it in GitHub Desktop.
Flutter example of a collapsing AppBar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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