flutter 引发“格式异常:在图像小工具上使用'from.createSignedUrls()'时,方案字符””非法

kmpatx3s  于 2022-11-17  发布在  Flutter
关注(0)|答案(1)|浏览(105)

我尝试在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');
                }
              })
oalqel3c

oalqel3c1#

您需要访问signedUrl参数来访问图像的URL。

Image.network(
  snapshot.data![index].signedUrl,
  fit: BoxFit.fill,
)

对于某些清理,可以将getUrls的返回类型更改为List<SignedUrl>,如下所示:

Future<List<SignedUrl>> getURLs()

同时更新FutureBuilder的类型:

FutureBuilder<List<SignedUrl>>(

相关问题