flutter 中web应用,在微信开发工具打开链接,报错imageCodecException
侧边栏壁纸
  • 累计撰写 2 篇文章
  • 累计收到 0 条评论

flutter 中web应用,在微信开发工具打开链接,报错imageCodecException

seeking
2025-10-28 / 0 评论 / 3 阅读 / 正在检测是否收录...

报错如下:
imageCodecException: Failed to decode image using the browser's ImageDecoder API.
Image source: encoded image bytes
Original browser eror: Expected a value of type'JSObject,but gotene of type'Null'

原因分析:
这个错误是 Flutter Web 在微信开发者工具中遇到的图像解码问题

解决方法:
修改 Flutter Web 渲染设置
在 web/index.html 中添加以下配置:

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>My Flutter App</title>
  
  <!-- 添加以下 meta 标签 -->
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="IE=Edge">
  
  <!-- 禁用某些浏览器特性 -->
  <script>
    window.flutterWebRenderer = "html"; // 强制使用 HTML 渲染器
  </script>
  
  <script src="main.dart.js" type="application/javascript"></script>
</head>
<body>
  <script>
    // 图像加载错误处理
    window.addEventListener('error', function(e) {
      if (e.target && (e.target.tagName === 'IMG' || e.target.tagName === 'IMAGE')) {
        console.log('Image load error:', e.target.src);
        e.preventDefault();
      }
    }, true);
  </script>
</body>
</html>
1

评论 (0)

取消