📜  创建一个 int list dart 代码示例

📅  最后修改于: 2022-03-11 14:48:05.177000             🧑  作者: Mango

代码示例1
// a simple a.to(b) solution:

extension RangeExtension on int {
  List to(int maxInclusive) =>
    [for (int i = this; i <= maxInclusive; i++) i];
}
// or with optional step:


extension RangeExtension on int {
  List to(int maxInclusive, {int step = 1}) =>
      [for (int i = this; i <= maxInclusive; i += step) i];
}
// use the last one like this:

void main() {
  // [5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47, 50]
  print(5.to(50, step: 3));
}