将dart数组按照指定的长度分割,返回一个二维数组,实现list的split功能.
例如:
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 splitList(List list, int len) { if (len <= 1) { return [list]; } List result = []; int index = 1; while (true) { if (index * len < list.length) { List temp = list.skip((index - 1) * len).take(len).toList(); result.add(temp); index++; continue; } List temp = list.skip((index - 1) * len).toList(); result.add(temp); break; } return result; } 标签:index,List,list,len,Dart,result,数组,Flutter From: https://www.cnblogs.com/liangqilin/p/17296381.html