Skip to content

Instantly share code, notes, and snippets.

@carzacc
Last active August 17, 2022 04:28
Show Gist options
  • Save carzacc/03e1556e28147a81b60277ad8e42e1b5 to your computer and use it in GitHub Desktop.
Save carzacc/03e1556e28147a81b60277ad8e42e1b5 to your computer and use it in GitHub Desktop.
Example Flutter Web app using GridView.builder with a SliverGridDelegateWithMaxCrossAxisExtent
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(context) =>
MaterialApp(
home: MyHomePage()
);
}
class MyHomePage extends StatelessWidget {
final List<String> elements = ["Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "A Million Billion Trillion", "A much, much longer text that will still fit"];
@override
Widget build(context) =>
Scaffold(
body: GridView.builder(
itemCount: elements.length,
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 130.0,
crossAxisSpacing: 20.0,
mainAxisSpacing: 20.0,
),
itemBuilder: (context, i) => Card(
child: Center(
child: Padding(
padding: EdgeInsets.all(8.0), child: Text(elements[i])
)
)
)
)
);
}
@sirEgghead
Copy link

I'd like to see an update to this. It doesn't appear that everything is working properly two years later. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment