Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
S
screenshot
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
openSourceLibrary
screenshot
Commits
237ce298
提交
237ce298
authored
2月 10, 2021
作者:
ritheshSalyan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add new method captureAndSave
上级
980871be
隐藏空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
130 行增加
和
68 行删除
+130
-68
main.dart
example/lib/main.dart
+12
-22
screenshot.dart
lib/screenshot.dart
+19
-4
file_manager.dart
lib/src/platform_specific/file_manager/file_manager.dart
+11
-0
file_manager_io.dart
lib/src/platform_specific/file_manager/file_manager_io.dart
+17
-0
file_manager_mobile.dart
...c/platform_specific/file_manager/file_manager_mobile.dart
+18
-0
file_manager_stub.dart
...src/platform_specific/file_manager/file_manager_stub.dart
+4
-0
non_io.dart
lib/src/platform_specific/file_manager/non_io.dart
+18
-0
pubspec.lock
pubspec.lock
+0
-8
pubspec.yaml
pubspec.yaml
+31
-34
没有找到文件。
example/lib/main.dart
浏览文件 @
237ce298
import
'dart:typed_data'
;
import
'package:flutter/material.dart'
;
...
...
@@ -58,8 +57,7 @@ class _MyHomePageState extends State<MyHomePage> {
@override
void
initState
()
{
// if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
// if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
super
.
initState
();
}
...
...
@@ -92,8 +90,7 @@ class _MyHomePageState extends State<MyHomePage> {
child:
new
Center
(
child:
Screenshot
(
controller:
screenshotController
,
child:
Text
(
"HEllo"
),
child:
Text
(
"HEllo"
),
),
),
),
...
...
@@ -104,28 +101,21 @@ class _MyHomePageState extends State<MyHomePage> {
screenshotController
.
capture
(
delay:
Duration
(
milliseconds:
10
))
.
then
((
Uint8List
image
)
async
{
//print("Capture Done");
// setState(() {
_imageFile
=
image
;
showDialog
(
context:
context
,
_imageFile
=
image
;
showDialog
(
context:
context
,
builder:
(
context
)
=>
Scaffold
(
appBar:
AppBar
(
title:
Text
(
"CAPURED SCREENSHOT"
),
),
body:
Center
(
child:
Column
(
children:
[
_imageFile
!=
null
?
Image
.
memory
(
_imageFile
)
:
Container
(),
],
)
),
)
,
);
// });
// final result =
// await ImageGallerySaver.save(image.readAsBytesSync());
print
(
"File Saved to Gallery"
);
child:
Column
(
children:
[
_imageFile
!=
null
?
Image
.
memory
(
_imageFile
)
:
Container
(),
],
)),
),
);
}).
catchError
((
onError
)
{
print
(
onError
);
});
...
...
lib/screenshot.dart
浏览文件 @
237ce298
...
...
@@ -3,7 +3,7 @@ library screenshot;
// import 'dart:io';
import
'dart:async'
;
import
'dart:typed_data'
;
import
'src/platform_specific/file_manager/file_manager.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/rendering.dart'
;
import
'package:flutter/widgets.dart'
;
...
...
@@ -21,8 +21,24 @@ class ScreenshotController {
_containerKey
=
GlobalKey
();
}
/// Captures image and saves to given path
Future
<
String
>
captureAndSave
(
String
directory
,
{
String
fileName
,
double
pixelRatio
,
Duration
delay:
const
Duration
(
milliseconds:
20
),
})
async
{
Uint8List
content
=
await
capture
(
pixelRatio:
pixelRatio
,
delay:
delay
,
);
PlatformFileManager
fileManager
=
PlatformFileManager
();
return
fileManager
.
saveFile
(
content
,
directory
,
name:
fileName
);
}
Future
<
Uint8List
>
capture
({
String
path
=
""
,
double
pixelRatio
,
Duration
delay:
const
Duration
(
milliseconds:
20
),
})
{
...
...
@@ -73,7 +89,7 @@ class Screenshot<T> extends StatefulWidget {
this
.
child
,
this
.
controller
,
})
:
super
(
key:
key
);
@override
State
<
Screenshot
>
createState
()
{
return
new
ScreenshotState
();
...
...
@@ -116,4 +132,3 @@ class ScreenshotState extends State<Screenshot> with TickerProviderStateMixin {
);
}
}
lib/src/platform_specific/file_manager/file_manager.dart
0 → 100644
浏览文件 @
237ce298
import
'dart:typed_data'
;
// import 'file_manager_mobile.dart';
import
'file_manager_stub.dart'
if
(
dart
.
library
.
io
)
"file_manager_io.dart"
if
(
dart
.
library
.
html
)
"non_io.dart"
;
abstract
class
PlatformFileManager
{
factory
PlatformFileManager
()
=>
getFileManager
();
Future
<
String
>
saveFile
(
Uint8List
fileContent
,
String
path
,
{
String
name
});
}
lib/src/platform_specific/file_manager/file_manager_io.dart
0 → 100644
浏览文件 @
237ce298
import
'dart:io'
;
import
'dart:typed_data'
;
import
'file_manager.dart'
;
PlatformFileManager
getFileManager
(
)
=>
PlatformFilePickerWindows
();
class
PlatformFilePickerWindows
implements
PlatformFileManager
{
@override
Future
<
String
>
saveFile
(
Uint8List
fileContent
,
String
path
,
{
String
name
})
async
{
name
=
name
??
"
${DateTime.now().microsecondsSinceEpoch}
.png"
;
File
file
=
await
File
(
"
$path
/
$name
"
).
create
(
recursive:
true
);
file
.
writeAsBytesSync
(
fileContent
);
return
file
.
path
;
}
}
lib/src/platform_specific/file_manager/file_manager_mobile.dart
0 → 100644
浏览文件 @
237ce298
// import 'dart:io';
// import 'dart:typed_data';
// import 'file_manager.dart';
// PlatformFileManager getFilePicker() => PlatformFilePickerMobile();
// class PlatformFilePickerMobile with PlatformFileManager {
// @override
// Future<String> saveFile(Uint8List fileContent, String path, {String name}) async{
// name = name??"${DateTime.now().toIso8601String()}.png";
// File file = File("$path/$name");
// file.writeAsBytesSync(fileContent);
// return file.path;
// }
// }
lib/src/platform_specific/file_manager/file_manager_stub.dart
0 → 100644
浏览文件 @
237ce298
import
'file_manager.dart'
;
PlatformFileManager
getFileManager
(
)
=>
throw
UnimplementedError
(
"File Picker is Not Implementd in current platform"
);
lib/src/platform_specific/file_manager/non_io.dart
0 → 100644
浏览文件 @
237ce298
// import 'dart:html';
import
'dart:typed_data'
;
import
'file_manager.dart'
;
PlatformFileManager
getFileManager
(
)
=>
PlatformFileManagerWeb
();
class
PlatformFileManagerWeb
implements
PlatformFileManager
{
@override
Future
<
String
>
saveFile
(
Uint8List
fileContent
,
String
path
,
{
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);
// file.writeAsBytesSync(fileContent);
// return file.path;
}
}
pubspec.lock
浏览文件 @
237ce298
...
...
@@ -81,13 +81,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0-nullsafety.3"
path_provider:
dependency: "direct main"
description:
name: path_provider
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
sky_engine:
dependency: transitive
description: flutter
...
...
@@ -151,4 +144,3 @@ packages:
version: "2.1.0-nullsafety.5"
sdks:
dart: ">=2.12.0-0.0 <3.0.0"
flutter: ">=0.1.4"
pubspec.yaml
浏览文件 @
237ce298
...
...
@@ -6,12 +6,11 @@ homepage: https://github.com/SachinGanesh/screenshot
environment
:
sdk
:
'
>=2.8.0
<3.0.0'
# sdk: '>=2.12.0-259.8.beta <3.0.0'
# analyzer:
# enable-experiment:
# - non-nullable
dependencies
:
path_provider
:
^1.1.0
flutter
:
sdk
:
flutter
...
...
@@ -21,37 +20,35 @@ dev_dependencies:
# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec
# The following section is specific to Flutter.
flutter
:
# To add assets to your package, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
#
# For details regarding assets in packages, see
# https://flutter.io/assets-and-images/#from-packages
#
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.io/assets-and-images/#resolution-aware.
flutter
:
null
# To add custom fonts to your package, add a fonts section here,
# 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
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts in packages, see
# https://flutter.io/custom-fonts/#from-packages
# To add assets to your package, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
#
# For details regarding assets in packages, see
# https://flutter.io/assets-and-images/#from-packages
#
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.io/assets-and-images/#resolution-aware.
# To add custom fonts to your package, add a fonts section here,
# 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
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts in packages, see
# https://flutter.io/custom-fonts/#from-packages
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论