1

Hi everyone I have some troubles with Flutter FormBuilderDateTimePicker

My problem is that when I set the value manually (with a keyboard not using graphical draggable 'arrows' offered by the widget) I get the validation error every time the hour value is between 12 and 00.

For example, if I set 12:30 the value will be accepted, but if I change the hour to 16:30 it will display a validation error message. Below you can find a graphical representation of my case.

enter image description here enter image description here

Here is how I set my FormBuilderTimePicker widget

    FormBuilderDateTimePicker(
         name: 'fieldname',
         initialValue: DateTime.now(),
         initialDate: DateTime.now(),
         initialEntryMode: DatePickerEntryMode.input,
         alwaysUse24HourFormat: true,
         onChanged: (value) => mayValue = ,
         format: DateFormat.yMMMMd('it_IT').add_Hm(),
         timePickerInitialEntryMode: TimePickerEntryMode.input,
       )

The other input type is working fine, but I would like to keep them both enter image description here

2

2 Answers 2

1

On flutter_form_builder: ^7.3.1 source code, alwaysUse24HourFormat has not being used. As matias-de-andrea mention on git issue which is still open.

To make it work, they override the transitionBuilder in order to provide 24h format on showTimePicker context.

transitionBuilder: (BuildContext context, Widget? child) {
    return MediaQuery(
      data: MediaQuery.of(context)
          .copyWith(alwaysUse24HourFormat: true),
      child: child!,
    );
  },

You can check How to use 24 hour clock when invoking showTimePicker() in Flutter? and they've discussed more about this.

Sign up to request clarification or add additional context in comments.

Comments

0

You can disable hour/minute textfield height decreasing by wrapping the builder of timer picker with a new Theme and setting errorStyle of inputDecorationTheme to 0.

              TimeOfDay? timeOfDay = await showTimePicker(
                context: context,
                initialTime: _toTime,
                initialEntryMode: TimePickerEntryMode.inputOnly,
                hourLabelText: '',
                minuteLabelText: '',
                helpText: AppLocalizations.of(context)!.enterTime,
                confirmText: AppLocalizations.of(context)!.save,
                builder: (context, child) {
                  return Theme(
                    data: theme.copyWith(
                      inputDecorationTheme:
                          theme.inputDecorationTheme.copyWith(
                        errorStyle: const TextStyle(height: 0),
                      ),
                    ),
                    child: child!,
                  );
                },
              );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.