Skip to content

Instantly share code, notes, and snippets.

@nodahikaru
Created April 23, 2020 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nodahikaru/f0e0c32386313fe8348d50e86e9a7663 to your computer and use it in GitHub Desktop.
Save nodahikaru/f0e0c32386313fe8348d50e86e9a7663 to your computer and use it in GitHub Desktop.
Fancy Scaffold using Slivers
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