未定义命名参数“onTap”

问题描述

我目前正在学习 Flutter 并且我对它很陌生。在我的应用程序中,我使用了响应式网格包并在响应式容器中添加了文本。我想在点击此文本时转到另一个页面,但我的错误给了我这个错误。

The named parameter 'onTap' isn't defined.
Try correcting the name to an existing named parameter's name,or defining a named parameter with the name 'onTap'.

我使用了以下代码:

Widget build(BuildContext context) {
return Scaffold(
  body: SingleChildScrollView(
    child: Container(
      child: ResponsiveGridRow(children: [
        ResponsiveGridCol(
          lg: 12,child: Container(
            height: 400,alignment: Alignment.center,color: Colors.orange,child: Column(
              children: [
                Container(
                  margin: EdgeInsets.only(top: 150),child: Text("Welcome To",style: TextStyle(
                       fontSize: 40,color: Colors.white)),),Container(
                  alignment: Alignment.center,child: Text("our App",color: Colors.white,fontWeight: FontWeight.bold)),],ResponsiveGridCol(
          xs: 4,md: 2,child: Container(
              height: 18,alignment: Alignment.centerLeft,child: Text("Login",style: TextStyle(
                      fontSize: 13,// decoration: TextDecoration.underline,color: Colors.orange[800])),onTap: () { // i got error here
                Navigator.push(
                  context,MaterialPageRoute(builder: (context) => SignIn()),);
              }
              ),)
      ]),);

} }

解决方法

您的小部件没有 onTap 属性,您需要通过使用 gesture detector 或 InkWell 包装您需要可点击的小部件来创建如下所示的属性

GestureDetector(
   onTap: () { 
                Navigator.push(
                  context,MaterialPageRoute(builder: (context) => SignIn()),);
              }
     child:Container(
              height: 18,alignment: Alignment.centerLeft,child: Text("Login",style: TextStyle(
                      fontSize: 13,// decoration: TextDecoration.underline,color: Colors.orange[800])),)),
,

Container 小部件没有 onTap 属性尝试将其包装在 InkWell 中,如下所示:

InkWell(
    onTap: () {
        Navigator.push(
            context,);
      },child: Container(
      height: 18,style: TextStyle(
              fontSize: 13,)))

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...