Created
June 7, 2019 20:54
-
-
Save diegoveloper/20d7c0175e838063d46c127b3b5b4831 to your computer and use it in GitHub Desktop.
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
| class Sample2 extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| return SafeArea( | |
| child: Material( | |
| child: CustomScrollView( | |
| slivers: [ | |
| SliverPersistentHeader( | |
| delegate: MySliverAppBar(expandedHeight: 200), | |
| pinned: true, | |
| ), | |
| SliverList( | |
| delegate: SliverChildBuilderDelegate( | |
| (_, index) => ListTile( | |
| title: Text("Index: $index"), | |
| ), | |
| ), | |
| ) | |
| ], | |
| ), | |
| ), | |
| ); | |
| } | |
| } | |
| class MySliverAppBar extends SliverPersistentHeaderDelegate { | |
| final double expandedHeight; | |
| MySliverAppBar({@required this.expandedHeight}); | |
| @override | |
| Widget build( | |
| BuildContext context, double shrinkOffset, bool overlapsContent) { | |
| return Stack( | |
| fit: StackFit.expand, | |
| overflow: Overflow.visible, | |
| children: [ | |
| Image.network( | |
| "https://images.pexels.com/photos/396547/pexels-photo-396547.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500", | |
| fit: BoxFit.cover, | |
| ), | |
| Center( | |
| child: Opacity( | |
| opacity: shrinkOffset / expandedHeight, | |
| child: Text( | |
| "MySliverAppBar", | |
| style: TextStyle( | |
| color: Colors.white, | |
| fontWeight: FontWeight.w700, | |
| fontSize: 23, | |
| ), | |
| ), | |
| ), | |
| ), | |
| Positioned( | |
| top: expandedHeight / 2 - shrinkOffset, | |
| left: MediaQuery.of(context).size.width / 4, | |
| child: Opacity( | |
| opacity: (1 - shrinkOffset / expandedHeight), | |
| child: Card( | |
| elevation: 10, | |
| child: SizedBox( | |
| height: expandedHeight, | |
| width: MediaQuery.of(context).size.width / 2, | |
| child: FlutterLogo(), | |
| ), | |
| ), | |
| ), | |
| ), | |
| ], | |
| ); | |
| } | |
| @override | |
| double get maxExtent => expandedHeight; | |
| @override | |
| double get minExtent => kToolbarHeight; | |
| @override | |
| bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) => true; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment