Created
September 16, 2019 03:41
-
-
Save b-cancel/b9842c61f02765620020094172785813 to your computer and use it in GitHub Desktop.
SliverPersistentHeaderDelegate Example
This file contains 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
/* | |
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