问题描述
我目前正在学习 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,)))