Flutter 如何在flatter中显示来自Wordpress的图像

Flutter 如何在flatter中显示来自Wordpress的图像,flutter,dart,Flutter,Dart,我有密码 return Post( id: json['id'], title: json['title']['rendered'], content: json['content']['rendered'], date: json['date'] != null ? json['date'].toString().replaceFirst('T', ' ') : null, image: json['

我有密码

return Post(
      id: json['id'],

      title: json['title']['rendered'],
      content: json['content']['rendered'],
      date: json['date'] != null
        ? json['date'].toString().replaceFirst('T', ' ')
        : null,
      image: json['_links']['wp:featuredmedia'] != null
        ? json['_links']['wp:featuredmedia'][0]['source_url']
        : null,
      excerpt: json['excerpt']['rendered'],
      author: json['author'].toString(),
    );
  }
然后我用

post.image != null
              ? Image.network(post.image) 
但我的应用程序中没有图像。错误:异常:无法实例化图像编解码器。
如何修复它?

否,您可以将wp:featuredmedia的链接直接指定给image属性,然后使用image.network()小部件随时随地呈现该属性

只需查看API的JSON响应中存储的特色媒体链接的位置。遍历JSON树并分配该值

这会有用的。

试试这个

image: json["_embedded"]["wp:featuredmedia"][0]["source_url"],

它对我来说很好

我假设您正在使用以下基本链接

https://yourwebsite.com/wp-json/wp/v2/posts
修复方法是更改基本URL,如下所示

https://yourwebsite.com/wp-json/wp/v2/posts?_embed
然后使用以下命令:

image: json["_embedded"]["wp:featuredmedia"][0]["source_url"]

您可以添加您的图像源url吗?问题可能链接到文件urlYes。URL的问题。这是调试器中的我的链接。您可能应该从
媒体\u详细信息
而不是
\u链接
中解析图像URL。现在,出现了此错误:异常。NoSuchMethodError(NoSuchMethodError:对null调用了方法“[]”。Receiver:null尝试调用:[](“wp:featuredmedia”))如果这样做,我将收到错误消息(类型字符串不是int类型的子类型)。我在我的['href']之后接收此消息。这是我的完整图像[''u链接]['wp:featuredmedia'][0]['href']['media\u details']['file']