我尝试在flutter应用程序屏幕上显示来自supabase bucket的多个图像,但当我尝试从列表中传递每个签名的URL时,我收到FormatException
下面是我的FutureBuilder代码
Future<List?> getURLs() async {
final List<FileObject> path = await Supabase.instance.client.storage
.from("public-image")
.list(path: user!.id);
final List<String> fpath =
path.map((e) => '${user!.id}/${e.name}').toList();
final signedUrls = await Supabase.instance.client.storage
.from("public-image")
.createSignedUrls(fpath, 120);
return signedUrls;
}
urls = DatabaseService().getURLs();
FutureBuilder<List?>(
future: urls,
builder: (context, snapshot) {
if (!snapshot.hasError && snapshot.hasData) {
return SizedBox(
height: 500,
child: ListView.builder(
scrollDirection: Axis.vertical,
itemCount: snapshot.data!.length,
itemBuilder: (BuildContext context, int index) {
return Card(
semanticContainer: true,
clipBehavior: Clip.antiAliasWithSaveLayer,
child: Image.network(
'${snapshot.data![index]}',
fit: BoxFit.fill,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
elevation: 5,
margin: EdgeInsets.all(10),
);
}),
);
} else {
return Text('error');
}
})
1条答案
按热度按时间oalqel3c1#
您需要访问
signedUrl
参数来访问图像的URL。对于某些清理,可以将getUrls的返回类型更改为
List<SignedUrl>
,如下所示:同时更新
FutureBuilder
的类型: