首页 > 解决方案 > 如何设置默认日期选择器值?

问题描述

我使用日期选择器包来获取日期,这是我的代码

DatePicker(
   key: dobKey,
   setDate: _setDate,          
   customShape: StadiumBorder(
      side: BorderSide(
      color: Color(0xFFF991A0),
   )
),

如何设置默认值?喜欢2019-04-15

标签: flutterdatepicker

解决方案


用这个 -

await showDatePicker(
    context: context,
    initialDate: DateTime.now(),
    firstDate: DateTime.now().subtract(Duration(days: 1)),
    lastDate: DateTime.now().add(Duration(days: 6570)),
    initialDatePickerMode: DatePickerMode.year);

您可以添加 initialDate 以及可能的日期范围。您还可以添加选择器模式。


推荐阅读