generateIntList static method
Generates a list of integers in ascending order, starting from start
and ending at end
(inclusive).
Returns null
if start
is greater than end
, indicating an invalid range.
In case of an invalid range, a warning debug message is printed.
Example:
NumberUtils.generateIntList(1, 5); // Returns [1, 2, 3, 4, 5]
NumberUtils.generateIntList(3, 3); // Returns [3]
NumberUtils.generateIntList(5, 1); // Returns null, prints a warning
Implementation
static List<int>? generateIntList(int start, int end) {
if (start > end) {
debugPrint(
'Invalid [start]: `$start` for '
'[end]: `$end`',
);
return null;
}
return List<int>.generate(end - start + 1, (int i) => start + i);
}