【问题标题】:DateRangePicker - Grey out unavailable datesDateRangePicker - 灰色显示不可用的日期
【发布时间】:2022-10-04 19:05:45
【问题描述】:

正如标题所示,我正在使用 DateRangePicker 将日期范围添加到数组中。如果可能的话,我希望能够将数组中已经选择的日期“变灰”。有没有办法做到这一点?

【问题讨论】:

    标签: flutter daterangepicker


    【解决方案1】:

    是的,您可以将禁用日期发送到组件中。

    Check this sample of the documentation

    如需更多选项,请查看the whole docs

    【讨论】:

    • 好的,据我所知,这接受单一日期。所以说我有两个日期来创建一个范围。 10 月 1 日和 10 月 7 日,是否有一种简单的方法可以获取介于两者之间的各个日期,以便我可以在阻止程序中输入这些日期以将日期范围创建为不可选择?
    【解决方案2】:

    这是返回范围之间的日期以防其他人需要的解决方案。

    List<DateTime> getDaysInBetweenIncludingStartEndDate(
        {required DateTime startDateTime, required DateTime endDateTime}) {
      // Converting dates provided to UTC
      // So that all things like DST don't affect subtraction and addition on dates
      DateTime startDateInUTC =
          DateTime.utc(startDateTime.year, startDateTime.month, startDateTime.day);
      DateTime endDateInUTC =
          DateTime.utc(endDateTime.year, endDateTime.month, endDateTime.day);
    
      // Created a list to hold all dates
      List<DateTime> daysInFormat = [];
    
      // Starting a loop with the initial value as the Start Date
      // With an increment of 1 day on each loop
      // With condition current value of loop is smaller than or same as end date
      for (DateTime i = startDateInUTC;
          i.isBefore(endDateInUTC) || i.isAtSameMomentAs(endDateInUTC);
          i = i.add(const Duration(days: 1))) {
        // Converting back UTC date to Local date if it was local before
        // Or keeping in UTC format if it was UTC
    
        if (startDateTime.isUtc) {
          daysInFormat.add(i);
        } else {
          daysInFormat.add(DateTime(i.year, i.month, i.day));
        }
      }
      return daysInFormat;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多