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
相关产品推荐
相关产品推荐

