如何让 Flutter FormBuilderDateTimePicker 只显示日期选择器

How to get Flutter FormBuilderDateTimePicker to show only the date picker

如何让 Flutter FormBuilderDateTimePicker 只显示日期?下面的代码在日期选择器关闭后生成一个时间选择器,输出为:

flutter: 2022-04-02 00:00:00.000

我可以使用 DateTime.timeonly() 去除时间,但这并不能解决问题。这应该是一个只有日期的字段。

FormBuilderDateTimePicker(
    name: 'date_established',
    format: DateFormat('dd/MM/yyyy'),
    enabled: true,
    decoration: InputDecoration(
        labelText: 'Date Established',
        labelStyle: TextStyle(
            color: Colors.white,
            fontSize: 16.0,
            fontWeight: FontWeight.normal)),
        style: TextStyle(
            color: Colors.white,
            fontSize: 16.0,
            fontWeight: FontWeight.normal),
),

解决方案是添加

inputType: InputType.date,
var _selectedDate;
DateTime? datePicked;

    Future<void> _showDObPicker() async {
        datePicked = await showDatePicker(
            context: context,
            initialDate: DateTime.now(),
            firstDate: DateTime(1900,1,1),
            lastDate: DateTime.now(),
            builder: (BuildContext context, Widget? child) {
              return Theme(
                data: ThemeData.light().copyWith(
                  colorScheme: ColorScheme.light(primary: kPrimaryColor),
                  buttonTheme: ButtonThemeData(textTheme: ButtonTextTheme.primary),
                ),
                child: child!,
              );
            });
    
        setState(() {
    
          _selectedDate = DateFormat("dd/MM/yyyy").format(datePicked!);
    
        });
      }

像这样声明一个方法并像下面那样使用它

hint: _selectedDate