Network Image Mock

Pub Version Lint & Test

A utility for providing mocked response to in Flutter widget tests.


Since you are here you probably already know that calling results in 400 response in Flutter widget tests. The reason for this is that default HTTP client in tests always return a 400.

So, what can we do about it? Instead of copying the whole code over and over again for mocking the HTTP client, I created this package. It is heavily inspired by roughike/image_test_utils, however that package is not being maintained despite multiple pull requests asking for bumping the mockito version and making the package usable again.


This package should be installed under dev_dependencies like

  network_image_mock: ^1.0.2


The package is quite straightforward to use. All you have to do is include it in your test file and wrap widget testing functions that require proper response in mockNetworkImagesFor() function provided by this package. A full test example could look like this.

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:network_image_mock/network_image_mock.dart';

Widget makeTestableWidget() => MaterialApp(home:''));

void main() {
    'should properly mock and not crash',
    (WidgetTester tester) async {
      mockNetworkImagesFor(() => tester.pumpWidget(makeTestableWidget()));

This is actually an example taken from tests for this package.


There is not much to contribute since the package serves its purpose, however, in chance of needing to bump or adjust some version, or any other suggestion for that matter, please read CONTRIBUTING.