substring function

String? substring(
  1. String? value,
  2. int start, [
  3. int end = -1
])

Returns a substring of value from start to end.

  • If end is -1 or greater than the string length, uses the full length.
  • Returns null if value is null.

Implementation

String? substring(String? value, int start, [int end = -1]) {
  if (value == null) return null;
  final maxEnd = value.length;
  return value.substring(start, end > 0 && end <= maxEnd ? end : maxEnd);
}