quantityFromString method
double?
quantityFromString(
{ - required String regionString,
})
Implementation
double? quantityFromString({required String regionString}) {
if (isEmpty) {
return null;
}
try {
String toFormat = this;
List<String> parts;
if (regionString.contains('de')) {
parts = replaceAll('.', '').split(',');
} else {
parts = replaceAll(',', '').split('.');
}
toFormat = parts.length > 1
? '${parts.sublist(0, parts.length - 1).join()}.${parts.last}'
: this;
return double.tryParse(toFormat);
} catch (_) {
return null;
}
}