我尝试按流获取文件夹中的所有文件。Directort(path).list()
返回Stream<FileSystemEntity>
。
我想返回Stream<List<FileSystemEntity>>
。
例:
1 => 1
2 => 1,2
3 => 1,2,3
最佳答案
scan
中的rxdart
运算符是最佳答案
https://pub.dev/documentation/rxdart/latest/rx/ScanExtension/scan.html
https://rxjs.dev/api/operators/scan
Stream<FileSystemEntity> source$ = ...;
Stream<List<FileSystemEntity>> result$ = source$.scan(
(acc, element, _) => [...acc, element],
[],
);
关于flutter - 将Stream <Item>转换为Stream <List <Item >>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64578047/