【发布时间】:2020-10-29 15:45:11
【问题描述】:
如何在 dart 中创建嵌套列表的副本?在这段代码中,我对副本所做的更改也在原版中进行了更改
List board = [[0,0,0], [0,0,0], [0,0,0]];
List boardCopy = List.from(board); // create copy of the board
boardCopy[0][0] = 1; // change copy
print(board); // print original board
OUTPUT:
[[1,0,0], [0,0,0], [0,0,0]] <-- it has changed the original board!!!
【问题讨论】:
标签: list flutter dart nested-lists deep-copy