提交 36afd738 authored 作者: Yonatan Naor's avatar Yonatan Naor

migrate to null safety

上级 da943171
......@@ -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,
);
}
......
......@@ -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});
}
......@@ -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);
......
......@@ -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);
......
......@@ -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"
......@@ -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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论