带限制的showTimePicker方法 [英] Methods showTimePicker with restrictions

查看:38
本文介绍了带限制的showTimePicker方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在拍片中限制自己的时间选择器(showTimePicker)的指定时间?我不希望有人能够选择不合适的时间.

我该如何处理?有例子吗?

顺便说一下, showDatePicker 方法是否只具有禁用日期的功能?

非常感谢你们所有人!

解决方案

您可以尝试以下临时解决方案

  showCustomTimePicker(上下文:上下文,//如果您提供selectableTimePredicate,则必须填写onFailValidation :(上下文)=>打印(无法选择"),initialTime:TimeOfDay(小时:2,分钟:0),selectableTimePredicate:(时间)=>时间.小时>1&&时间.小时<14&&time.minute%10 == 0).then((time)=>setState(()=> selectedTime = time?.format(context))) 

How do I restrict own specified times of the time picker (showTimePicker) in flutter? I don't want that someone is able to select inappropriate times.

How can I handle this? Are there any examples?

By the way is there a similar way for the showDatePicker method only for disabling dates?

Thank you all so much in advanced !!

解决方案

You could try this temporal solution time_picker_widget

DEMO

It is a custom showTimePicker to allow you set a selectableTimePredicate like you do in showDatePicker.

showCustomTimePicker(
    context: context,
    // It is a must if you provide selectableTimePredicate
    onFailValidation: (context) => print('Unavailable selection'),
    initialTime: TimeOfDay(hour: 2, minute: 0),
    selectableTimePredicate: (time) =>
        time.hour > 1 &&
        time.hour < 14 &&
        time.minute % 10 == 0).then((time) =>
    setState(() => selectedTime = time?.format(context)))

这篇关于带限制的showTimePicker方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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