capture_screenshots 0.0.5
capture_screenshots: ^0.0.5 copied to clipboard
Provide easy way to take screenshot of single or multiple widget.
A simple Dart package for capturing screenshots of single widget or specific descendant widgets all at once.
Features #
Widgets
ScreenShotWidget: Wraps a list ofWidgets for which we want to take a screenshot.TakeScreenShot: Wraps all descendantScreenShotWidgets and provides a way to capture screenshots for all of them.
Controllers
ScreenShotController: Used to take a screenshot for children ofScreenShotWidget.TakeScreenShotController: Used to get screenshots from all descendantScreenShotWidgetwidgets. It provides a list of images, one for each descendantScreenShotWidget, in the same order as they occur.
Getting Started #
Using ScreenShotWidget widget
// Define a controller for `ScreenShotWidget` which will be used to take screenshots
ScreenShotController screenShotController = ScreenShotController();
// Other code...
// Wrap the widget list
const ScreenShotWidget(
children: [
Text("Widget to be captured as an image"),
]
);
// Other code...
// Use the controller's `captureScreenShot` method to get a screenshot of the widget
Uint8List capturedImage = await screenShotController.captureScreenShot();
Using TakeScreenShot widget
// Define a controller for `TakeScreenShot` which will be used to take screenshots of all descendant `ScreenShotWidget`s all at once
TakeScreenShotController takeScreenShotController = TakeScreenShotController();
// Other code...
// Wrap all descendant `ScreenShotWidget` widgets
TakeScreenShot(
controller: takeScreenShotController,
// Take a screenshot of the entire column widget
child: ScreenShotWidget(
children: [
Column(
children: [
// Only captured by wrapping `ScreenShotWidget` widget
const Text("Another Widget"),
// Capturing specific sub-part
const ScreenShotWidget(
children: [
Text("Hello World")
],
),
// Capturing specific sub-part
ScreenShotWidget(
children: [
Container(
width: 100,
height: 100,
color: Colors.red,
)
],
)
],
),
],
),
);