在扑来中设置小时时输入时的时间验证错误

发布于 2025-02-12 01:24:20 字数 1333 浏览 2 评论 0原文

大家好,我遇到了一些麻烦 form builderdateTimePicker

我的问题是我的问题是手动设置值(使用键盘不使用窗口小部件提供的图形拖动“箭头”),我每次 hour 值值在12到00之间都会验证错误。

例如,如果我设置12个:30该值将被接受,但是如果我将小时更改为16:30,它将显示验证错误消息。在下面,您可以找到我案件的图形表示。

这是我设置formBuilderTimePicker窗口小部件的方式,

    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,
       )

其他输入类型正常,但是我想让它们俩都保持

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情绪操控生活 2025-02-19 01:24:20

Flutter_form_builder: ^7.3.1源代码,lovelyuse24hourformat尚未使用。正如

为了使它起作用,他们覆盖transitionBuilder,以便在showtimepicker上下文上提供24小时格式。

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

您可以检查在扑朔迷离时如何使用24小时时钟使用24小时时钟?他们已经讨论了更多。

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.

海拔太高太耀眼 2025-02-19 01:24:20

您可以使用新的主题和设置errorStyle inputDecorationThemeTheme to 0来禁用小时/分钟的TextField高度降低降低计时器选择器的构建器。

              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!,
                  );
                },
              );

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!,
                  );
                },
              );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文