List flatten(List list) { for (int j = getDim(list).length; j > 1; j--) { list = list.expand((i) => i).toList(); } return list; }