Skip to content

Instantly share code, notes, and snippets.

@e200
Created August 21, 2020 14:59
Show Gist options
  • Save e200/6f3a5428bbd143dc65f51a5e7a8f3e71 to your computer and use it in GitHub Desktop.
Save e200/6f3a5428bbd143dc65f51a5e7a8f3e71 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
void main() {
runApp(LazyGridViewApp());
}
class LazyGridViewApp extends StatelessWidget {
final _list = List.generate(42, (index) => index);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Lazy Grid View'),
),
body: CustomScrollView(
slivers: [
SliverGrid(
delegate: SliverChildBuilderDelegate(
(context, index) {
return Container(
color: Colors.blue.withOpacity(index.isEven ? .1 : .4),
child: Center(
child: Text(index.toString()),
),
);
},
childCount: _list.length,
),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
),
),
SliverToBoxAdapter(
child: Center(
child: Padding(
padding: const EdgeInsets.all(15),
child: CircularProgressIndicator(),
),
),
),
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment