Forked from b-cancel/sliverPersistentHeaderDelegate.dart
Created
September 8, 2021 20:49
-
-
Save osamamohammed98/0f90f5ea134336b60f438aba941df140 to your computer and use it in GitHub Desktop.
SliverPersistentHeaderDelegate Example
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
/* | |
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