Flutter web显示网络图片OCRS(资源跨域)问题

出错提示:

Failed to load network image.
Image URL: https://tva1.sinaimg.cn/large/006y8mN6gy1g72j6nk1d4j30u00k0n0j.jpg
Trying to load an image from another domain? Find answers at:

图片资源跨域问题详细解释可以去官方查看官方解释
这里给出解决方式的一种:

Image(image: NetworkImage("https://tva1.sinaimg.cn/large/006y8mN6gy1g72j6nk1d4j30u00k0n0j.jpg"),
  fit: BoxFit.cover,
),

替代方式之一:

class MyImage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    String imageUrl = "https://tva1.sinaimg.cn/large/006y8mN6gy1g72j6nk1d4j30u00k0n0j.jpg";
    // https://github.com/flutter/flutter/issues/41563
    // ignore: undefined_prefixed_name
    ui.platformViewRegistry.registerViewFactory(
      imageUrl,
          (int _) => ImageElement()..src = imageUrl,
    );
    return HtmlElementView(
      viewType: imageUrl,
    );
  }
}

更多 :https://github.com/flutter/flutter/issues/41563

你可能感兴趣的:(Flutter web显示网络图片OCRS(资源跨域)问题)