Skip to content

CachedNetworkImage is stuck in progress state #416

Description

@tolotrasamuel

🐛 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:<zero widgets with key [<'failed'>] (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:

  • 📱 iOS
  • 🤖 Android

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions