【问题标题】:Flutter: How to disable the past dates in `showDatePicker`?Flutter:如何在`showDatePicker`中禁用过去的日期?
【发布时间】:2020-05-13 12:21:49
【问题描述】:

如何在颤振showDatePicker 中禁用过去的日期?下面是我的代码

DateTime picked = await showDatePicker(
                              context: context,
                              initialDate: DateTime.now(),
                              firstDate: DateTime(2020, 1),
                              lastDate: DateTime(2101));

【问题讨论】:

    标签: android ios flutter mobile


    【解决方案1】:

    试试这个

    final DateTime picked = await showDatePicker(
      context: context,
      initialDate: DateTime.now(),
      firstDate: DateTime.now().subtract(Duration(days: 1)),
      lastDate: DateTime(2100),
    );
    

    【讨论】:

      【解决方案2】:

      initialDate:选择器对话框中的默认选定日期

      firstDate:从日期选择器的最小日期开始

      lastDate : 日期选择器的 To-Date 的最大日期

      您可以在第一个日期和最后一个日期之间选择日期

       DateTime picked = await showDatePicker(
                                        context: context,
                                        initialDate: DateTime.now(),
                                        firstDate: DateTime.now(),
                                        lastDate: DateTime(2101));
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-08-06
        • 1970-01-01
        • 1970-01-01
        • 2015-08-09
        • 1970-01-01
        • 2017-08-02
        • 2021-04-15
        • 1970-01-01
        相关资源
        最近更新 更多