flutter_image_test_utils 1.1.0 copy "flutter_image_test_utils: ^1.1.0" to clipboard
flutter_image_test_utils: ^1.1.0 copied to clipboard

Provides an easier and simple way to test flutter network images.

Flutter Image Test Utils 🖼️

This package provides a simple and easier way to test flutter widgets that are using `Image.network` or `CachedNetworkImage`, by using a mock HTTP client with mocktail stubs that responds with a fake image for every requests.

Drop a 👍🏽 and a ⭐ to support the project!

Note

This is an inspiration of: image_test_utils that is discontinued and mock_image_http from the Flutter team.

Important

On the web, this package does not mock the HTTP client. It only executes the callback. This is because dart:io is not available on the web.

Usage #

Run this command on the root folder of your Flutter project:

flutter pub add -d flutter_image_test_utils

Or simple paste the following dependency on your pubspec.yaml file:

dev_dependencies:
  flutter_image_test_utils: ^1.1.0

Import the library and wrap your test function with: provideMockedNetworkImages(), for example:

import ...
import 'package:flutter_image_test_utils/flutter_image_test_utils.dart';

testWidgets('should do something', (tester) async {
  provideMockedNetworkImages(
    () async {
      await tester.pumpWidget(
        MaterialApp(
          home: MyWidget(),
        ),
      );
      ...
    },
  );
});

You can also use your own image bytes value, you just need to pass it to the function with the imageBytes parameter:

import ...

testWidgets('should do something', (tester) async {
  provideMockedNetworkImages(
    () async {
      ...
    },
    imageBytes: [ ... ]
  );
});
2
likes
150
points
9.24k
downloads

Publisher

verified publisherwilliamamaral.com

Weekly Downloads

Provides an easier and simple way to test flutter network images.

Repository (GitHub)
View/report issues

Topics

#widget-tests #flutter #network-image

Documentation

Documentation
API reference

License

MIT (license)

Dependencies

mocktail

More

Packages that depend on flutter_image_test_utils