Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
S
screenshot
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
openSourceLibrary
screenshot
Commits
d03e0095
提交
d03e0095
authored
2月 10, 2021
作者:
ritheshSalyan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support web and windows platfom
上级
89b80987
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
60 行增加
和
75 行删除
+60
-75
build.gradle
example/android/app/build.gradle
+1
-1
main.dart
example/lib/main.dart
+8
-18
pubspec.yaml
example/pubspec.yaml
+3
-12
screenshot.dart
lib/screenshot.dart
+44
-40
pubspec.yaml
pubspec.yaml
+4
-4
没有找到文件。
example/android/app/build.gradle
浏览文件 @
d03e0095
...
@@ -35,7 +35,7 @@ android {
...
@@ -35,7 +35,7 @@ android {
defaultConfig
{
defaultConfig
{
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId
"com.screenshot.example"
applicationId
"com.screenshot.example"
minSdkVersion
1
6
minSdkVersion
1
7
targetSdkVersion
30
targetSdkVersion
30
versionCode
flutterVersionCode
.
toInteger
()
versionCode
flutterVersionCode
.
toInteger
()
versionName
flutterVersionName
versionName
flutterVersionName
...
...
example/lib/main.dart
浏览文件 @
d03e0095
// import 'dart:io';
import
'dart:typed_data'
;
import
'dart:typed_data'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:screenshot/screenshot.dart'
;
import
'package:screenshot/screenshot.dart'
;
// import 'package:webview_flutter/webview_flutter.dart';
// import 'package:image_gallery_saver/image_gallery_saver.dart';
// import 'package:image_gallery_saver/image_gallery_saver.dart';
void
main
(
)
=>
runApp
(
MyApp
());
void
main
(
)
=>
runApp
(
MyApp
());
...
@@ -57,6 +58,8 @@ class _MyHomePageState extends State<MyHomePage> {
...
@@ -57,6 +58,8 @@ class _MyHomePageState extends State<MyHomePage> {
@override
@override
void
initState
()
{
void
initState
()
{
// if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
super
.
initState
();
super
.
initState
();
}
}
...
@@ -87,23 +90,10 @@ class _MyHomePageState extends State<MyHomePage> {
...
@@ -87,23 +90,10 @@ class _MyHomePageState extends State<MyHomePage> {
),
),
body:
Container
(
body:
Container
(
child:
new
Center
(
child:
new
Center
(
child:
Column
(
child:
Screenshot
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
controller:
screenshotController
,
children:
<
Widget
>[
child:
Text
(
"HEllo"
),
Screenshot
(
controller:
screenshotController
,
child:
Column
(
children:
<
Widget
>[
Text
(
'You have pushed the button this many times:'
+
_counter
.
toString
(),
),
FlutterLogo
(),
],
),
),
_imageFile
!=
null
?
Image
.
memory
(
_imageFile
)
:
Container
(),
],
),
),
),
),
),
),
...
...
example/pubspec.yaml
浏览文件 @
d03e0095
...
@@ -14,24 +14,19 @@ environment:
...
@@ -14,24 +14,19 @@ environment:
# sdk: '>=2.12.0-259.8.beta <3.0.0'
# sdk: '>=2.12.0-259.8.beta <3.0.0'
dependencies
:
dependencies
:
image_gallery_saver
:
^1.1.0
screenshot
:
path
:
../
flutter
:
flutter
:
sdk
:
flutter
sdk
:
flutter
screenshot
:
# The following adds the Cupertino Icons font to your application.
path
:
../
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons
:
^0.1.2
cupertino_icons
:
^0.1.2
image_gallery_saver
:
^1.1.0
dev_dependencies
:
dev_dependencies
:
flutter_test
:
flutter_test
:
sdk
:
flutter
sdk
:
flutter
# For information on the generic Dart part of this file, see the
# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec
# following page: https://www.dartlang.org/tools/pub/pubspec
# The following section is specific to Flutter.
# The following section is specific to Flutter.
flutter
:
flutter
:
...
@@ -39,18 +34,14 @@ flutter:
...
@@ -39,18 +34,14 @@ flutter:
# included with your application, so that you can use the icons in
# included with your application, so that you can use the icons in
# the material Icons class.
# the material Icons class.
uses-material-design
:
true
uses-material-design
:
true
# To add assets to your application, add an assets section, like this:
# To add assets to your application, add an assets section, like this:
# assets:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.io/assets-and-images/#resolution-aware.
# https://flutter.io/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# For details regarding adding assets from package dependencies, see
# https://flutter.io/assets-and-images/#from-packages
# https://flutter.io/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# "family" key with the font family name, and a "fonts" key with a
...
...
lib/screenshot.dart
浏览文件 @
d03e0095
...
@@ -10,6 +10,11 @@ import 'package:flutter/widgets.dart';
...
@@ -10,6 +10,11 @@ import 'package:flutter/widgets.dart';
// import 'package:path_provider/path_provider.dart';
// import 'package:path_provider/path_provider.dart';
import
'dart:ui'
as
ui
;
import
'dart:ui'
as
ui
;
///
///
///Cannot capture Platformview due to issue https://github.com/flutter/flutter/issues/25306
///
///
class
ScreenshotController
{
class
ScreenshotController
{
GlobalKey
_containerKey
;
GlobalKey
_containerKey
;
ScreenshotController
()
{
ScreenshotController
()
{
...
@@ -19,58 +24,56 @@ class ScreenshotController {
...
@@ -19,58 +24,56 @@ class ScreenshotController {
Future
<
Uint8List
>
capture
({
Future
<
Uint8List
>
capture
({
String
path
=
""
,
String
path
=
""
,
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
,
()
async
{
return
new
Future
.
delayed
(
delay
,
()
async
{
try
{
try
{
RenderRepaintBoundary
boundary
=
ui
.
Image
image
=
await
captureAsUiImage
(
this
.
_containerKey
.
currentContext
.
findRenderObject
()
as
RenderRepaintBoundary
;
delay:
Duration
.
zero
,
pixelRatio
=
pixelRatio
??
MediaQuery
.
of
(
_containerKey
.
currentContext
).
devicePixelRatio
;
pixelRatio:
pixelRatio
,
ui
.
Image
image
=
await
boundary
.
toImage
(
pixelRatio:
pixelRatio
);
);
ByteData
byteData
=
ByteData
byteData
=
await
image
.
toByteData
(
format:
ui
.
ImageByteFormat
.
png
);
await
image
.
toByteData
(
format:
ui
.
ImageByteFormat
.
png
);
Uint8List
pngBytes
=
byteData
.
buffer
.
asUint8List
();
Uint8List
pngBytes
=
byteData
.
buffer
.
asUint8List
();
// if (path == "") {
// final directory = (await getApplicationDocumentsDirectory()).path;
// String fileName = DateTime.now().toIso8601String();
// path = '$directory/$fileName.png';
// }
// File imgFile = new File(path);
// await imgFile.writeAsBytes(pngBytes).then((onValue) {});
return
pngBytes
;
return
pngBytes
;
}
catch
(
Exception
)
{
}
catch
(
Exception
)
{
throw
(
Exception
);
throw
(
Exception
);
}
}
});
});
}
}
Future
<
ui
.
Image
>
captureAsUiImage
(
Future
<
ui
.
Image
>
captureAsUiImage
({
{
double
pixelRatio:
1
,
double
pixelRatio:
1
,
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
,
()
async
{
return
new
Future
.
delayed
(
delay
,
()
async
{
try
{
try
{
RenderRepaintBoundary
boundary
=
RenderRepaintBoundary
boundary
=
this
this
.
_containerKey
.
currentContext
.
findRenderObject
();
.
_containerKey
return
await
boundary
.
toImage
(
pixelRatio:
pixelRatio
);
.
currentContext
.
findRenderObject
()
as
RenderRepaintBoundary
;
pixelRatio
=
pixelRatio
??
MediaQuery
.
of
(
_containerKey
.
currentContext
).
devicePixelRatio
;
ui
.
Image
image
=
await
boundary
.
toImage
(
pixelRatio:
pixelRatio
);
return
image
;
}
catch
(
Exception
)
{
}
catch
(
Exception
)
{
throw
(
Exception
);
throw
(
Exception
);
}
}
});
});
}
}
}
}
class
Screenshot
<
T
>
extends
StatefulWidget
{
class
Screenshot
<
T
>
extends
StatefulWidget
{
final
Widget
child
;
final
Widget
child
;
final
ScreenshotController
controller
;
final
ScreenshotController
controller
;
final
GlobalKey
containerKey
;
const
Screenshot
({
const
Screenshot
({
Key
key
,
this
.
child
,
this
.
controller
,
this
.
containerKey
})
Key
key
,
:
super
(
key:
key
);
this
.
child
,
this
.
controller
,
})
:
super
(
key:
key
);
@override
@override
State
<
Screenshot
>
createState
()
{
State
<
Screenshot
>
createState
()
{
return
new
ScreenshotState
();
return
new
ScreenshotState
();
...
@@ -89,21 +92,21 @@ class ScreenshotState extends State<Screenshot> with TickerProviderStateMixin {
...
@@ -89,21 +92,21 @@ class ScreenshotState extends State<Screenshot> with TickerProviderStateMixin {
_controller
=
widget
.
controller
;
_controller
=
widget
.
controller
;
}
}
@override
//
@override
void
didUpdateWidget
(
Screenshot
oldWidget
)
{
//
void didUpdateWidget(Screenshot oldWidget) {
super
.
didUpdateWidget
(
oldWidget
);
// //
super.didUpdateWidget(oldWidget);
if
(
widget
.
controller
!=
oldWidget
.
controller
)
{
// //
if (widget.controller != oldWidget.controller) {
widget
.
controller
.
_containerKey
=
oldWidget
.
controller
.
_containerKey
;
// //
widget.controller._containerKey = oldWidget.controller._containerKey;
if
(
oldWidget
.
controller
!=
null
&&
widget
.
controller
==
null
)
// //
if (oldWidget.controller != null && widget.controller == null)
_controller
.
_containerKey
=
oldWidget
.
controller
.
_containerKey
;
// //
_controller._containerKey = oldWidget.controller._containerKey;
if
(
widget
.
controller
!=
null
)
{
// //
if (widget.controller != null) {
if
(
oldWidget
.
controller
==
null
)
{
// //
if (oldWidget.controller == null) {
_controller
=
null
;
// //
_controller = null;
}
// //
}
}
// //
}
}
// //
}
}
//
}
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
...
@@ -113,3 +116,4 @@ class ScreenshotState extends State<Screenshot> with TickerProviderStateMixin {
...
@@ -113,3 +116,4 @@ class ScreenshotState extends State<Screenshot> with TickerProviderStateMixin {
);
);
}
}
}
}
pubspec.yaml
浏览文件 @
d03e0095
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
:
0.
2
.0
version
:
0.
3
.0
homepage
:
https://github.com/SachinGanesh/screenshot
homepage
:
https://github.com/SachinGanesh/screenshot
environment
:
environment
:
sdk
:
'
>=2.8.0
<3.0.0'
sdk
:
'
>=2.8.0
<3.0.0'
# sdk: '>=2.12.0-259.8.beta <3.0.0'
# sdk: '>=2.12.0-259.8.beta <3.0.0'
analyzer
:
#
analyzer:
enable-experiment
:
#
enable-experiment:
-
non-nullable
#
- non-nullable
dependencies
:
dependencies
:
path_provider
:
^1.1.0
path_provider
:
^1.1.0
flutter
:
flutter
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论