Catch tap event on TextFormField

Wrap TextFormField widget With AbsorbPointer widget , then OnTap() works definitely

here is an example:-

  GestureDetector(
        onTap: () => dialog(),
        child: AbsorbPointer(
          child: TextFormField(
            textInputAction: TextInputAction.newline,
            decoration: new InputDecoration(
                fillColor: Colors.grey,
                border: OutlineInputBorder(
                    borderRadius:
                        BorderRadius.all(Radius.circular(6.0)),
                    borderSide:
                        BorderSide(color: Colors.grey[100]),
                    gapPadding: 4),
                labelText: "Enter your mood",
                labelStyle: TextStyle(
                    letterSpacing: 1,
                    color: Colors.grey,
                    fontSize: 13),
                hintMaxLines: 1),
            validator: (val) {
              if (val == "") return "Field can't be empty";
            },
            keyboardType: TextInputType.text,
            enabled: true,
            textAlign: TextAlign.justify,
            minLines: 3,
            autofocus: false,
            style: new TextStyle(
              fontSize: 16.0,
              color: Colors.black,
            ),
            maxLines: 10,

          ),
        ),
      ),

Wrap AbsorbPointer Widget with Gesture Detector, and then work in onTap(). it will work fine.


Simply use onTap Method of TextFormField:

TextFormField(
  onTap: () {
    print("I'm here!!!");
  }
)

I have found a solution by using the InputDecorator (from the flutter gallery) :

          child: new InputDecorator(
                decoration: const InputDecoration(
                  labelText: 'Localisation',
                  icon: const Icon(Icons.room),
                ),
                child: widget.request.localisationLibelle != null
                    ? new Text(widget.request.localisationLibelle)
                    : new Text("-- Choisissez un lieu --"),
              ),

Instead of using a TextFormField that catch the tap at the place of the GestureDetector I use a simple child Text of the InputDecorator widget.


I just solved this myself using Flutter 0.6.0.

The GestureDetector object takes in a behavior property from this enum to determine how to defer actions.

Small snippet of the GestureDetector taking priority over a TextFormField:

new GestureDetector(
   onTap: onTap,
   behavior: HitTestBehavior.opaque,
   child: new TextFormField(
     enabled: onTap == null,
     *other stuff here*
   ),
)

The onTap object is a Function object I declare outside of this. I also set the enabled property based on my onTap object, so I can ensure that if I want to capture a tap, the text form field is disabled.