flutter_image_test_utils 1.0.0 copy "flutter_image_test_utils: ^1.0.0" to clipboard
flutter_image_test_utils: ^1.0.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.

ℹī¸ This is an inspiration of: image_test_utils that is discontinued and mock_image_http from Flutter team.

Usage #

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

flutter pub add flutter_image_test_utils

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

dev_dependencies:
  flutter_image_test_utils: ^1.0.0

In your widget tests, simple import the library and 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: [ ... ]
  );
});
1
likes
140
pub points
30%
popularity

Publisher

unverified uploader

Provides an easier and simple way to test flutter network images

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

mocktail

More

Packages that depend on flutter_image_test_utils