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.
Example:
NumberUtils.generateIntList(1, 5); // Returns [1, 2, 3, 4, 5]
NumberUtils.generateIntList(3, 3); // Returns [3]
NumberUtils.generateIntList(5, 1); // Returns null (start > end)
Audited: 2026-06-12 11:26 EDT
Implementation
@useResult
static List<int>? generateIntList(int start, int end) {
if (start > end) {
return null;
}
return List<int>.generate(end - start + 1, (int i) => start + i);
}