How do I use the SelectableDayPredicate to limit my DatePicker to only weekdays?

血红的双手。 提交于 2019-12-01 08:15:37

Here is an example where I omit Fridays and Saturdays from the picker, you can follow the logic here to achieve what you want:

selectableDayPredicate: (DateTime val) =>
            val.weekday == 5 || val.weekday == 6 ? false : true,

Thanks!

However, for date picker you must provide an initialValue which probably should be 'today', but if 'today' is a weekend, then you will get exception!

So iv'e set the initial to 1'st day of month on this case

    initialDate: _dateTime.weekday == 5 || _dateTime.weekday == 6 ? DateTime(DateTime.now().year, DateTime.now().month, 1) :  _dateTime ,
    selectableDayPredicate: (DateTime val) =>
    val.weekday == 5 || val.weekday == 6 ? false : true,
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!