当我尝试将一个按钮路由到一个小部件时,我一直会收到这个错误。
======== 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.这是密码。我想使用info按钮类调用多个历史人物,然后列出ListTile中的每个历史数字,比如桑托斯杜蒙特路由。
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);
}));
}
}发布于 2022-02-27 19:58:38
您需要在/SantosDumont内部的路由中定义MaterialApp,或者使用Navigator.of(context).push。看看这个链接:用指定的路线导航
https://stackoverflow.com/questions/71287950
复制相似问题