这是indexloc提供的服务,不要输入任何密码

test_screenshot 0.0.8 copy "test_screenshot: ^0.0.8" to clipboard
test_screenshot: ^0.0.8 copied to clipboard

Take screenshots during your flutter unit tests

Take screenshots during your flutter unit tests for debugging purpose.

usage #

  • Wrap your widget tree with a Screenshotter widget
  • call tester.screenshot()
  • profit
  testWidgets('should create a screenshot', (tester) async {
    await tester.pumpWidget(
      Screenshotter(
        child: MaterialApp(
          home: Scaffold(body: Center(child: Icon(Icons.home))),
        ),
      ),
    );

    await tester.screenshot(path: 'screenshot.png');
  });

Fonts, icons and images #

By default, flutter will use its own font during unit tests. It will also not allow network images to be rendered.

To allow fonts and network images you can use the screenshotWithImages() method.

  testWidgets('should create a screenshot with fonts and images',
      (tester) async {

    await tester.screenshotWithImages(() async {
      await tester.pumpWidget(
        Screenshotter(
          child: MaterialApp(
            home: Scaffold(
              body: Center(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Text('Below is an icon'),
                    Icon(Icons.home),
                    Image.network(
                      'https://images.pexels.com/photos/1805164/pexels-photo-1805164.jpeg',
                      height: 300,
                      width: 300,
                    ),
                  ],
                ),
              ),
            ),
          ),
        ),
      );
      // do things...
    }, path: 'file_with_image.png');

  });

6
likes
140
points
1.37k
downloads

Publisher

unverified uploader

Weekly Downloads

Take screenshots during your flutter unit tests

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

file, flutter, flutter_test, image, platform

More

Packages that depend on test_screenshot