skip to Main Content

i am using GestureDetector and onTap() in flutter i have

an error:

(Handler: "onTap" Recognizer: TapGestureRecognizer") when clicking the onTap() Event

I cannot show the next Screen

I Used route method:

Navigator.of(context).pushNamed('AboutUsScreen');

and MaterialPageRoute method this `

Navigator.of(context).push(MaterialPageRoute(builder: (context) => AboutUsScreen()));`
Expanded(
                child: ListView(
                  shrinkWrap: true,
                  // scrollDirection: Axis.horizontal,
                  //shrinkWrap: bool.fromEnvironment("true"),

                  children: <Widget>[
              

GestureDetector(
                      behavior: HitTestBehavior.translucent,
                      onTap: () {
                        // Navigator.of(context).pushNamed('AboutUsScreen1111111');

                        Navigator.of(context).push(MaterialPageRoute(
                             builder: (context) => AboutUsScreen()));
                          Navigator.pushNamed(context, '/about');

                         Navigator.push(
                             context,
                             MaterialPageRoute(
                                 builder: (context) =>
                                     new AboutUsScreen1111111()));

                       
                      },

                        child: const Card(
                          elevation: 10,
                          color: Colors.blueAccent,
                          child: Padding(
                            padding: EdgeInsets.all(5),
                            child: Column(
                              mainAxisAlignment: MainAxisAlignment.center,
                              mainAxisSize: MainAxisSize.min,
                              children: [
                                Icon(Icons.document_scanner,
                                    fill: BorderSide.strokeAlignCenter),
                                Text(
                                  "AboutUS",
                                  textAlign: TextAlign.center,
                                  style: TextStyle(
                                    color: Colors.white,
                                    fontSize: 28,
                                  ),
                                ),
                              ],
                            ),
                          ),
                        ),
                      ),
                    ),
            
                  ],
                ),
              )

What is the problem?

2

Answers


  1. Chosen as BEST ANSWER

    The solution was strange I have separated the body of my widget out of main widget (type of widget statelesswidget) and run it. it is very strange .

    The Error Was About BuildContext But I Can't know if it has Any RelationShip. thank for all


  2. Kindly run this, it works:

    void main() {
      runApp(const MyApp());
    }
    
    class MyApp extends StatelessWidget {
      const MyApp({Key? key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return const MaterialApp(
          home: Home(),
        );
      }
    }
    
    class Home extends StatelessWidget {
      const Home({Key? key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: ListView(
            shrinkWrap: true,
            // scrollDirection: Axis.horizontal,
            //shrinkWrap: bool.fromEnvironment("true"),
    
            children: <Widget>[
              GestureDetector(
                behavior: HitTestBehavior.translucent,
                onTap: () {
                  Navigator.of(context).push(
                      MaterialPageRoute(builder: (context) => const  AboutUsScreen()));
                },
                child: const Card(
                  elevation: 10,
                  color: Colors.blueAccent,
                  child: Padding(
                    padding: EdgeInsets.all(5),
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        Icon(Icons.document_scanner,
                            fill: BorderSide.strokeAlignCenter),
                        Text(
                          "AboutUS",
                          textAlign: TextAlign.center,
                          style: TextStyle(
                            color: Colors.white,
                            fontSize: 28,
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ),
            ],
          ),
        );
      }
    }
    

    kindly let me know if this helps you.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search