我是 iOS 开发人员,也是 Flutter 的新手。在 Swift 语言中如果我们想在数组中的特定时间重复相同的值。
例如
如果在数组中我想重复 0 5 次,那么我可以通过如下一行代码来完成。
let fiveZeros = Array(repeating: "0", count: 5)
print(fiveZeros)
// Prints "["0", "0", "0", "0", "0"]"
init(repeating:count:) function used.
所以我正在寻找任何适用于 Flutter 的函数或代码。
我用谷歌搜索但没有找到解决方案。
最佳答案
在 dart 中,您可以使用 List
的 filled
工厂。
final list = List.filled(5, 0);
print(list); //-> [0, 0, 0, 0, 0]
在 list docs 中查看更多信息.
关于arrays - 如何在 Flutter 中重复数组的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50597994/