Flutter how to display datepicker when textformfield is clicked

Update 2020:

As pointed by another answer @Lekr0 this can now be done using onTap() property of TextFormField.

TextFormField(
      onTap: (){
        // Below line stops keyboard from appearing
        FocusScope.of(context).requestFocus(new FocusNode());

        // Show Date Picker Here

      },
    )

Original Answer:

Simple Way of Doing it :

Wrap your TextFormField with IgnorePointer & wrap IgnorePointer with InkWell

InkWell(
        onTap: () {
          _selectDate();   // Call Function that has showDatePicker()
        },
        child: IgnorePointer(
          child: new TextFormField(
            decoration: new InputDecoration(hintText: 'DOB'),
            maxLength: 10,
            // validator: validateDob,
            onSaved: (String val) {},
          ),
        ),
      ),

Also in Your _selectDate() make lastDate: new DateTime(2020)); else you will get error.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)