network_image_mock
2.1.1, released 4 years ago by stelynx.com
Utility for mocking Image.network responses in Flutter widget tests.
What it does
Provides a mock response wrapper for Image.network calls in Flutter widget tests to prevent 400 errors. Wraps widget testing functions inside a mockNetworkImagesFor helper.
AI-written summary of version 2.1.1, based on the package's README and metadata. Report an inaccuracy
Use it when
- You are writing Flutter widget tests that load network images.
- You want to avoid 400 responses from Image.network during testing.
Skip it when
- You are writing production code (this is strictly for tests).
Strengths
- Simple and straightforward API.
- Prevents Image.network from crashing tests.
- Supports null safety.
Weaknesses
- Limited to mocking network image responses in a testing context.
Setup
- Kind
- Flutter widgets
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 1
Install under dev_dependencies in pubspec.yaml.
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: Image.network(''));
void main() {
testWidgets(
'should properly mock Image.network and not crash',
(WidgetTester tester) async {
mockNetworkImagesFor(() => tester.pumpWidget(makeTestableWidget()));
},
);
}Alternatives
Packages that do the same job and could replace network_image_mock.
- mocktail_image_network
Mock Image.network in widget tests without real network calls
81Compare - golden_test
A zero-dependency wrapper for Flutter golden tests with theme, locale, and multi-device support.
79Compare - build_test
Utilities for unit testing Dart build_runner builders in memory
78Compare - golden_screenshot
Utilities to automate screenshot generation using Flutter's golden tests.
76Compare
Works with
Packages commonly used together with network_image_mock: ones it builds on, ones built on it, and its own family.