toNum property

num? get toNum

Converts a String to a numeric value if possible.

If conversion fails, null is returned.

Example

String foo = '4';
int fooInt = foo.toNum(); // returns 4;
String foo = '4f';
var fooNull = foo.toNum(); // returns null;

Implementation

num? get toNum {
  if (isBlank) {
    return null;
  }
  return num.tryParse(this);
}