jifalops / datetime_picker_formfield

A Flutter widget that wraps a TextFormField and integrates the date and/or time picker dialogs.
MIT License
186 stars 101 forks source link

BasicDateTimeField allowing user to select time before initialTime. #120

Open ghost opened 3 years ago

ghost commented 3 years ago

This is the widget I'm working with:

DateTimeField(
  // Is disabled for iOS, only it's decoration is being used.
  enabled: platformIsAndroid,
  controller: _deadlineController,
  format: CreatePollModel.deadLineFormat,
  style: Properties.black16RegTextField,
  maxLines: 1,
  onShowPicker: (context, currentValue) async {
    final now = DateTime.now();
    final date = await showDatePicker(
      context: context,
      firstDate: now,
      initialDate: now,
      lastDate: widget.model.maxDate,
    );
    if (date != null) {
      final time = await showTimePicker(
        context: context,
        initialTime: TimeOfDay.fromDateTime(currentValue ?? now),
      );
      return DateTimeField.combine(date, time);
    } else {
      return currentValue;
    }
  },
  onFieldSubmitted: widget.model.updateDeadLine,
),

The calendar correctly disables the previous dates from DateTime.now() but when the user selects the current day, the time picker does not "remember" that it shouldn't allow to use an earlier time from the day.

Please confirm if I'm doing something wrong.

related https://github.com/jifalops/datetime_picker_formfield/issues/25#issuecomment-473597378