I am trying to use solution from here How make button which open random page in Flutter? but instead of RaisedButton, do it with my Listview buttons.
Here's what I have so far after I added the RandomRouteGenerator from the other StackOverflow:
ListView(
children: const <Widget>[
Card(
child: ListTile(
leading: Text('🐔'),
title: Text('Chicken'),
onTap: () {
Navigator.of(context).pushNamed(
RouteGenerator.getRandomNameOfRoute());
},
),
),
//... more Cards that would become other listview items
Here's the errors:
Compiler message:
lib/main.dart:163:28: Error: Not a constant expression.
Navigator.of(context).pushNamed(
^^^^^^^
lib/main.dart:163:25: Error: Method invocation is not a constant expression.
Navigator.of(context).pushNamed(
^^
lib/main.dart:164:32: Error: Method invocation is not a constant expression.
RouteGenerator.getRandomNameOfRoute());
^^^^^^^^^^^^^^^^^^^^
lib/main.dart:163:37: Error: Method invocation is not a constant expression.
Navigator.of(context).pushNamed(
^^^^^^^^^
lib/main.dart:162:20: Error: Not a constant expression.
onTap: () {
^^
Thanks
Aucun commentaire:
Enregistrer un commentaire