Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Locale aware double input #469

Open
t-unit opened this issue Oct 24, 2024 · 0 comments
Open

Locale aware double input #469

t-unit opened this issue Oct 24, 2024 · 0 comments
Labels
question Further information is requested

Comments

@t-unit
Copy link

t-unit commented Oct 24, 2024

Environment

Package version: 17.0.1

Describe your question

Depending on the local/language setting of an app, users expect to input floating point number with varying decimal separators. (E.g. see https://en.wikipedia.org/wiki/Decimal_separator#Conventions_worldwide).

I found that this library does not have any support for locale aware parsing, as DoubleValueAccessor is using double.tryParse that does not take any locale into account.

  1. What is the intended way to deal with different locales and floating point formats an this library?
  2. Shouldn't this library already take care of this an provide proper parsing for any locals? (It already has a dependency towards intl)

We came up with a custom value accessor:

class NumberFormatDoubleValueAccessor extends ControlValueAccessor<double, String> {
  NumberFormatDoubleValueAccessor(this.format);

  final NumberFormat format;

  @override
  String modelToViewValue(double? modelValue) => format.format(modelValue);

  @override
  double? viewToModelValue(String? viewValue) =>
      (viewValue == '' || viewValue == null)
          ? null
          : format.tryParse(viewValue)?.toDouble();
}

that allows specifying a format like NumberFormatDoubleValueAccessor(NumberFormat.decimalPattern('de')).

@t-unit t-unit added the question Further information is requested label Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant