1

I currently learning Flutter and I'm very new to it. in my app I used responsive grid package and add Text in responsive container. i wanted to go to another page when tap on this text but my bad it gives me this error.

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'.

i used following code:

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),
                  alignment: Alignment.center,
                  child: Text("Welcome To",
                     style: TextStyle(
                       fontSize: 40,
                       color: Colors.white)),
                ),
                Container(
                  alignment: Alignment.center,
                  child: Text("our App",
                     style: TextStyle(
                       fontSize: 40,
                       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()),
                );
              }
              ),
        )
      ]),
    ),
  ),
);

} }

Mrunal
  • 578
  • 2
  • 21
  • 39

2 Answers2

1

Your widget does not have an onTap property you need to create as show below by wrapping the widget that you need to be clickable with a gesture detector or 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])),
              
              )),
griffins
  • 7,079
  • 4
  • 29
  • 54
1

The Container widget does not have onTap property try to wrap it in InkWell like this:

InkWell(
    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])),
    )))
Schaban
  • 126
  • 1
  • 6