tryParse static method

int? tryParse(
  1. dynamic v, {
  2. bool allowHex = true,
})

Tries to parse a dynamic value v into an integer, returning null if parsing fails.

If the input value v is null, directly returns null. Otherwise, attempts to parse the dynamic value v into an integer using the parse method. If successful, returns the resulting integer; otherwise, returns null. allowHex: convert hexadecimal to integer Parameters:

  • v: The dynamic value to be parsed into an integer.

Returns:

  • An integer if parsing is successful; otherwise, returns null.

Implementation

static int? tryParse(dynamic v, {bool allowHex = true}) {
  if (v == null) return null;
  try {
    return parse(v, allowHex: allowHex);
  } on ArgumentException {
    return null;
  }
}