Created with <3 with dartpad.dev.
Created
August 18, 2023 01:20
-
-
Save jtmuller5/013b30bec64c2ec58855e6bfcbecce06 to your computer and use it in GitHub Desktop.
xenial-performance-6792
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/material.dart'; | |
const Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData.dark().copyWith( | |
scaffoldBackgroundColor: darkBlue, | |
), | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: Center( | |
child: MyWidget(), | |
), | |
), | |
); | |
} | |
} | |
class MyWidget extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return CustomScrollView(slivers: [ | |
SliverMainAxisGroup( | |
slivers: [ | |
SliverToBoxAdapter( | |
child: Padding( | |
padding: const EdgeInsets.all(16.0), | |
child: Text( | |
'Hello, World!', | |
style: TextStyle(fontSize: 12), | |
), | |
), | |
), | |
SliverPersistentHeader( | |
pinned: true, | |
floating: false, | |
delegate: HeaderDelegate(ListTile( | |
tileColor: darkBlue, | |
title: Text('Look at these numbers'), | |
), | |
), | |
), | |
SliverList.builder( | |
itemCount: 200, | |
itemBuilder: (context, index) { | |
return ListTile(title: Text(index.toString())); | |
}), | |
SliverToBoxAdapter( | |
child: Divider( | |
height: 2, | |
thickness: 1, | |
color: Colors.grey.shade300, | |
), | |
), | |
SliverToBoxAdapter( | |
child: Padding( | |
padding: | |
const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8), | |
child: Text('Hello Again!', | |
style: Theme.of(context).textTheme.bodySmall), | |
), | |
), | |
], | |
) | |
]); | |
} | |
} | |
class HeaderDelegate extends SliverPersistentHeaderDelegate { | |
const HeaderDelegate(this.child); | |
final Widget child; | |
@override | |
Widget build( | |
BuildContext context, double shrinkOffset, bool overlapsContent) { | |
return child; | |
} | |
@override | |
double get maxExtent => minExtent; | |
@override | |
double get minExtent => 48; | |
@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