form-validator icon indicating copy to clipboard operation
form-validator copied to clipboard

Add a method to add locale to the supported list (instead of using the globalLocale

Open dreemz-dev opened this issue 3 years ago • 1 comments

Is your feature request related to a problem? Please describe. If I want to add a custom locale and switch to another local on runtime, When the user change locale, for custom local I need to use the globalLocale, while for supported locale I need to use setLoacel()

Describe the solution you'd like I want a method like: ValidationBuilder.addLocale(FormValidatorLocale customLocale);

dreemz-dev avatar May 21 '22 20:05 dreemz-dev

ValidationBuilder already supports using "local" locales by providing them as constructor parameter:

ValidationBuilder(locale: customLocale)

If you need more "flexibility" you can write some helper function like this and use on your app:

const customLocales = {
  'x': MyLocale(),
};

ValidationBuilder validator(BuildContext context) {
  final currentLocale = Locale.of(context);

  if (customLocales.containsKey(currentLocale.languageCode)) {
    return ValidationBuilder(locale: customLocales[currentLocale.languageCode]);
  }

  return ValidationBuilder(localeName: currentLocale.languageCode);
}

themisir avatar May 21 '22 20:05 themisir