slice method

String slice(
  1. int start, [
  2. int? end
])

Implementation

String slice(int start, [int? end]) {
  if (isEmptyOrNull) return '';

  var s = start, e = end ?? size;
  if (s < 0) {
    s = max(0, size + s);
  }
  if (e < 0) {
    e = max(0, size + e);
  }

  return (s < e) ? this!.substring(s, min(e, size)) : '';
}