Created
April 23, 2020 16:43
-
-
Save nodahikaru/f0e0c32386313fe8348d50e86e9a7663 to your computer and use it in GitHub Desktop.
Fancy Scaffold using Slivers
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
class CustomScaffold extends StatelessWidget { | |
const CustomScaffold._({ | |
Key key, | |
this.title, | |
this.color, | |
this.sliverChildDelegate, | |
this.padding = const EdgeInsets.symmetric(horizontal: 20, vertical: 10), | |
this.actions, | |
this.onRefresh, | |
}) : super(key: key); | |
factory CustomScaffold({ | |
Key key, | |
String title, | |
Color color, | |
List<Widget> actions, | |
List<Widget> children, | |
EdgeInsets padding = const EdgeInsets.symmetric(horizontal: 20, vertical: 10), | |
RefreshCallback onRefresh | |
}) => CustomScaffold._( | |
key: key, | |
title: title, | |
color: color, | |
actions: actions, | |
padding: padding, | |
onRefresh: onRefresh, | |
sliverChildDelegate: SliverChildListDelegate(children) | |
); | |
factory CustomScaffold.builder({ | |
Key key, | |
String title, | |
Color color, | |
IndexedWidgetBuilder builder, | |
int childCount, | |
List<Widget> actions, | |
RefreshCallback onRefresh, | |
EdgeInsets padding = const EdgeInsets.symmetric(horizontal: 20, vertical: 10), | |
}) => CustomScaffold._( | |
key: key, | |
title: title, | |
color: color, | |
actions: actions, | |
padding: padding, | |
onRefresh: onRefresh, | |
sliverChildDelegate: SliverChildBuilderDelegate( | |
builder, | |
childCount: childCount | |
) | |
); | |
final String title; | |
final Color color; | |
final List<Widget> actions; | |
final EdgeInsets padding; | |
final SliverChildDelegate sliverChildDelegate; | |
final RefreshCallback onRefresh; | |
@override | |
Widget build(BuildContext context) { | |
Widget body = CustomScrollView( | |
slivers: <Widget>[ | |
SliverAppBar( | |
floating: true, | |
elevation: 1, | |
backgroundColor: Colors.white, | |
actions: actions, | |
title: Text(title, style: const TextStyle(fontSize: 18)), | |
), | |
SliverPadding( | |
padding: padding, | |
sliver: SliverList(delegate: sliverChildDelegate) | |
) | |
] | |
); | |
if (onRefresh != null) { | |
body = RefreshIndicator( | |
child: body, | |
onRefresh: onRefresh, | |
); | |
} | |
return Scaffold( | |
backgroundColor: Colors.white, | |
body: body | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment