form-validator
form-validator copied to clipboard
Add a method to add locale to the supported list (instead of using the globalLocale
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);
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);
}