Baseflow / Baseflow/flutter_cached_network_image

CachedNetworkImage() in AnimatedList crash when not connected to the Internet

Open
#851 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Dart
Stars
2.6k
Forks
731
Avg merge
3d 9h
Merged PRs (30d)
1

Description

## 🐛 Bug Report

When I scroll an `AnimatedList` containing items, each one containing a `CachedNetworkImage`, when the device is not connected to the Internet, I got errors in the logs, even though I use `errorWidget`.

### Expected behavior

I should be able to scroll without any error in the logs and without seeing the error page.
Every `CachedNetworkImage() that can not download the image should just display the error widget returned by `errorWidget`.

### Reproduction steps

1. Disconnect your device from the Internet
2. Launch the app
3. Scroll the list, maybe for quite a few seconds

### Code

```Dart
class MyHomePage extends StatefulWidget
{
const MyHomePage({super.key});

@override
State createState() => _MyHomePageState();
}

class _MyHomePageState extends State
{

final _scrollController = ScrollController();


@override
Widget build(BuildContext context)
{
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: const Text("List demo"),
),
body: SafeArea(
child: AnimatedList(
controller: _scrollController,
initialItemCount: 100,
itemBuilder: (context, index, animation)
{
return Container(
constraints: const BoxConstraints(minHeight: 64),
padding: const EdgeInsets.all(8),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [

CachedNetworkImage(
imageUrl: "http://s519716619.onlinehome.fr/test/image.jpg?id=$index",
width: 80,
height: 60,
errorWidget: (context, url, error) => const Icon(Icons.error),
),

const SizedBox(width: 8),

Expanded(
child: Text(
"Item $index",
),
),

]
),
);
},
),
),
);
}

}

```

### Configuration

**Version:** 3.2.3

**Platform:**
- [ x] :iphone: iOS
- [x ] :robot: Android

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.