gpt4 book ai didi

flutter - 使用 NetworkImage 显示来自 Google Drive 的图像

转载 作者:行者123 更新时间:2023-12-04 12:08:06 25 4
gpt4 key购买 nike

我正在尝试将一些图像加载到 gridview 中。每个 GridTile 都包含一个带有使用 NetworkImage 装饰的容器。我使用的所有图像都存储在 google drive 中,问题是由于某种原因,flutter 不喜欢 Google Drive url。我试过以下网址:

  • https://docs.google.com/uc?id= {fileId}
  • https://drive.google.com/uc?export=view&id= {fileId}
  • https://drive.google.com/a/ {domain}.com/uc?authuser=0&id=fileId}&export=download
  • https://drive.google.com/file/d/ {fileId}/查看

  • 以上都不起作用。它引发以下错误:

    The following _Exception was thrown resolving an image codec: Exception: Could not instantiate image codec.



    我注意到所有这些 url 最终都重定向到另一个链接,可能是图像被缓存的地方。这就是不工作的原因吗?如果是这样,我如何强制它遵循重定向?

    这是相关的一段代码:
    String imgUrl = "https://drive.google.com/file/d/$fileId/view";
    GridTile(
    child: InkWell(
    onTap: () {
    openDriveImage(fileId);
    },
    child: Container(
    margin: EdgeInsets.all(5.0),
    decoration: BoxDecoration(
    border: Border.all(
    color: Colors.black38,
    ),
    shape: BoxShape.rectangle,
    image: DecorationImage(
    fit: BoxFit.fitWidth,
    image: NetworkImage(imgUrl),
    ),
    ),
    ),
    ),

    最佳答案

    以下是步骤:

  • 右击图片,点击Share,如下图; enter image description here
  • 在出现的对话框中,确保从下拉列表中选择的选项是Anyone with the link can view如下图:
    enter image description here
  • 之后,单击 Copy link 然后将其粘贴到
  • 某处
  • 格式应该是这样的 https://drive.google.com/file/d/1VdjEgb0aZl9IZa2jOzGU5_SNbmlmeiCj/view?usp=sharing

    https://drive.google.com/file/d/<FILE_ID>/view?usp=sharing

  • 复制 在我的例子中是 1VdjEgb0aZl9IZa2jOzGU5_SNbmlmeiCj
  • 按以下格式将其附加到此链接:

    https://drive.google.com/uc?export=view&id=<FILE_ID>

  • 以我为例,最后一个链接是:

    https://drive.google.com/uc?export=view&id=1VdjEgb0aZl9IZa2jOzGU5_SNbmlmeiCj

  • 最后获取该链接并粘贴到 NetworkImage()Image.network() 小部件中,然后完成
  • 关于flutter - 使用 NetworkImage 显示来自 Google Drive 的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59849232/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com