如何在Flutter的showDatePicker或showDateRangePicker中限制时间?

huangapple go评论62阅读模式
英文:

How to limit the time in showDatePicker or showDateRangePicker Flutter

问题

I need to set Date limit at DatePicker. like i need to set date picker in between 12 Mar, 2023 to 20 Mar, 2023 and another date i don't want to select from user. user can select date in between 12 Mar, 2023 to 20 Mar, 2023 from date picker so how can we set that.

DateTime? pickedDate = await showDatePicker(
                        context: context,
                        initialDate: DateTime.now(),
                        firstDate: DateTime(2023, 3, 12),
                        lastDate: DateTime(2023, 3, 20),
                      );

I want to set limit at DatePicker based on requirement. Is there any way to set it. like any Property or any third party package?

英文:

I need to set Date limit at DatePicker. like i need to set date picker in between 12 Mar,2023 to 20 Mar,2023 and another date i don't want to select from user. user can select date in between 12 Mar,20233 to 20 Mar,2023 from date picker so how can we set that.

DateTime? pickedDate = await showDatePicker(
                        context: context,
                        initialDate: DateTime.now(),
                        firstDate: DateTime(1950),
                        lastDate: DateTime(2100),
                      );

I want to set limit at DatePicker based on requirement. Is there any way to set it. like any Property or any third party package?

答案1

得分: 1

你可以轻松地在“日期选择器”中定义“年、月和日”来设置日期范围。

final DateTime pickedDate = await showDatePicker(
  context: context,
  initialDate: DateTime(2021, 3, 15),
  firstDate: DateTime(2021, 3, 12),
  lastDate: DateTime(2023, 3, 20),
);
英文:

You can easily set Date range in Date Picker defining year, month & day.

 final DateTime pickedDate = await showDatePicker(
          context: context,
          initialDate: DateTime(2021, 3, 15),
          firstDate: DateTime(2021, 3, 12),
          lastDate: DateTime(2023, 3, 20),
        );

huangapple
  • 本文由 发表于 2023年3月9日 15:44:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/75681695.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定