import 'dart:math' as math; extension ListExtension on List { Iterable takeIndex(List indexes) => indexes.map((e) => this[e]); List slice(int start, [int? stop]) { if (start < 0) { start = math.max(length + start, 0); } if (stop != null && stop < 0) { stop = math.max(length + stop, 0); } if (start >= length) { return []; } else if (stop == null) { return sublist(start); } else if (start >= stop) { return []; } else { return sublist(start, math.min(stop, length)); } } }