Skip to content

FormBuilderDateTimePicker: onPressed of suffix don't work #1205

Closed
@virdosdo

Description

@virdosdo

Environment Flutter

Package version: 7.8.0

Describe your question

In FormBuilderDateTimePicker I need to clear the date. So use option suffix with IconButton. But when I click on the icon, opens calendar ignoring onpress event.I even wrapped the iconbutton with GestureDetector but it doesn't execute the onTap event either.

FormBuilderDateTimePicker(
            name: _infoTabla[x].cName,
            enabled: crudCtrl.formEsEditable(_infoTabla[x].cName),
            validator: (v) => (_infoTabla[x].cIsRequired && DateTime.tryParse(v.toString()) == null && !_infoTabla[x].cName.contains('fecmod')) ? "Este campo no puede estar vacío." : null,
            locale: const Locale("es", "ES"),
            initialValue: crudCtrl.formValorInicial(_infoTabla[x].cName, _infoTabla[x].cType, _infoTabla[x].cInitialValue, widget.tipoAlta, widget.datosFila[_infoTabla[x].cName]),
            initialDate: DateTime.now(),
            firstDate: (crudCtrl.formValorInicial(_infoTabla[x].cName, _infoTabla[x].cType, _infoTabla[x].cInitialValue, widget.tipoAlta, widget.datosFila[_infoTabla[x].cName]) != null)
                ? crudCtrl.formValorInicial(_infoTabla[x].cName, _infoTabla[x].cType, _infoTabla[x].cInitialValue, widget.tipoAlta, widget.datosFila[_infoTabla[x].cName]).isBefore(DateTime.now().add(Duration(days: _infoTabla[x].cValMin)))
                    ? crudCtrl.formValorInicial(_infoTabla[x].cName, _infoTabla[x].cType, _infoTabla[x].cInitialValue, widget.tipoAlta, widget.datosFila[_infoTabla[x].cName])
                    : DateTime.now().add(Duration(days: _infoTabla[x].cValMin))
                : DateTime.now().add(Duration(days: _infoTabla[x].cValMin)),
            lastDate: DateTime(DateTime.now().year + 1, 12),
            inputType: (_infoTabla[x].cType == 'Datetime')
                ? InputType.both
                : (_infoTabla[x].cType == 'Time')
                    ? InputType.time
                    : InputType.date,
            decoration: InputDecoration(
              icon: !crudCtrl.formEsEditable(_infoTabla[x].cName)
                  ? Icon(Icons.speaker_notes_off, color: Colors.grey[400], size: 20.0)
                  : Icon(
                      Icons.app_registration,
                      color: Colors.blue,
                      size: 20.0,
                    ),
              helperText: _infoTabla[x].cComments ?? '',
              labelText: _infoTabla[x].cDescription,
              labelStyle: TextStyle(fontSize: 20.0, color: Colors.blue[900]),
              suffixIconConstraints: BoxConstraints(minWidth: 10.0),
              suffixIconColor: Colors.blue,
              suffix: GestureDetector(
                onTap: () {
                  print('onTap event! ');
                },
                child: CircleAvatar(
                  backgroundColor: Colors.red,
                  child: IconButton(
                    icon: const Icon(
                      Icons.close,
                      color: Colors.blue,
                      size: 10.0,
                    ),
                    onPressed: () {
                      print('suffixIcon pressed');
                      _formKey.currentState!.fields[_infoTabla[x].cName]!.didChange(null);
                    },
                  ),
                ),
              ),
            ),
            onChanged: (dynamic valor) async {
              if (valor == null) return;
              if (_infoTabla[x].cType == 'Datetime' || _infoTabla[x].cType == 'Date') {
                cambios.addAll({_infoTabla[x].cName: DateFormat('yyyy-MM-dd HH:mm:ss').format(valor).toString()});
              } else if (_infoTabla[x].cType == 'Time') {
                cambios.addAll({_infoTabla[x].cName: DateFormat('HH:mm:ss').format(valor).toString()});
              }
            },
            initialTime: TimeOfDay(hour: 8, minute: 0),
          ),

Thanks,

Metadata

Metadata

Labels

questionFurther information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions