Created
August 22, 2022 14:08
-
-
Save mosluce/00e0814eea6bdfeedb4e1cd2bee6de4b to your computer and use it in GitHub Desktop.
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
import 'package:flutter/cupertino.dart'; | |
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({Key? key}) : super(key: key); | |
// This widget is the root of your application. | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
// This is the theme of your application. | |
// | |
// Try running your application with "flutter run". You'll see the | |
// application has a blue toolbar. Then, without quitting the app, try | |
// changing the primarySwatch below to Colors.green and then invoke | |
// "hot reload" (press "r" in the console where you ran "flutter run", | |
// or simply save your changes to "hot reload" in a Flutter IDE). | |
// Notice that the counter didn't reset back to zero; the application | |
// is not restarted. | |
primarySwatch: Colors.blue, | |
), | |
home: const MyHomePage(title: 'Flutter Demo Home Page'), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
final String title; | |
const MyHomePage({super.key, required this.title}); | |
@override | |
State<StatefulWidget> createState() => MyHomePageState(); | |
} | |
class MyHomePageState extends State<MyHomePage> { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Container( | |
color: Colors.grey.shade50, | |
child: Column( | |
children: [ | |
buildAppBar(context), | |
Expanded( | |
child: DefaultTabController( | |
length: 2, | |
child: CustomScrollView( | |
slivers: [ | |
buildHeader(context), | |
buildList(context), | |
], | |
), | |
), | |
), | |
], | |
), | |
), | |
); | |
} | |
buildAppBar(BuildContext context) { | |
return Container( | |
height: 100, | |
color: const Color.fromARGB(255, 0, 49, 90), | |
); | |
} | |
buildAvatar(BuildContext context) { | |
return Center( | |
child: Container( | |
width: 180, | |
height: 180, | |
margin: const EdgeInsets.symmetric(vertical: 16), | |
color: Colors.blueGrey, | |
), | |
); | |
} | |
buildDisplayName(BuildContext context) { | |
return Center( | |
child: Container( | |
width: 120, | |
height: 30, | |
color: Colors.blueGrey, | |
), | |
); | |
} | |
buildTabBar(BuildContext context) { | |
return Container( | |
height: 60, | |
color: Colors.grey, | |
margin: const EdgeInsets.only(top: 8, left: 24, right: 24, bottom: 0), | |
); | |
} | |
buildHeader(BuildContext context) { | |
return SliverPersistentHeader( | |
pinned: true, | |
delegate: MySliverPersistentHeaderDelegate( | |
child: Column( | |
children: [ | |
buildAvatar(context), | |
buildDisplayName(context), | |
buildTabBar(context), | |
], | |
), | |
), | |
); | |
} | |
buildList(BuildContext context) { | |
return SliverList( | |
delegate: SliverChildBuilderDelegate( | |
(context, index) { | |
return Container( | |
padding: const EdgeInsets.all(8), | |
alignment: Alignment.centerLeft, | |
height: 40, | |
child: Text('$index'), | |
); | |
}, | |
childCount: 100, | |
), | |
); | |
} | |
} | |
class MySliverPersistentHeaderDelegate extends SliverPersistentHeaderDelegate { | |
final Widget child; | |
MySliverPersistentHeaderDelegate({required this.child}); | |
@override | |
Widget build( | |
BuildContext context, double shrinkOffset, bool overlapsContent) { | |
return Container( | |
color: Colors.orange, | |
child: child, | |
); | |
} | |
@override | |
double get maxExtent => 310; | |
@override | |
double get minExtent => 60; | |
@override | |
bool shouldRebuild(covariant SliverPersistentHeaderDelegate oldDelegate) => | |
false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment