toInt method

int? toInt(
  1. {int radix = 10}
)

Parses string and returns integer value.

You can set an optional radix to specify the numeric base. If no radix is set, it will use the decimal system (10).

Returns null if parsing fails.

Example:

'42'.toDouble();      // 42
'invalid'.toDouble(); // null

Implementation

int? toInt({int radix = 10}) {
  try {
    return int.parse(this, radix: radix);
  } catch (error) {
    return null;
  }
}