You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter使用GestureDetector提示未定义命名参数'onTap'如何解决

问题解决方案

你遇到的命名参数'onTap'未定义报错是参数名拼写错误导致的,需要修正2个问题:

  • GestureDetector的点击回调参数名你写成了oneTap,Flutter官方定义的点击回调参数为onTap,修改参数名即可解决报错。
  • 跳转目标页面类名SingUpPage大概率是笔误,Sing为唱歌的含义,注册页对应的常规拼写是SignUpPage,如果你实际定义的类名确实是SingUpPage可忽略该提示。

修正后完整代码

return Expanded(
    flex: 1,
    child: Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: <Widget>[
        GestureDetector(
          // 修正参数名为onTap
          onTap: () {
            Navigator.push(context, MaterialPageRoute(builder: (context) => SignUpPage()));
          },
          child: Text(
            'Sign up',
            style: GoogleFonts.openSans(
                fontSize: 18,
                fontWeight: FontWeight.w700,
                decoration: TextDecoration.underline),
          ),
        ),
        Text(
          'Forgot Password',
          style: GoogleFonts.openSans(
              fontSize: 18,
              fontWeight: FontWeight.w700,
              decoration: TextDecoration.underline),
        )
      ],
    ),
  );

扩展提示:如果需要点击文本时带原生水波纹交互效果,可以把GestureDetector替换为InkWell,参数用法完全一致,用户体验更好。如果需要给"Forgot Password"文本也加跳转逻辑,同样套一层GestureDetector/InkWell加onTap回调即可。

内容的提问来源于stack exchange,提问作者xxdfv

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.23 20:45:04