screenshot 0.0.2

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 86

screenshot #

A simple plugin to capture widgets as Images.

This plugin wraps your widgets inside RenderRepaintBoundary

Source

Getting Started #

This handy plugin can be used to capture any Widget including full screen screenshots & individual widgets like Text().

  1. Create Instance of Screenshot Controller
class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;
  File _imageFile;

  //Create an instance of ScreenshotController
  ScreenshotController screenshotController = ScreenshotController(); 

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }
  ...
}
  1. Wrap the widget that you want to capture inside Screenshot Widget. Assign the controller to screenshotController that you have created earlier
Screenshot(
    controller: screenshotController,
    child: Text("This text will be captured as image"),
),
  1. Take the screenshot by calling capture method. This will return a File
screenshotController.capture().then((File image) {
    //Capture Done
    setState(() {
        _imageFile = image;
    });
}).catchError((onError) {
    print(onError);
});

Example:

@override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Container(
        child: new Center(
          child: new Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Screenshot( //Screenshot Widget
                controller: screenshotController, //asign Controller
                //wrap the widgets that you want to capture as image
                child: <Widget>[ 
                      Text(
                        'You have pushed the button this many times:' +
                            _counter.toString(),
                      ),
                      FlutterLogo(),
                    ],
                ),
              _imageFile != null ? Image.file(_imageFile) : Container(),
            ],
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          _incrementCounter();
          _imageFile = null;
          screenshotController.capture().then((File image) {
            setState(() {
              _imageFile = image;
            });
          }).catchError((onError){
            print(onError);
          });
          
        },
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }
screenshot

By defualt, the captured image will be saved to Application Directory. Custom paths can be set using path parameter. Refer path_provider

final directory = (await getApplicationDocumentsDirectory ()).path; //from path_provide package
String fileName = DateTime.now().toIso8601String();
path = '$directory/$fileName.png';

screenshotController.capture(
    path:path //set path where screenshot will be saved
);

Note: #

Captured image may look pixelated. You can overcome this issue by setting value for pixelRatio

The pixelRatio describes the scale between the logical pixels and the size of the output image. It is independent of the window.devicePixelRatio for the device, so specifying 1.0 (the default) will give you a 1:1 mapping between logical pixels and the output pixels in the image.

screenshotController.capture(
    pixelRatio: 1.5
)

Known Bugs #

  • Image will not be updated if same filename is given multiple times

[0.0.2] - 16/02/2019

  • added support for older versions of path provider

[0.0.1] - 12/02/2019

  • initial release.

example/README.md

example #

A new Flutter project.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  screenshot: ^0.0.2

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:screenshot/screenshot.dart';
  
Version Uploaded Documentation Archive
0.0.2 Feb 16, 2019 Go to the documentation of screenshot 0.0.2 Download screenshot 0.0.2 archive
0.0.1 Feb 12, 2019 Go to the documentation of screenshot 0.0.1 Download screenshot 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
77
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
86
Learn more about scoring.

We analyzed this package on Apr 16, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.2.0
  • pana: 0.12.14
  • Flutter: 1.4.7

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Fix lib/screenshot.dart. (-0.50 points)

Analysis of lib/screenshot.dart reported 1 hint:

line 17 col 3: The class 'Future' was not exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions.

Format lib/src/main.dart.

Run flutter format to format lib/src/main.dart.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
path_provider ^0.4.1 0.4.1 0.5.0+1
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test