isNumber property
Returns true if this string parses as an integer via int.tryParse.
Stricter than isNumeric: a value with a decimal point ('4.2') or in
scientific notation ('1e3') is false here but true for isNumeric,
which parses as a double. Use this when only whole-number input is
acceptable (IDs, counts, ports), and isNumeric when decimals are valid.
Delegates entirely to int.tryParse, so its acceptance rules apply: an
optional leading sign and a 0x/0X hexadecimal prefix are accepted
('0x1F' is true), surrounding whitespace is trimmed (' 42 ' is
true), and a magnitude that overflows the platform int returns null
(true on the web's doubles, false on the native 64-bit VM). The empty
string is false.
Example:
'42'.isNumber; // true
'-7'.isNumber; // true
'0x1F'.isNumber; // true (hexadecimal)
'4.2'.isNumber; // false (decimal)
'1e3'.isNumber; // false (scientific notation)
''.isNumber; // false
Audited: 2026-06-12 11:26 EDT
Implementation
@useResult
bool get isNumber => int.tryParse(this) != null;