Flutter 颤振|如何验证时间选择器

Flutter 颤振|如何验证时间选择器,flutter,dart,flutter-layout,timepicker,Flutter,Dart,Flutter Layout,Timepicker,这里我想验证时间选择器。当我要从时间选择器中选择时间时,它必须只允许我选择当前时间或当前时间之前的时间。我不应该允许选择未来的时间 这是我试过的时间选择器片段 DateTimeField( format: format, autocorrect: true, autovalidate: false, controller: _serviceDate, readOnly: true, validator: (date) =&g

这里我想验证时间选择器。当我要从时间选择器中选择时间时,它必须只允许我选择当前时间或当前时间之前的时间。我不应该允许选择未来的时间

这是我试过的时间选择器片段

DateTimeField(
      format: format,
      autocorrect: true,
      autovalidate: false,
      controller: _serviceDate,
      readOnly: true,
      validator: (date) => (date == null || _serviceDate.text == '')
          ? 'Please enter valid date'
          : null,
      onShowPicker: (context, currentValue) async {
        final date = await showDatePicker(
            context: context,
            firstDate: DateTime.now(),
            initialDate: currentValue ?? DateTime.now(),
            lastDate: DateTime(2100));
        if (date != null) {
          final time = await showTimePicker(
            context: context,
            initialTime: TimeOfDay.fromDateTime(
              currentValue ?? DateTime.now(),
            ),
          );
          return DateTimeField.combine(date, time);
        } else {
          return currentValue;
        }
      },
    );

将firstDate更改为firstDate:DateTime(1900),将lastDate更改为lastDate:DateTime