isNumList function

bool isNumList(
  1. Object? value, [
  2. String delimiter = ','
])

Returns true if is a list of num. Can be a string of num too.

Implementation

bool isNumList(Object? value, [String delimiter = ',']) {
  if (value == null) return false;

  if (value is List<num>) return true;
  if (value is List<int>) return true;
  if (value is List<double>) return true;

  if (value is Iterable) {
    return listMatchesAll(value, (e) => e is num);
  }

  var s = value.toString();
  return RegExp(r'^-?\d+(?:\.\d+)?(?:' + delimiter + r'-?\d+(?:\.\d+)?)+$')
      .hasMatch(s);
}