//获取当前的时间
DateTime start = DateTime.now();
//在当前的时间上多添加4天
DateTime end = DateTime(start.year, start.month, start.day + 4);
// Navigator.pushNamed(context, DeviceDetails());
DateTimeRange? selectTimeRange = await showDateRangePicker(
//语言环境
locale: Locale("zh", "CH"),
context: context,
//开始时间
firstDate: DateTime(2018, 1, 1),
//结束时间
lastDate: DateTime(2050, 1, 1),
cancelText: "取消",
confirmText: "确定",
//初始的时间范围选择
initialDateRange: DateTimeRange(start: start, end: end),
builder: (context, child) {
return Theme(
data: ThemeData(
colorScheme: const ColorScheme(
// brightness: Colors.red,
primary: Color(0xFFE53835),
onPrimary: Colors.white,
secondary: Colors.white,
onSecondary: Color.fromARGB(255, 255, 255, 255),
error: Colors.white,
onError: Color.fromARGB(255, 255, 255, 255),
background: Colors.white,
onBackground: Colors.white,
surface: Colors.white,
onSurface: Colors.black,
brightness: Brightness.light)),
child: child!,
);
},
);
//结果
_dateSelectText = selectTimeRange.toString();
// 选择结果中的开始时间
DateTime selectStart = selectTimeRange!.start;
//选择结果中的结束时间
DateTime selectEnd = selectTimeRange!.end;
flutter日期区间选择
最新推荐文章于 2025-03-29 22:57:42 发布