提交 1265f8d5 authored 作者: Sachin Ganesh's avatar Sachin Ganesh

Release 1.1.0

上级 727e4860
## [1.1.0] - 13/06/2021
* Add support for invisible widget capture
## [1.0.0-nullsafety.0] - 10/02/2021 ## [1.0.0-nullsafety.0] - 10/02/2021
* Add nullsafety * Add nullsafety
...@@ -6,7 +9,6 @@ ...@@ -6,7 +9,6 @@
* support for web and windows * support for web and windows
* Add captureAndSave method. * Add captureAndSave method.
## [0.2.0] - 10/06/2020 ## [0.2.0] - 10/06/2020
* Add captureAsUiImage method * Add captureAsUiImage method
......
...@@ -6,7 +6,20 @@ This package wraps your widgets inside [RenderRepaintBoundary](https://docs.flut ...@@ -6,7 +6,20 @@ This package wraps your widgets inside [RenderRepaintBoundary](https://docs.flut
[Source](https://stackoverflow.com/a/51118088) [Source](https://stackoverflow.com/a/51118088)
<img src="https://github.com/SachinGanesh/screenshot/raw/master/assets/screenshot.gif" alt="screenshot" width="200"/> ---
<br>
<div style="display: flex;">
<div style="flex: 40%; padding: 5px;">
<img src="https://github.com/SachinGanesh/screenshot/raw/master/assets/screenshot.gif" alt="screenshot"/>
</div>
<div style="flex: 60%; padding: 5px;">
<p>&nbsp; Capture a widget part of the widget tree:</p>
<img src="https://github.com/SachinGanesh/screenshot/raw/master/assets/code1.png" alt="screenshot"/>
<hr>
<p>&nbsp;Capture an invisible widget (a widget which is not part of the widget tree):</p>
<img src="https://github.com/SachinGanesh/screenshot/raw/master/assets/code2.png" alt="screenshot"/>
</div>
</div>
--- ---
## Getting Started ## Getting Started
...@@ -181,7 +194,7 @@ The solution is to add a small delay before capturing. ...@@ -181,7 +194,7 @@ The solution is to add a small delay before capturing.
```dart ```dart
screenshotController.capture(delay: Duration(milliseconds: 10)) screenshotController.capture(delay: Duration(milliseconds: 10))
``` ```
---
## Known Issues ## Known Issues
- Platform Views are not supported. (Example: Google Maps, Camera etc) - Platform Views are not supported. (Example: Google Maps, Camera etc)
---
\ No newline at end of file
...@@ -31,7 +31,7 @@ class MyApp extends StatelessWidget { ...@@ -31,7 +31,7 @@ class MyApp extends StatelessWidget {
} }
class MyHomePage extends StatefulWidget { class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key); MyHomePage({Key? key, required this.title}) : super(key: key);
final String title; final String title;
@override @override
...@@ -86,8 +86,8 @@ class _MyHomePageState extends State<MyHomePage> { ...@@ -86,8 +86,8 @@ class _MyHomePageState extends State<MyHomePage> {
onPressed: () { onPressed: () {
screenshotController screenshotController
.capture(delay: Duration(milliseconds: 10)) .capture(delay: Duration(milliseconds: 10))
.then((Uint8List capturedImage) async { .then((capturedImage) async {
ShowCapturedWidget(context, capturedImage); ShowCapturedWidget(context, capturedImage!);
}).catchError((onError) { }).catchError((onError) {
print(onError); print(onError);
}); });
......
...@@ -32,17 +32,14 @@ class ScreenshotController { ...@@ -32,17 +32,14 @@ class ScreenshotController {
pixelRatio: pixelRatio, pixelRatio: pixelRatio,
delay: delay, delay: delay,
); );
if (content != null) { PlatformFileManager fileManager = PlatformFileManager();
PlatformFileManager fileManager = PlatformFileManager();
return fileManager.saveFile(content, directory, name: fileName); return fileManager.saveFile(content!, directory, name: fileName);
}
return null;
} }
Future<Uint8List> capture({ Future<Uint8List?> capture({
double? pixelRatio, double? pixelRatio,
Duration delay: const Duration(milliseconds: 20), Duration delay = const Duration(milliseconds: 20),
}) { }) {
//Delay is required. See Issue https://github.com/flutter/flutter/issues/22308 //Delay is required. See Issue https://github.com/flutter/flutter/issues/22308
return new Future.delayed(delay ?? Duration(milliseconds: 20), () async { return new Future.delayed(delay ?? Duration(milliseconds: 20), () async {
...@@ -141,7 +138,7 @@ class ScreenshotController { ...@@ -141,7 +138,7 @@ class ScreenshotController {
class Screenshot<T> extends StatefulWidget { class Screenshot<T> extends StatefulWidget {
final Widget? child; final Widget? child;
final ScreenshotController? controller; final ScreenshotController controller;
const Screenshot({ const Screenshot({
Key? key, Key? key,
required this.child, required this.child,
...@@ -160,32 +157,13 @@ class ScreenshotState extends State<Screenshot> with TickerProviderStateMixin { ...@@ -160,32 +157,13 @@ class ScreenshotState extends State<Screenshot> with TickerProviderStateMixin {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
// if (widget.controller == null) {
// _controller = ScreenshotController();
// } else
_controller = widget.controller; _controller = widget.controller;
} }
// @override
// void didUpdateWidget(Screenshot oldWidget) {
// // super.didUpdateWidget(oldWidget);
// // if (widget.controller != oldWidget.controller) {
// // widget.controller._containerKey = oldWidget.controller._containerKey;
// // if (oldWidget.controller != null && widget.controller == null)
// // _controller._containerKey = oldWidget.controller._containerKey;
// // if (widget.controller != null) {
// // if (oldWidget.controller == null) {
// // _controller = null;
// // }
// // }
// // }
// }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return RepaintBoundary( return RepaintBoundary(
key: _controller!._containerKey, key: _controller._containerKey,
child: widget.child, child: widget.child,
); );
} }
......
name: screenshot name: screenshot
description: Flutter Screenshot Package (Runtime). Capture any Widget as an image. description: Flutter Screenshot Package (Runtime). Capture any Widget as an image.
version: 1.0.0-nullsafety.0 version: 1.1.0
homepage: https://github.com/SachinGanesh/screenshot homepage: https://github.com/SachinGanesh/screenshot
environment: environment:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论