Last active
August 15, 2020 00:07
-
-
Save PiN73/721c681ae3eadd61d290ad2073797d9e to your computer and use it in GitHub Desktop.
Flutter slivers (CustomScrollView) example
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'; | |
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