to2dList static method

List<List<int>> to2dList(
  1. List<int> data,
  2. int columnSize,
  3. int fillValue
)

转换为二维数组

Implementation

static List<List<int>> to2dList(List<int> data,int columnSize,int fillValue) {
  int rowSize = (data.length / columnSize).ceil();
  List<List<int>> dataNew = List.generate(rowSize,(index)=> List.generate(columnSize, (index) => 0));
  /// print(dataNew.toString());
  for (int i = 0; i < data.length; i++) {
    int row = (i / columnSize).floor();
    int column = i % columnSize;
    /// print(row.toString() +","+ column.toString()+ ",value:" + data[i].toString());
    if (data[i] != 0) {
      dataNew[row][column] = 1;
    } else {
      dataNew[row][column] = 0;
    }
  }
  return dataNew;
}