C
I chose the answer above Matheus as correct for being fair the answer that answers my question. But I found another solution to my problem and solved the way below, so the two answers are correct for those who need it in the future.In my solution I deleted the listing lines and modified the ItensCard widget builder as follows, adding in addition to the callback I also put another option for icon colors:class ItensCard extends StatelessWidget {
ItensCard({this.title, this.icon, this.colorItem, this.onPressBtn});
final String title;
final IconData icon;
final MaterialColor colorItem;
final VoidCallback onPressBtn;
@override
Widget build(BuildContext context) {
final TextStyle textStyle = Theme.of(context).textTheme.bodyText2;
return Card(
color: Colors.white,
child: InkWell(
onTap: onPressBtn,
splashColor: Colors.amber,
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Icon(icon, size: 80.0, color: colorItem),
Text(title, style: textStyle),
]),
),
));
}
}
And now instead of me using the gridview listing as I did before: children: List.generate(itenslist.length, (index) {
return Center(
child: ItensCard(item: itenslist[index]),
);
}),
Now I add the direct gridview list in this way:children: <Widget>[
ItensCard(title: 'Carro', icon: Icons.directions_car, colorItem: Colors.blue, onPressBtn: () => print("Teste Carro")),
ItensCard(title: 'Bike', icon: Icons.directions_bike, colorItem: Colors.red, onPressBtn: () => print("Teste Bike")),
ItensCard(title: 'Barco', icon: Icons.directions_boat, colorItem: Colors.pink, onPressBtn: () => print("Teste Barco")),
ItensCard(title: 'Ônibus', icon: Icons.directions_bus, ncolorItem: Colors.green, onPressBtn: () => print("Teste Ônibus")),
]);
That for me in my case spared more lines of codes greatly reducing the size, and also facilitated the work. I don't know if it's useful to everyone but it's very useful to me.Follow the solution link for viewing on DartPad: https://dartpad.dev/96d51e9f55496f4125ab6697d1a639e4