run_with_network_images 0.0.1 copy "run_with_network_images: ^0.0.1" to clipboard
run_with_network_images: ^0.0.1 copied to clipboard

Helper for providing mocked Image.network response in Flutter widget tests.

example/main.dart

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Image.network(
        'https://dev-yakuza.posstree.com/assets/images/yakuza.jpg',
      ),
    );
  }
}

void main() {
  testWidgets('Network image is rendered in widget test', (
    WidgetTester tester,
  ) async {
    await runWithNetworkImages(() async {
      await tester.pumpWidget(const MyApp());

      final image = tester.widget<Image>(find.byType(Image));
      expect(
        (image.image as NetworkImage).url,
        'https://dev-yakuza.posstree.com/assets/images/yakuza.jpg',
      );
    });
  });
}
1
likes
150
pub points
64%
popularity

Publisher

unverified uploader

Helper for providing mocked Image.network response in Flutter widget tests.

Repository (GitHub)
View/report issues
Contributing

Documentation

API reference

License

MIT (license)

Dependencies

build_runner, flutter, mockito

More

Packages that depend on run_with_network_images