?將dart數(shù)組按照指定的長(zhǎng)度分割,返回一個(gè)二維數(shù)組抢埋,實(shí)現(xiàn)list的split功能.
?```
?eg:
?源數(shù)組:a?=?[0,?1,?2,?3,?4,?5,?6,?7,?8,?9,?10,?11,?12,?13,?14,?15,?16,?17,?18,?19]
splitList(a,?6):[[0,?1,?2,?3,?4,?5],?[6,?7,?8,?9,?10,?11],?[12,?13,?14,?15,?16,?17],?[18,?19]]
?```
代碼如下:
```dart
static?List<List<T>>?splitList<T>(List<T>?list,?int?len)?{
????if?(len?<=?1)?{
??????return?[list];
????}
????List<List<T>>?result?=?List();
????int?index?=?1;
????while?(true)?{
??????if?(index?*?len?<?list.length)?{
????????List<T>?temp?=?list.skip((index?-?1)?*?len).take(len).toList();
????????result.add(temp);
????????index++;
????????continue;
??????}
??????List<T>?temp?=?list.skip((index?-?1)?*?len).toList();
??????result.add(temp);
??????break;
????}
????return?result;
??}
```