Skip to content

Double date separators appearing in DatePicker, preventing date selection #63373

@shihaohong

Description

@shihaohong

Originally mentioned in #55535 by @whoch in this comment.

The issue might be related to incorrect date separators for particular locales: #63372

This issue occurs because the dateHelpText, dateSeparator in MaterialLocalization are different from the compactDateFormat used by the validator in TextFormField.

In Korea, helpText and separator of MaterialLocalizationKo are as follows:

String get dateHelpText => 'yyyy/mm/dd';
String get dateSeparator => '/';

And compactDateFormat is y. M. d.

InputText is initially shown in y. M. d. format, but when the value is modified, it is changed to y//M//d// by inputFormatters. And Only '/' is entered, therefore cannot be entered y. M. d. format.

HintText also outputs 'yyyy/mm/dd' which is different from the compactDateFormat.

Even if input the hintText format, the errorText is displayed because the _validateDate method, validator of InputDatePickerFormField, internally parse the compateDate.

String _validateDate(String text) {
  final DateTime date = _parseDate(text);
  if (date == null) {
    return widget.errorFormatText ?? MaterialLocalizations.of(context).invalidDateFormatLabel;
  } else if (!_isValidAcceptableDate(date)) {
    return widget.errorInvalidText ?? MaterialLocalizations.of(context).dateOutOfRangeLabel;
  }
  return null;
}

DateTime _parseDate(String text) {
 final MaterialLocalizations localizations = MaterialLocalizations.of(context);
 return localizations.parseCompactDate(text);
}

Can I modify compactDateFormat or can someone solve this issue?
photo1
photo2

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: internationalizationSupporting other languages or locales. (aka i18n)c: regressionIt was better in the past than it is nowf: date/time pickerDate or time picker widgetsf: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions