Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Images fails to load the second time on web when compiled to wasm

未关闭
#1,007 4 条评论 9 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
dart, flutter, wasm
领域
web-dev

调研方向

使用 lib/main.dart 中的示例重现该问题,并使用 flutter run -d chrome --wasm 运行。比较有无 errorListener 时的导航序列;在不提供 errorListener 的情况下返回并重新打开页面后图像再次加载,即表示完成。

由索引模型根据 Issue 内容生成。

描述

🐛 Bug Report

When compiled to wasm, images don't load the second time if navigated back and forth again, giving the below error:

ImageCodecException: Failed to decode image using the browser's ImageDecoder API.
Image source: https://docs.flutter.dev/assets/images/dash/dash-fainting.gif
Original browser error: JavaScriptError

But, if you provide the errorListener param some value, this error mysteriously fixes.

Expected behavior

Images should load every time without giving any errors even if errorListener is not provided.

Reproduction steps
  1. Copy below sample code into lib/main.dart
  2. Run on web with wasm using the below command:
    flutter run -d chrome --wasm
    
  3. Click on Open Page 1 button and wait for the image to load
  4. Click back and wait 5 seconds
  5. Once again click Open Page 1 button
  6. See image loading error
  7. Now uncomment the errorListener line in sample code
  8. Enter r in terminal to hot restart
  9. Repeat steps 3-5
  10. See the error is fixed magically
Configuration

Version: 3.4.1

Platform:

  • 📱 iOS
  • 🤖 Android
  • 🕸️ Web
Additional Data
Sample Code

import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';

void main() => runApp(const MyApp());

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final _urls = [
    'https://docs.flutter.dev/assets/images/dash/dash-fainting.gif',
    'https://picsum.photos/250?image=2',
  ];

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Web Images',
      home: Builder(
        builder: (context) {
          return Scaffold(
            appBar: AppBar(title: Text('Web Images')),
            body: Center(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  ElevatedButton(
                    onPressed: () => _onPressed(context, 0),
                    child: Text('Open Page 1'),
                  ),
                  const SizedBox(height: 20),
                  ElevatedButton(
                    onPressed: () => _onPressed(context, 1),
                    child: Text('Open Page 2'),
                  ),
                ],
              ),
            ),
          );
        },
      ),
    );
  }

  void _onPressed(BuildContext context, int index) {
    Navigator.of(context).push(
      MaterialPageRoute(builder: (context) => NewWidget(url: _urls[index])),
    );
  }
}

class NewWidget extends StatelessWidget {
  const NewWidget({super.key, required this.url});

  final String url;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Center(
        child: CachedNetworkImage(
          imageUrl: url,
          placeholder: (_, _) => CircularProgressIndicator.adaptive(),
          // ! Uncomment the line below to see magic
          // errorListener: (_) {},
        ),
      ),
    );
  }
}

主要语言
Dart
星标
2.6k
派生
734
平均合并
3 天 10 小时
30 天内合并 PR
14

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Baseflow/flutter_cached_network_image 的其他 Issue

查看 Baseflow/flutter_cached_network_image 的全部 Issue

相似的 Issue

更多 Dart Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。