I keep getting this error when I try to route a button to a widget.
======== Exception caught by gesture ===============================================================
The following assertion was thrown while handling a gesture:
Could not find a generator for route RouteSettings("/SantosDumont", null) in the _WidgetsAppState.
This is the code. I want to call multiple historical figures using the info buttons class and then listing off each historical figure within ListTile like the Santos Dumont route
class Hwk3 extends StatefulWidget {
const Hwk3({Key? key}) : super(key: key);
@override
class _Hwk3State extends State<Hwk3> {
var nameArray = [
'Pablo Picasso',
'Santos Dumont'
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Historical Figures'),
),
body: ListView.builder(
itemCount: nameArray.length,
itemBuilder: (BuildContext context, index) {
return ListTile(
title: Text(nameArray[index]),
trailing: InfoButtons(historicalfigure: '/SantosDumont'));
},
),
);
}
}
class InfoButtons extends StatelessWidget {
final String historicalfigure;
InfoButtons({required this.historicalfigure});
@override
Widget build(BuildContext context) {
return (IconButton(
icon: const Icon(Icons.info),
tooltip: "Press for more information on historical figure",
onPressed: () {
Navigator.of(context).pushNamed(historicalfigure);
}));
}
}
CodePudding user response:
You need to either define /SantosDumont
in your routes inside MaterialApp
or use Navigator.of(context).push
.
Look at this link: Navigate with named routes