Fabrizio
Fabrizio

Reputation: 93

How to add a popup on onTap of a TextFormField

I need to show a popup on tapping the textFormField, just like a dropDownButton, but I need to use controllers of textFormField so I cannot manage it with dropDown.

I was trying like this

                        Container(
                          width: 50,
                          child: TextFormField(
                            controller: _edits1,
                            autofocus: true,
                            textAlign: TextAlign.center,
                            maxLength: 3,
                            decoration: InputDecoration(counterText: ""),
                            style: TextStyle(
                                fontFamily: 'Comfortaa',
                                color: Colors.blueGrey,
                                fontSize: 30),
                            onEditingComplete: () => node.nextFocus(),
                            onTap: () {
                              PopupMenuItem(child: Text('One'));
                              PopupMenuItem(child: Text('Two'));
                            },

                          ),
                        ),

Or something similar. How can I do it? Thanks

Upvotes: 2

Views: 1817

Answers (1)

Pranay Fating
Pranay Fating

Reputation: 84

Wrap your TextFormField inside the IgnorePointer widget

Container(
  child: IgnorePointer(
    child: TextFormField(),
  ),
),
                                                    

You can also use the InkWell widget to perform onTap on TextFormField

InkWell(
 onTap:(){},
  Container(
    child: IgnorePointer(
      child: TextFormField()
    ),
  ),
),

                                             

Upvotes: 1

Related Questions