Skip to content

Instantly share code, notes, and snippets.

@PiN73
Last active August 15, 2020 00:07
Show Gist options
  • Save PiN73/721c681ae3eadd61d290ad2073797d9e to your computer and use it in GitHub Desktop.
Save PiN73/721c681ae3eadd61d290ad2073797d9e to your computer and use it in GitHub Desktop.
Flutter slivers (CustomScrollView) example
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark(),
home: FriendsPage(),
);
}
}
final requests = ['A', 'B', 'C'];
final friends = ['Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
class FriendsPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
slivers: [
SliverToBoxAdapter(
child: ListTile(
title: Center(
child: Text('Requests'),
),
),
),
SliverGrid(
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 400,
childAspectRatio: 3.0,
),
delegate: SliverChildBuilderDelegate(
(context, i) => Card(
child: Center(
child: ListTile(
leading: CircleAvatar(),
title: Text(requests[i]),
),
),
),
childCount: requests.length,
),
),
SliverToBoxAdapter(
child: ListTile(
title: Center(
child: Text('Friends'),
),
),
),
SliverList(
delegate: SliverChildBuilderDelegate(
(context, i) => ListTile(
leading: CircleAvatar(),
title: Text(friends[i]),
),
childCount: friends.length,
),
),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment