Last active
August 17, 2022 04:28
-
-
Save carzacc/03e1556e28147a81b60277ad8e42e1b5 to your computer and use it in GitHub Desktop.
Example Flutter Web app using GridView.builder with a SliverGridDelegateWithMaxCrossAxisExtent
This file contains hidden or 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(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]) | |
) | |
) | |
) | |
) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'd like to see an update to this. It doesn't appear that everything is working properly two years later. Thanks!