CupertinoDatePicker禁用当前时间之前的小时和分钟 [英] CupertinoDatePicker disable hours and minutes before the current time

查看:145
本文介绍了CupertinoDatePicker禁用当前时间之前的小时和分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

**

在minimumDate参数中,我们无法控制最短时间.

In the minimumDate param, we can't control the minimum time.

`  CupertinoDatePickerTest(                             
   onDateTimeChanged: (DateTime newdate) {
     print(newdate);
   },
   use24hFormat: false,
   maximumDate: DateTime.now().add(Duration(days: 2)),
   minimumDate:DateTime.now().subtract(Duration(days: 1)),
   minuteInterval: 1,
   mode: CupertinoDatePickerMode.dateAndTime,
   )`

推荐答案

您可以在CupertinoDatePicker小部件内使用 minimumDate 属性,以下代码将禁用当前时间之前的小时和分钟:

You can use minimumDate attribute inside CupertinoDatePicker widget, the following code will disable hours and minutes before the current time:

CupertinoDatePicker(
      minimumDate: DateTime.now(), //Min Date time is current time
  }

如果您想限制最大日期,还可以使用 maximumDate 属性:

You can use maximumDate attribute as well if you would like to limit the maximum date:

maximumDate: DateTime.now().add(Duration(days: 2)), //Max Date is after tomorrow

这篇关于CupertinoDatePicker禁用当前时间之前的小时和分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆