tryParse method Null safety

num? tryParse (
  1. String input

Parses a string containing a number literal into a number.

Like parse except that this function returns null for invalid inputs instead of throwing.


static num? tryParse(String input) {
  String source = input.trim();
  // TODO(lrn): Optimize to detect format and result type in one check.
  return int.tryParse(source) ?? double.tryParse(source);