當我嘗試將按鈕路由到小部件時,我不斷收到此錯誤。
======== 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.
這是代碼。我想使用資訊按鈕類呼叫多個歷史人物,然后列出 ListTile 中的每個歷史人物,例如 Santos Dumont 路線
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);
}));
}
}
uj5u.com熱心網友回復:
您需要/SantosDumont在您的路線中定義MaterialApp或使用Navigator.of(context).push. 查看此鏈接:使用命名路線導航
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/435792.html
