parseDouble function
Parses a rawDouble
String
to a double
.
The rawDouble
might include a unit (px
, em
or ex
)
which is stripped off when parsed to a double
.
Passing null
will return null
.
Implementation
double? parseDouble(String? rawDouble, {bool tryParse = false}) {
if (rawDouble == null) {
return null;
}
rawDouble = rawDouble
.replaceFirst('rem', '')
.replaceFirst('em', '')
.replaceFirst('ex', '')
.replaceFirst('px', '')
.replaceFirst('pt', '')
.trim();
if (tryParse) {
return double.tryParse(rawDouble);
}
return double.parse(rawDouble);
}