Created
April 25, 2020 22:42
-
-
Save diegoveloper/2385cf7f2435cf6293f01f6419886336 to your computer and use it in GitHub Desktop.
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
| class _HomeState extends State<Home> { | |
| final elements = List.generate(10, (index) => index); | |
| void _onTap() { | |
| setState(() { | |
| elements.add(elements.length); | |
| }); | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| body: GridView.builder( | |
| itemCount: elements.length + 1, | |
| itemBuilder: (_, index) { | |
| if (index == elements.length) { | |
| return GestureDetector( | |
| onTap: _onTap, | |
| child: Container( | |
| child: FittedBox(child: Icon(Icons.add)), | |
| ), | |
| ); | |
| } | |
| return Padding( | |
| padding: const EdgeInsets.all(5.0), | |
| child: Container( | |
| color: Colors.primaries[index % Colors.primaries.length], | |
| child: FittedBox( | |
| child: Text( | |
| index.toString(), | |
| ), | |
| ), | |
| ), | |
| ); | |
| }, | |
| gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( | |
| crossAxisCount: 3, | |
| childAspectRatio: 1, | |
| ), | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment