Baseflow / flutter_cached_network_image

Download, cache and show images in a flutter app
https://baseflow.com
2.44k stars 656 forks source link

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

Open mregnauld opened 1 year ago

mregnauld commented 1 year ago

🐛 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 byerrorWidget`.

Reproduction steps

  1. Disconnect your device from the Internet
  2. Launch the app
  3. 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:

kwul0208 commented 12 months ago

is there a solution yet?