Skip to content

Instantly share code, notes, and snippets.

@diegoveloper
Created April 25, 2020 22:42
Show Gist options
  • Select an option

  • Save diegoveloper/2385cf7f2435cf6293f01f6419886336 to your computer and use it in GitHub Desktop.

Select an option

Save diegoveloper/2385cf7f2435cf6293f01f6419886336 to your computer and use it in GitHub Desktop.
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