首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在“颤振”中路由按钮时不断出错。

在“颤振”中路由按钮时不断出错。
EN

Stack Overflow用户
提问于 2022-02-27 19:43:24
回答 1查看 77关注 0票数 0

当我尝试将一个按钮路由到一个小部件时,我一直会收到这个错误。

代码语言:javascript
复制
======== 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中的每个历史数字,比如桑托斯杜蒙特路由。

代码语言:javascript
复制
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);
        }));
  }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-02-27 19:58:38

您需要在/SantosDumont内部的路由中定义MaterialApp,或者使用Navigator.of(context).push。看看这个链接:用指定的路线导航

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71287950

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档