isNumber method Null safety

bool? isNumber()

Checks whether the String is a number.

Example

String foo = '45';
bool isNumber = foo.isNumber(); // returns true
String foo = '45s';
String isNumber = foo.isNumber() // returns false

Implementation

bool? isNumber() {
  if (this == null) {
    return null;
  }
  if (this!.isEmpty) {
    return false;
  }
  return num.tryParse(this!) != null;
}