如何将firebase存储中所有子文件夹的第一个图像放入列表中(Dart/FLIFT)
所以基本上我想从每个星期的子文件夹中获取第一张照片,并返回这些第一张照片的列表;在这种情况下,列表将有4个图像。我使用一个模型来表示带有3个参数的照片(FirebaseFile);参考URL、下载链接和文件名。我引用了该模型的视频: 上面的代码是我已经走了多远。“listFirst”函数返回给定文件夹中的第一张照片。“listWeek”函数列出对子文件夹的所有引用。到目前为止,我已经设法枚举了列表的所有结果和其中的一个firebasefile,但现在我不知道如何将其合并到未来的列表中以返回到我的主程序 对不起,如果我让它听起来混乱和感谢阅读如何将firebase存储中所有子文件夹的第一个图像放入列表中(Dart/FLIFT),firebase,flutter,dart,firebase-storage,Firebase,Flutter,Dart,Firebase Storage,所以基本上我想从每个星期的子文件夹中获取第一张照片,并返回这些第一张照片的列表;在这种情况下,列表将有4个图像。我使用一个模型来表示带有3个参数的照片(FirebaseFile);参考URL、下载链接和文件名。我引用了该模型的视频: 上面的代码是我已经走了多远。“listFirst”函数返回给定文件夹中的第一张照片。“listWeek”函数列出对子文件夹的所有引用。到目前为止,我已经设法枚举了列表的所有结果和其中的一个firebasefile,但现在我不知道如何将其合并到未来的列表中以返回到我的
//get a list of the FIRST images in each week
static Future<List<FirebaseFile>> listWeek(String path) async {
final ref = FirebaseStorage.instance.ref(path);
final result = await ref.listAll();
result.prefixes.forEach((Reference ref) {
//Stuck here, not sure how to combine Future<FirebaseFile> into a list
Future<FirebaseFile> temp = listFirst(ref.fullPath);
});
}
//get the first image in a week
static Future<FirebaseFile> listFirst(String path) async{
final ref = FirebaseStorage.instance.ref(path);
final result = await ref.listAll();
final refItem = result.items[0];
final name = refItem.name;
final url = (await refItem.getDownloadURL()).toString();
return FirebaseFile(ref: refItem, name: name, url: url);
}
class FirebaseFile {
final Reference ref;
final String name;
final String url;
}
ccaian3/week_1/
ccaian3/week_2/
ccaian3/week_3/
ccaian3/week_4/