0
I tried to follow the tutorial of this link http://www.macoratti.net/19/07/flut_gridv1.htm because it has a list of items in gridview closer than I want to use.
And then I tried to add an option to make these items clickable and made some small modifications but is giving error in option Voidcallback.
The error returned are these:
Invalid constant value - line 38
The values in a const list literal must be constants - line 38
Const variables must be initialized with a constant value - line 38
The part of the code that’s going wrong is this:
class ItemExemplo {
const ItemExemplo({this.titulo, this.icon, this.onPressBtn});
final String titulo;
final IconData icon;
final VoidCallback onPressBtn;
}
const List<ItemExemplo> itenslist = const <ItemExemplo>[
const ItemExemplo(titulo: 'Carro', icon: Icons.directions_car),
const ItemExemplo(titulo: 'Bike', icon: Icons.directions_bike),
const ItemExemplo(titulo: 'Barco', icon: Icons.directions_boat),
// o onPressBtn da linha abaixo é onde esta dando o erro, mas preciso dele pra função onTap do Widget que será exibido no grid.
const ItemExemplo(titulo: 'Ônibux', icon: Icons.directions_bus, onPressBtn: () => print("Teste")),
];
I even understand that the error is in the constants, but am I on the right path or should I redo it in a totally different way? There’s another way to do it that works?
As there is not yet a snippet to flutter here in the OS I put the complete code in Dartpad in the link below:
Thanks for answering, but it’s not working yet, it solves the question when callback runs just a simple
print
, but if I try to use another method as aNavigator.of(context).push
he of the other mistake ofA value of type 'Future<Null>' can't be returned from function 'onClick'
. Excuse my ignorance on this subject, I’m still learning about flutter.– Bruno De Souza Carvalho
As you said, it solved your problem, which is what you had doubts about and was specified in your example. Now you are facing another different problem friend.
– Matheus Ribeiro
Change your question and add an example of this problem you mentioned regarding
Navigator
. A tip (Don’t get me wrong), when asking questions, don’t hide information, we still don’t know how to deal with xD crystal balls right– Matheus Ribeiro
Sorry buddy, as I said I’m still learning about flutter, I thought I’d make a callback from Voidcallback that was used as onPressBtn in a gridview serveria for all types of callbacks as well as in an ontap or an onpress of any widget, did not know that one style would override the other. But I stayed hj all day trying to solve this and I think I found a solution, I will post Aja. Even so thank you and forgive my mistakes.
– Bruno De Souza Carvalho