Skip to content

Instantly share code, notes, and snippets.

@b-cancel
Created September 16, 2019 03:41
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save b-cancel/b9842c61f02765620020094172785813 to your computer and use it in GitHub Desktop.
Save b-cancel/b9842c61f02765620020094172785813 to your computer and use it in GitHub Desktop.
SliverPersistentHeaderDelegate Example
/*
SliverPersistentHeader(
pinned: true,
floating: true,
delegate: OurDelegate(
toolBarHeight: MediaQuery.of(context).padding.top,
openHeight: 250,
closedHeight: 40,
),
),
*/
class OurDelegate extends SliverPersistentHeaderDelegate {
double toolBarHeight;
//toolBarHeight Included in both
double closedHeight;
double openHeight;
OurDelegate({
this.toolBarHeight,
this.closedHeight,
this.openHeight,
});
@override
Widget build(BuildContext context, double shrinkOffset, bool overlapsContent){
return Container(
height: toolBarHeight + openHeight,
color: Theme.of(context).primaryColorDark,
child: SafeArea(
child: Container(
padding: EdgeInsets.symmetric(
horizontal: 64,
),
child: FittedBox(
fit: BoxFit.contain,
child: Text("Workouts"),
),
),
),
);
}
@override
double get maxExtent => toolBarHeight + openHeight;
@override
double get minExtent => toolBarHeight + closedHeight;
@override
bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) => true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment