如何为Firebase创建类似于UI的文件浏览器?我尝试使用listAll(),然后在用户单击目录时再次调用listAll(),但它没有刷新视图。
我还尝试了递归调用该函数,该函数在用户单击目录时调用构建ListView小部件的功能,但是它仅显示存储的根级别,并且在单击目录时不会更新视图。 / p>
我还尝试将引用存储在类对象中并调用setState(),但它也没有更新视图。我在这里做错了什么?任何帮助表示赞赏!
Widget showDirectories(firebase_storage.ListResult directories) {
List<firebase_storage.Reference> directoryList = directories.prefixes;
List<firebase_storage.Reference> items = directories.items;
return Column(
children: <Widget>[
ListView.builder(
shrinkWrap: true,
itemCount: directoryList.length,
itemBuilder: (BuildContext context, int index) {
return Card(
child: ListTile(
title: Text(directoryList[index].name),
subtitle: Text(directoryList[index].fullPath),
onTap: () async {
//open the directory and get the list of items in there
firebase_storage.ListResult subDirectory =
await directoryList[index]
.listAll();
return showDirectories(subDirectory);
},
),
);
},
),
==========其他版本========
Widget showDirectories() {
List<firebase_storage.Reference> directoryList = head.prefixes;
List<firebase_storage.Reference> items = head.items;
return Column(
children: <Widget>[
ListView.builder(
shrinkWrap: true,
itemCount: directoryList.length,
itemBuilder: (BuildContext context, int index) {
return Card(
child: ListTile(
title: Text(directoryList[index].name),
subtitle: Text(directoryList[index].fullPath),
onTap: () async {
//open the directory and get the list of items in there
firebase_storage.ListResult subDirectory =
await directoryList[index].listAll();
setState(() {
head = subDirectory;
});
},
),
);
},
),
我关注了here
中的文档