patchNumberSeperators static method
patchNumberSeperators patches all locales with the
decimal seperators to the decimal separator of the user.
The locales can also be patched for users with a samsung keyboard.
This is done by changing the patchForSamsungKeyboards
to true.
The samsung keyboard always uses a '.' as input for a decimal seperator.
This means that the DECIMAL_SEP
is a '.' and the GROUP_SEP
is a ','
see https://github.com/flutter/flutter/issues/61175
Implementation
static Future<void> patchNumberSeperators({
bool patchForSamsungKeyboards = false,
}) async {
final localePlus = LocalePlus();
try {
final bool isUsingSamsungKeyboard = patchForSamsungKeyboards &&
(await localePlus.isUsingSamsungKeyboard() ?? false);
final String? userDecimalSeperator =
isUsingSamsungKeyboard ? '.' : await localePlus.getDecimalSeparator();
final String? userGroupingSeperator = isUsingSamsungKeyboard
? ','
: await localePlus.getGroupingSeparator();
if (userDecimalSeperator == null || userGroupingSeperator == null) {
return debugPrint('''
The decimalSeperator and/or groupingSeperator can not be found.
The locales are not patched.
''');
}
if (userDecimalSeperator == userGroupingSeperator) {
return debugPrint('''
locale_plus: The group seperator and decimalSeperator are the same.
the locales are not patched.
decimal seperator: $userDecimalSeperator
group seperator: $userGroupingSeperator
''');
}
final entries = numberFormatSymbols.entries;
if (entries is! Iterable<MapEntry<String, NumberSymbols>>) {
return debugPrint('''
numberFormat Symbols is the wrong type
please create an issue on https://github.com/gokberkbar/locale_plus''');
}
for (final MapEntry<String, NumberSymbols> n in entries) {
numberFormatSymbols[n.key] = n.value.overrideSeperators(
decimalSeparator: userDecimalSeperator,
groupingSeparator: userGroupingSeperator,
);
}
} on MissingPluginException {
debugPrint(
'''locale_plus: plugin is not implemented on $os. The locales are not patched.''');
}
}