Flutter_cached_network_image: CachedNetworkImage is stuck in progress state

Created on 14 Jun 2020  路  6Comments  路  Source: Baseflow/flutter_cached_network_image

馃悰 Bug Report

According to the documentation, an http call during widgets test will fail with a 400 status code.

So why the code below never displays the errorWidget ? However it displays the progressWidget and gets stuck there.

  testWidgets('Cached networked image 400', (tester) async {
    final widget = CachedNetworkImage(
      imageBuilder: (
        context,
        url,
      ) =>
          Container(
        key: Key('image'),
      ),
      progressIndicatorBuilder: (context, url, progress) => Container(
        key: Key('progress'),
      ),
      errorWidget: (context, url, error) => Container(
        key: Key('failed'),
      ),
      imageUrl: 'https://example.com/image.png',
    );
    await tester.pumpWidget(
      MediaQuery(
        data: MediaQueryData(),
        child: MaterialApp(
          home: widget,
        ),
      ),
    );

    await tester.pumpAndSettle();
    expect(find.byKey(Key('progress')), findsOneWidget); // this should be findsNothing but why does it pass here?
    expect(find.byKey(Key('failed')), findsOneWidget);
    expect(find.byKey(Key('image')), findsNothing);

I am getting:

Expected: exactly one matching node in the widget tree
Actual: _KeyFinder:] (ignoring offstage widgets)>

The plugin: https://pub.dev/packages/cached_network_image

Expected behavior

Progress Widget should not display anymore
Image Widget should not display
Failed Widget should display

Reproduction steps

Just run the above code in test.

Configuration

Version: 2.2.0+1

Platform:

  • [x] :iphone: iOS
  • [x] :robot: Android

Most helpful comment

Like this? https://medium.com/@ncuillery/golden-testing-using-cachednetworkimage-1b488c653af3

All 6 comments

FYI, I've traced the issue and found that it keeps in progress since it stuck on open method of cache object provider: https://github.com/Baseflow/flutter_cache_manager/blob/develop/flutter_cache_manager/lib/src/storage/cache_object_provider.dart#L15

I guess it is better to use a mock CacheManager, because than you really only test the image, and not the CacheManager as well.

Unable to load image. Loading spinner keep on spinning.

I guess bug reporter & commenters are looking for examples from community :)

Like this? https://medium.com/@ncuillery/golden-testing-using-cachednetworkimage-1b488c653af3

For now I'll close this issue as it looks like it is solved with this blog post. For improving testability there are other issues like https://github.com/Baseflow/flutter_cache_manager/issues/2

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nashfive picture nashfive  路  5Comments

gjrjf picture gjrjf  路  4Comments

srburton picture srburton  路  6Comments

digitaldangal picture digitaldangal  路  5Comments

flutteradv picture flutteradv  路  6Comments