Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
S
screenshot
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
openSourceLibrary
screenshot
Commits
727e4860
提交
727e4860
authored
6月 13, 2021
作者:
Sachin Ganesh
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/nullsafety'
上级
f296fd1c
9df6f30e
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
39 行增加
和
31 行删除
+39
-31
CHANGELOG.md
CHANGELOG.md
+3
-0
pubspec.yaml
example/pubspec.yaml
+2
-2
screenshot.dart
lib/screenshot.dart
+29
-24
main.dart
lib/src/main.dart
+1
-0
file_manager_mobile.dart
...c/platform_specific/file_manager/file_manager_mobile.dart
+1
-2
file_manager_stub.dart
...src/platform_specific/file_manager/file_manager_stub.dart
+2
-2
pubspec.yaml
pubspec.yaml
+1
-1
没有找到文件。
CHANGELOG.md
浏览文件 @
727e4860
## [1.0.0-nullsafety.0] - 10/02/2021
*
Add nullsafety
## [0.3.0] - 10/02/2021
*
breaking change capture method returns Uint8List instead of File.
*
support for web and windows
...
...
example/pubspec.yaml
浏览文件 @
727e4860
...
...
@@ -11,8 +11,8 @@ version: 1.0.0+1
publish_to
:
none
environment
:
sdk
:
'
>=2.8.0
<3.0.0'
#
sdk: '>=2.12.0-259.8.beta <3.0.0'
#
sdk: '>=2.8.0 <3.0.0'
sdk
:
'
>=2.12.0-259.8.beta
<3.0.0'
dependencies
:
flutter
:
...
...
lib/screenshot.dart
浏览文件 @
727e4860
...
...
@@ -16,26 +16,28 @@ import 'dart:ui' as ui;
///
///
class
ScreenshotController
{
GlobalKey
?
_containerKey
;
late
GlobalKey
_containerKey
;
ScreenshotController
()
{
_containerKey
=
GlobalKey
();
}
/// Captures image and saves to given path
Future
<
String
>
captureAndSave
(
Future
<
String
?
>
captureAndSave
(
String
directory
,
{
String
?
fileName
,
double
?
pixelRatio
,
Duration
delay
:
const
Duration
(
milliseconds:
20
),
Duration
delay
=
const
Duration
(
milliseconds:
20
),
})
async
{
Uint8List
content
=
await
capture
(
Uint8List
?
content
=
await
capture
(
pixelRatio:
pixelRatio
,
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
({
...
...
@@ -43,15 +45,15 @@ class ScreenshotController {
Duration
delay:
const
Duration
(
milliseconds:
20
),
})
{
//Delay is required. See Issue https://github.com/flutter/flutter/issues/22308
return
new
Future
.
delayed
(
delay
,
()
async
{
return
new
Future
.
delayed
(
delay
??
Duration
(
milliseconds:
20
)
,
()
async
{
try
{
ui
.
Image
image
=
await
captureAsUiImage
(
delay:
Duration
.
zero
,
pixelRatio:
pixelRatio
,
);
ByteData
byteData
=
await
(
image
.
toByteData
(
format:
ui
.
ImageByteFormat
.
png
)
as
FutureOr
<
ByteData
>
);
Uint8List
pngBytes
=
byteData
.
buffer
.
asUint8List
();
ByteData
?
byteData
=
await
image
.
toByteData
(
format:
ui
.
ImageByteFormat
.
png
);
Uint8List
?
pngBytes
=
byteData
?
.
buffer
.
asUint8List
();
return
pngBytes
;
}
catch
(
Exception
)
{
...
...
@@ -67,12 +69,15 @@ class ScreenshotController {
return
new
Future
.
delayed
(
delay
,
()
async
{
try
{
RenderRepaintBoundary
boundary
=
this
.
_containerKey
!
.
currentContext
!
.
findRenderObject
()
as
RenderRepaintBoundary
;
pixelRatio
=
pixelRatio
??
MediaQuery
.
of
(
_containerKey
!.
currentContext
!).
devicePixelRatio
;
ui
.
Image
image
=
await
boundary
.
toImage
(
pixelRatio:
pixelRatio
!);
.
_containerKey
.
currentContext
?.
findRenderObject
()
as
RenderRepaintBoundary
;
BuildContext
?
context
=
_containerKey
.
currentContext
;
if
(
pixelRatio
==
null
)
{
if
(
context
!=
null
)
pixelRatio
=
pixelRatio
??
MediaQuery
.
of
(
context
).
devicePixelRatio
;
}
ui
.
Image
image
=
await
boundary
.
toImage
(
pixelRatio:
pixelRatio
??
1
);
return
image
;
}
catch
(
Exception
)
{
throw
(
Exception
);
...
...
@@ -139,8 +144,8 @@ class Screenshot<T> extends StatefulWidget {
final
ScreenshotController
?
controller
;
const
Screenshot
({
Key
?
key
,
this
.
child
,
this
.
controller
,
required
this
.
child
,
required
this
.
controller
,
})
:
super
(
key:
key
);
@override
...
...
@@ -150,15 +155,15 @@ class Screenshot<T> extends StatefulWidget {
}
class
ScreenshotState
extends
State
<
Screenshot
>
with
TickerProviderStateMixin
{
ScreenshotController
?
_controller
;
late
ScreenshotController
_controller
;
@override
void
initState
()
{
super
.
initState
();
if
(
widget
.
controller
==
null
)
{
_controller
=
ScreenshotController
();
}
else
_controller
=
widget
.
controller
;
//
if (widget.controller == null) {
//
_controller = ScreenshotController();
//
} else
_controller
=
widget
.
controller
;
}
// @override
...
...
lib/src/main.dart
浏览文件 @
727e4860
lib/src/platform_specific/file_manager/file_manager_mobile.dart
浏览文件 @
727e4860
...
...
@@ -13,6 +13,5 @@
// file.writeAsBytesSync(fileContent);
// return file.path;
// }
// }
lib/src/platform_specific/file_manager/file_manager_stub.dart
浏览文件 @
727e4860
import
'file_manager.dart'
;
PlatformFileManager
getFileManager
(
)
=>
throw
UnimplementedError
(
"File Picker is Not Implementd in current platform"
);
PlatformFileManager
getFileManager
(
)
=>
throw
UnimplementedError
(
"File Picker is Not Implementd in current platform"
);
pubspec.yaml
浏览文件 @
727e4860
name
:
screenshot
description
:
Flutter Screenshot Package (Runtime). Capture any Widget as an image.
version
:
0.3
.0
version
:
1.0.0-nullsafety
.0
homepage
:
https://github.com/SachinGanesh/screenshot
environment
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论