Ad

Gesture Detector OnTap Is Not Triggered

- 1 answer

 Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
      appBar: AppBar(
        title: Text("new screen"),
      ),
      body: Column(
        children: [
          Container(
            height: 210,
            decoration: BoxDecoration(color: Colors.white),
            child: Column(
              children: [
                Stack(
                  children: [
                    GestureDetector(
                        behavior: HitTestBehavior.translucent,
                        onTap: () {
                          Navigator.pop(context);
                        },
                        child: Icon(Icons.arrow_back)),
                    Center(
                      child: Text(
                        'set Destination',
                        style: TextStyle(fontSize: 20),
                      ),
                    ),
                  ],
                ),
                SizedBox(
                  height: 18,
                ),
                Row(
                  children: [
                    SizedBox(
                      width: 10,
                    ),
                    Expanded(
                        child: Container(
                      decoration: BoxDecoration(
                          color: Colors.grey,
                          borderRadius: BorderRadius.circular(8)),
                      child: Padding(
                        padding: EdgeInsets.all(2),
                        child: TextField(
                          decoration: InputDecoration(
                              hintText: 'Pickup Location',
                              fillColor: Colors.grey,
                              filled: true,
                              border: InputBorder.none,
                              isDense: true,
                              contentPadding:
                                  EdgeInsets.only(left: 10, top: 8, bottom: 8)),
                        ),
                      ),
                    )),
                    SizedBox(
                      width: 10,
                    )
                  ],
                ),
                SizedBox(
                  height: 10,
                ),
                Row(
                  children: [
                    SizedBox(
                      width: 10,
                    ),
                    Expanded(
                        child: Container(
                      decoration: BoxDecoration(
                          color: Colors.grey,
                          borderRadius: BorderRadius.circular(8)),
                      child: Padding(
                        padding: EdgeInsets.all(2),
                        child: TextField(
                          decoration: InputDecoration(
                              hintText: 'Where to',
                              fillColor: Colors.grey,
                              filled: true,
                              border: InputBorder.none,
                              isDense: true,
                              contentPadding:
                                  EdgeInsets.only(left: 10, top: 8, bottom: 8)),
                        ),
                      ),
                    )),
                    SizedBox(
                      width: 10,
                    )
                  ],
                )
              ],
            ),
          )
        ],
      ),
    ));
  }
Ad

Answer

You are not pushing any route on the Navigator stack, so you are trying to pop from an empty list (ie, there is nothing inside the stack to be popped). Your gesture detector is working fine, i had tested it on dartpad but in your stack you have nothing to show after its pop.

Ad
source: stackoverflow.com
Ad