isDigit method

bool isDigit()

Check whether a string is digit or not

'123'.isDigit(); // false
'123.456'.isDigit(); // false
'abc'.isDigit(); // false
'123abc'.isDigit(); // false

Implementation

bool isDigit() {
  final isMatch = RegExp(r'\d').hasMatch(this);
  return isMatch && length == 1;
}