Aus öffentlichen Paketdaten erstellte Orientierung.
Das Screenshot-Paket ermöglicht die Runtime-Aufnahme beliebiger Flutter-Widgets als Bild über mehrere Plattformen hinweg. Es erlaubt Entwicklern, während der App-Ausführung programmgesteuert Screenshots von Widgets zu erstellen, was nützlich für Debugging, Tests oder den Austausch visueller Inhalte ist. Das Paket unterstützt Android, iOS, Web, macOS, Windows und Linux und ist daher äußerst vielseitig. Es integriert sich nahtlos in den Rendering-Pipeline von Flutter und bietet eine einfache API zum Generieren von Bildern aus Widget-Bäumen. Ideal für Anwendungen, die dynamische Bildgenerierung oder visuelle Rückmeldung erfordern.
Anwendungsfälle
Debugging von UI-Problemen
Erstellen von freigebaren Bildern
Automatisierte Tests
visuelle Dokumentation
App-Tutorials
Vorschau-Funktionen
Hauptmerkmale
Runtime-Widget-Screenshot-Aufnahme
Plattformübergreifende Unterstützung
Einfache API-Integration
Hochwertige Bildausgabe
Unterstützt alle wichtigen Plattformen
Keine externen Abhängigkeiten
Geeignet für
Entwickler, die dynamische Screenshots benötigen
Test- und QA-Teams
Apps mit visuellen Freigabefunktionen
Bildungs- oder Lernanwendungen
UI-Prototyping-Tools
Debugging komplexer Layouts
Hinweise
Leistungsbeeinflussung bei großen Widgets
Speicherbelegung für hochauflösende Bilder
Erforderliche Berechtigungen auf mobilen Plattformen
Nicht geeignet für die Echtzeit-Videobearbeitung
Beschränkt auf statische Widget-Vorschaubilder
Kann plattformspezifische Konfiguration erfordern
Original-README
Originaler README-Schnappschuss aus dem verknüpften Quell-Repository. Aktuelle Inhalte finden Sie im Repository.
A simple package to capture widgets as Images. Now you can also capture the widgets that are not rendered on the screen!
You can capture a long Invisible widgets by using captureFromLongWidget function.
var randomItemCount = Random().nextInt(100);
////// Step 1: Create Long widget using Column.///var myLongWidget = Builder(builder: (context) {
returnContainer(
padding: constEdgeInsets.all(30.0),
decoration: BoxDecoration(
border:
Border.all(color: Colors.blueAccent, width: 5.0),
color: Colors.redAccent,
),
////// Note: Do not use Scrolling widget, instead place your children in Column. /// /// Do not use widgets like 'Expanded','Flexible',or 'Spacer'///
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
for (int i = 0; i < randomItemCount; i++)
Text("Tile Index $i"),
],
));
});
////// Step 2: /// Use `captureFromLongWidget` function for taking screenshot.///
screenshotController
.captureFromLongWidget(
InheritedTheme.captureAll(
context,
Material(
child: myLongWidget,
),
),
delay: Duration(milliseconds: 100),
context: context,
////// Additionally you can define constraint for your image.////// constraints: BoxConstraints(/// maxHeight: 1000,/// maxWidth: 1000,/// )
)
.then((capturedImage) {
// Handle captured image
});
Saving images to Specific Location
For this you can use captureAndSave method by passing directory location. By default, the captured image will be saved to Application Directory. Custom paths can be set using path parameter. Refer path_provider
Note
Method captureAndSave is not supported for web.
final directory = (await getApplicationDocumentsDirectory ()).path; //from path_provide packageString fileName = DateTime.now().microsecondsSinceEpoch;
path = '$directory';
screenshotController.captureAndSave(
path //set path where screenshot will be saved
fileName:fileName
);
Saving images to Gallery
If you want to save captured image to Gallery, Please use https://github.com/hui-z/image_gallery_saver
Example app uses the same to save screenshots to gallery.
Sharing Captured Images
await _screenshotController.capture(delay: constDuration(milliseconds: 10)).then((Uint8List image) async {
if (image != null) {
final directory = awaitgetApplicationDocumentsDirectory();
final imagePath = awaitFile('${directory.path}/image.png').create();
await imagePath.writeAsBytes(image);
/// Share PluginawaitShare.shareFiles([imagePath.path]);
}
});
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.