Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
S
screenshot
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
openSourceLibrary
screenshot
Commits
36afd738
提交
36afd738
authored
6月 06, 2021
作者:
Yonatan Naor
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
migrate to null safety
上级
da943171
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
38 行增加
和
38 行删除
+38
-38
screenshot.dart
lib/screenshot.dart
+15
-15
file_manager.dart
lib/src/platform_specific/file_manager/file_manager.dart
+1
-1
file_manager_io.dart
lib/src/platform_specific/file_manager/file_manager_io.dart
+1
-1
non_io.dart
lib/src/platform_specific/file_manager/non_io.dart
+1
-1
pubspec.lock
pubspec.lock
+19
-19
pubspec.yaml
pubspec.yaml
+1
-1
没有找到文件。
lib/screenshot.dart
浏览文件 @
36afd738
...
...
@@ -16,7 +16,7 @@ import 'dart:ui' as ui;
///
///
class
ScreenshotController
{
GlobalKey
_containerKey
;
GlobalKey
?
_containerKey
;
ScreenshotController
()
{
_containerKey
=
GlobalKey
();
}
...
...
@@ -24,8 +24,8 @@ class ScreenshotController {
/// Captures image and saves to given path
Future
<
String
>
captureAndSave
(
String
directory
,
{
String
fileName
,
double
pixelRatio
,
String
?
fileName
,
double
?
pixelRatio
,
Duration
delay:
const
Duration
(
milliseconds:
20
),
})
async
{
Uint8List
content
=
await
capture
(
...
...
@@ -39,7 +39,7 @@ class ScreenshotController {
}
Future
<
Uint8List
>
capture
({
double
pixelRatio
,
double
?
pixelRatio
,
Duration
delay:
const
Duration
(
milliseconds:
20
),
})
{
//Delay is required. See Issue https://github.com/flutter/flutter/issues/22308
...
...
@@ -50,7 +50,7 @@ class ScreenshotController {
pixelRatio:
pixelRatio
,
);
ByteData
byteData
=
await
image
.
toByteData
(
format:
ui
.
ImageByteFormat
.
png
);
await
(
image
.
toByteData
(
format:
ui
.
ImageByteFormat
.
png
)
as
FutureOr
<
ByteData
>
);
Uint8List
pngBytes
=
byteData
.
buffer
.
asUint8List
();
return
pngBytes
;
...
...
@@ -61,18 +61,18 @@ class ScreenshotController {
}
Future
<
ui
.
Image
>
captureAsUiImage
(
{
double
pixelRatio:
1
,
{
double
?
pixelRatio:
1
,
Duration
delay:
const
Duration
(
milliseconds:
20
)})
{
//Delay is required. See Issue https://github.com/flutter/flutter/issues/22308
return
new
Future
.
delayed
(
delay
,
()
async
{
try
{
RenderRepaintBoundary
boundary
=
this
.
_containerKey
.
currentContext
.
_containerKey
!
.
currentContext
!
.
findRenderObject
()
as
RenderRepaintBoundary
;
pixelRatio
=
pixelRatio
??
MediaQuery
.
of
(
_containerKey
.
currentContext
).
devicePixelRatio
;
ui
.
Image
image
=
await
boundary
.
toImage
(
pixelRatio:
pixelRatio
);
MediaQuery
.
of
(
_containerKey
!.
currentContext
!
).
devicePixelRatio
;
ui
.
Image
image
=
await
boundary
.
toImage
(
pixelRatio:
pixelRatio
!
);
return
image
;
}
catch
(
Exception
)
{
throw
(
Exception
);
...
...
@@ -82,10 +82,10 @@ class ScreenshotController {
}
class
Screenshot
<
T
>
extends
StatefulWidget
{
final
Widget
child
;
final
ScreenshotController
controller
;
final
Widget
?
child
;
final
ScreenshotController
?
controller
;
const
Screenshot
({
Key
key
,
Key
?
key
,
this
.
child
,
this
.
controller
,
})
:
super
(
key:
key
);
...
...
@@ -97,7 +97,7 @@ class Screenshot<T> extends StatefulWidget {
}
class
ScreenshotState
extends
State
<
Screenshot
>
with
TickerProviderStateMixin
{
ScreenshotController
_controller
;
ScreenshotController
?
_controller
;
@override
void
initState
()
{
...
...
@@ -127,7 +127,7 @@ class ScreenshotState extends State<Screenshot> with TickerProviderStateMixin {
@override
Widget
build
(
BuildContext
context
)
{
return
RepaintBoundary
(
key:
_controller
.
_containerKey
,
key:
_controller
!
.
_containerKey
,
child:
widget
.
child
,
);
}
...
...
lib/src/platform_specific/file_manager/file_manager.dart
浏览文件 @
36afd738
...
...
@@ -7,5 +7,5 @@ import 'file_manager_stub.dart'
abstract
class
PlatformFileManager
{
factory
PlatformFileManager
()
=>
getFileManager
();
Future
<
String
>
saveFile
(
Uint8List
fileContent
,
String
path
,
{
String
name
});
Future
<
String
>
saveFile
(
Uint8List
fileContent
,
String
path
,
{
String
?
name
});
}
lib/src/platform_specific/file_manager/file_manager_io.dart
浏览文件 @
36afd738
...
...
@@ -8,7 +8,7 @@ PlatformFileManager getFileManager() => PlatformFilePickerWindows();
class
PlatformFilePickerWindows
implements
PlatformFileManager
{
@override
Future
<
String
>
saveFile
(
Uint8List
fileContent
,
String
path
,
{
String
name
})
async
{
{
String
?
name
})
async
{
name
=
name
??
"
${DateTime.now().microsecondsSinceEpoch}
.png"
;
File
file
=
await
File
(
"
$path
/
$name
"
).
create
(
recursive:
true
);
file
.
writeAsBytesSync
(
fileContent
);
...
...
lib/src/platform_specific/file_manager/non_io.dart
浏览文件 @
36afd738
...
...
@@ -8,7 +8,7 @@ PlatformFileManager getFileManager() => PlatformFileManagerWeb();
class
PlatformFileManagerWeb
implements
PlatformFileManager
{
@override
Future
<
String
>
saveFile
(
Uint8List
fileContent
,
String
path
,
{
String
name
})
async
{
{
String
?
name
})
async
{
throw
UnsupportedError
(
"File cannot be saved in current platform"
);
// name = name ?? "${DateTime.now().microsecondsSinceEpoch}.png";
// File file = await File("$path/$name").create(recursive: true);
...
...
pubspec.lock
浏览文件 @
36afd738
...
...
@@ -7,49 +7,49 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.
5.0-nullsafety.3
"
version: "2.
6.1
"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0
-nullsafety.3
"
version: "2.1.0"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0
-nullsafety.5
"
version: "1.1.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0
-nullsafety.3
"
version: "1.2.0"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0
-nullsafety.3
"
version: "1.1.0"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0
-nullsafety.5
"
version: "1.15.0"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0
-nullsafety.3
"
version: "1.2.0"
flutter:
dependency: "direct main"
description: flutter
...
...
@@ -66,21 +66,21 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.10
-nullsafety.3
"
version: "0.12.10"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0
-nullsafety.6
"
version: "1.3.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0
-nullsafety.3
"
version: "1.8.0"
sky_engine:
dependency: transitive
description: flutter
...
...
@@ -92,55 +92,55 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.
0-nullsafety.4
"
version: "1.8.
1
"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.10.0
-nullsafety.6
"
version: "1.10.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0
-nullsafety.3
"
version: "2.1.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0
-nullsafety.3
"
version: "1.1.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0
-nullsafety.3
"
version: "1.2.0"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.
2.19-nullsafety.6
"
version: "0.
3.0
"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0
-nullsafety.5
"
version: "1.3.0"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0
-nullsafety.5
"
version: "2.1.0"
sdks:
dart: ">=2.12.0
-0.0
<3.0.0"
dart: ">=2.12.0 <3.0.0"
pubspec.yaml
浏览文件 @
36afd738
...
...
@@ -4,7 +4,7 @@ version: 0.3.0
homepage
:
https://github.com/SachinGanesh/screenshot
environment
:
sdk
:
'
>=2.
8
.0
<3.0.0'
sdk
:
'
>=2.
12
.0
<3.0.0'
# sdk: '>=2.12.0-259.8.beta <3.0.0'
# analyzer:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论