flutter_cached_network_image
flutter_cached_network_image copied to clipboard
CachedNetworkImage() in AnimatedList crash when not connected to the Internet
🐛 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
- Disconnect your device from the Internet
- Launch the app
- Scroll the list, maybe for quite a few seconds
Code
class MyHomePage extends StatefulWidget
{
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage>
{
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
is there a solution yet?