Skip to content
pubscout

mocktail_image_network

1.3.0, released 7 months ago by felangel.dev

Mock Image.network in widget tests without real network calls

$ flutter pub add mocktail_image_network
Source repository

What it does

Allows developers to test widgets containing Image.network by mocking the internal HTTP client. It prevents HTTP 400 errors during widget tests and avoids real network requests.

AI-written summary of version 1.3.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You are writing widget tests for Flutter components that load images via Image.network
  • You want to prevent network requests during test execution

Skip it when

  • You are writing non-Flutter Dart tests that do not involve widget rendering
  • You need real network connectivity in integration tests

Strengths

  • Easy to use with the mockNetworkImages wrapper
  • Prevents failing network image tests in Flutter
  • Supports customizable image bytes and image resolvers

Weaknesses

  • Limited to mocking network images in tests

Setup

Kind
Flutter widgets
Effort
Low
Code generation
No
Direct dependencies
1
void main() {
  testWidgets('can use mocktail for network images', (tester) async {
    await mockNetworkImages(() async => tester.pumpWidget(FakeApp()));
    expect(find.byType(Image), findsOneWidget);
  });
}

Alternatives

Packages that do the same job and could replace mocktail_image_network.

  • mockito

    Alternative general mocking framework that can be used for custom mock implementations.

Works with

Packages commonly used together with mocktail_image_network: ones it builds on, ones built on it, and its own family.