Skip to content

Instantly share code, notes, and snippets.

@r100-stack
Created March 10, 2021 21:34
Show Gist options
  • Save r100-stack/3e6362ab2d60a15219df73759a1465f4 to your computer and use it in GitHub Desktop.
Save r100-stack/3e6362ab2d60a15219df73759a1465f4 to your computer and use it in GitHub Desktop.
Sample SliverGrid
import 'package:flutter/material.dart';
final 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 Scaffold(
body: CustomScrollView(slivers: [
SliverGrid(
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 200.0,
mainAxisSpacing: 10.0,
crossAxisSpacing: 10.0,
childAspectRatio: 4.0,
),
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return Container(
alignment: Alignment.center,
color: Colors.teal[100 * (index % 9)],
child: Text('grid item $index'),
);
},
childCount: 20,
),
)
]));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment