颤振如何获取星期几作为字符串

时间:2020-09-08 11:56:58

标签: flutter dart

如标题中所述:是否有一种简单的方法可以将一周中的所有时间都获取为字符串列表?

当前周的

输出:[“ 6”,“ 7”,“ 8”,“ 9”,“ 10”,“ 11”,“ 12”]

2 个答案:

答案 0 :(得分:2)

作为选择:

var now = DateTime.now();
var startFrom = now.subtract(Duration(days: now.weekday));
var list = List.generate(7, (i) => '${startFrom.add(Duration(days: i)).day}');
print('$list');

答案 1 :(得分:0)

您可以使用

var now = DateTime.now();
var startDate= now.subtract(Duration(days: now.weekday));
var listDate = List.generate(7, (i) => '${startDate.add(Duration(days: i)).day}');
print('$listDate ');

或可以使用Flutter软件包 weekdays