[Solved] GestureDetector is not working on the TextField

If a GestureDetector is not working on a TextField in Flutter, it’s important to note that TextField itself handles user input gestures, and using a GestureDetector directly on it might not behave as expected. If you require a Gesture Detector on a Text field, use the following code. In this code, the AbsorbPointer ensures that the Gesture Detector’s onTap function works

gesture detector not working on textfield.png
  GestureDetector(
                  onTap: () {
                    print("hello now i m working ");
                  },
                  child: AbsorbPointer(
                    child: TextField(
                      controller: textController,
                      readOnly: true,
                      decoration: InputDecoration(
                          labelText: 'Research Thinker File ',
                          suffixIcon: Icon(Icons.upload_outlined)),
                    ),
                  ),
                ),

Conclusion : If the onTap function of the Gesture Detector is not working, then use AbsorbPointer to ensure that the onTap of the Gesture Detector functions properly.

Leave a Reply

Your email address will not be published. Required fields are marked *

web_horizontal
About Us ♢ Disclaimer ♢ Privacy Policy ♢ Terms & Conditions ♢ Contact Us

Copyright © 2023 ResearchThinker.com. All rights reserved.