如何在 Flutter 中查找特定周的工作日?

how to find weekdays from specific week in Flutter?

例如20.week包含2020年5月11日-2020年5月17日

代码必须显示这些日期范围。但代码显示:2020-05-12 - 2020-05-18

这是代码

DateTime getDateByWeekNumber({
  int week,
  int year,
  bool start
}) {
  DateTime date;
  var days = ((week - 1) * 7) + (start ? 0: 6);
  date = DateTime.utc(2020, 1, days);
  return date;
}

有人可以帮忙吗?

这应该有效

DateTime getDateByWeekNumber({int week, int year, bool start}) {
 DateTime date;
 var days = ((week - 1) * 7) + (start ? -1 : 5);
 date = DateTime.utc(2020, 1, days);
 return date;
}

The ISO 8601 definition for week 01 is the week with the Gregorian year's first Thursday in it.

我们需要找出 first day of a year 是否在 Thursday

之前
DateTime getDateByWeekNumber({int week, int year, bool start}) {
  DateTime startOfaYear = DateTime.utc(year, 1, 1);
  int startOfaYearWeekDay = startOfaYear.weekday;
  DateTime firstWeekOfaYear = startOfaYearWeekDay < 4
      ? startOfaYear.subtract(Duration(days: startOfaYearWeekDay - 1))
      : startOfaYear.add(Duration(days: 8 - startOfaYearWeekDay));
  DateTime startOfNWeek = firstWeekOfaYear.add(Duration(days: (week - 1) * 7));
  return start ? startOfNWeek : startOfNWeek.add(Duration(days: 6));
}