addAlternativePhoneMasks static method
void
addAlternativePhoneMasks({})
adds a list of alternative phone maskes to a country
data. This method can be used if some mask is lacking
countryCode
must be exactrly 2 uppercase letters like RU, or US
or ES, or DE.
alternativeMasks
a list of masks like
'+00 (00) 00000-0000', '+00 (00) 0000-0000'
that will be used
as an alternative. The list might be in any order
mergeWithExisting
if this is true, new masks will be added to
an existing list. If false, the new list will completely replace the
existing one
Implementation
static void addAlternativePhoneMasks({
required String countryCode,
required List<String> alternativeMasks,
bool mergeWithExisting = false,
}) {
assert(alternativeMasks.isNotEmpty);
final countryData = _findCountryDataByCountryCode(countryCode);
String currentMask = countryData['phoneMask'];
alternativeMasks.sort((a, b) => a.length.compareTo(b.length));
countryData['phoneMask'] = alternativeMasks.first;
alternativeMasks.removeAt(0);
if (!alternativeMasks.contains(currentMask)) {
alternativeMasks.add(currentMask);
}
alternativeMasks.sort((a, b) => a.length.compareTo(b.length));
if (!mergeWithExisting || countryData['altMasks'] == null) {
countryData['altMasks'] = alternativeMasks;
} else {
final existingList = countryData['altMasks'];
alternativeMasks.forEach((m) {
existingList.add(m);
});
}
// if (kDebugMode) {
// print('Alternative masks for country "${countryData['country']}"' +
// ' is now ${countryData['altMasks']}');
// }
}