tryParse static method
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.
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) {
if (v == null) return null;
try {
return parse(v);
} on ArgumentException {
return null;
}
}