Skip to content
On this page

DatePicker 日期选择

代码演示

基本用法

dart
DatePicker(
  value: model.value,
  onChange: (value) => model.value = value,
),

最大值 & 最小值

dart
DatePicker(
  value: model.value,
  onChange: (value) => model.value = value,
  minDate: DateTime.now().subMonths(1),
  maxDate: DateTime.now().addMonths(1),
),

指定日期列

dart
DatePicker(
  value: model.value, // [year, month]
  onChange: (value) => model.value = value,
  columnsType: const {DateColumn.year, DateColumn.month},
),

选项格式化

dart
DatePicker(
  value: model.value,
  onChange: (value) => model.value = value,
  formatter: {
    DateColumn.year: (opt) => opt..name = "${opt.value}年",
    DateColumn.month: (opt) => opt..name = "${opt.value}月",
    DateColumn.day: (opt) => opt..name = "${opt.value}日",
  },
),

API

Props类型描述
titleWidget | String面板标题
confirmTextString确认文本
cancelTetxString取消文班
onConfirmFunction(List<int>)确认回调
onCancelFunction(List<int>)取消回调
minDateDateTime最小日期
maxDateDateTime最大日期
valueList<int>当前已选日期
columnsTypeSet<year | month | day>日期列
onChangeFunction(List<int> values)值变化回调
formatterMap<year | month | day, NamedValue Function(NamedValue option)>格式化选项