Unverified 提交 bf306156 authored 作者: Sachin's avatar Sachin 提交者: GitHub

Merge pull request #44 from yonatann/master

migrate to null safety
...@@ -16,7 +16,7 @@ import 'dart:ui' as ui; ...@@ -16,7 +16,7 @@ import 'dart:ui' as ui;
/// ///
/// ///
class ScreenshotController { class ScreenshotController {
GlobalKey _containerKey; GlobalKey? _containerKey;
ScreenshotController() { ScreenshotController() {
_containerKey = GlobalKey(); _containerKey = GlobalKey();
} }
...@@ -24,8 +24,8 @@ class ScreenshotController { ...@@ -24,8 +24,8 @@ class ScreenshotController {
/// Captures image and saves to given path /// Captures image and saves to given path
Future<String> captureAndSave( Future<String> captureAndSave(
String directory, { String directory, {
String fileName, String? fileName,
double pixelRatio, double? pixelRatio,
Duration delay: const Duration(milliseconds: 20), Duration delay: const Duration(milliseconds: 20),
}) async { }) async {
Uint8List content = await capture( Uint8List content = await capture(
...@@ -39,7 +39,7 @@ class ScreenshotController { ...@@ -39,7 +39,7 @@ class ScreenshotController {
} }
Future<Uint8List> capture({ Future<Uint8List> capture({
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
...@@ -50,7 +50,7 @@ class ScreenshotController { ...@@ -50,7 +50,7 @@ class ScreenshotController {
pixelRatio: pixelRatio, pixelRatio: pixelRatio,
); );
ByteData byteData = ByteData byteData =
await image.toByteData(format: ui.ImageByteFormat.png); await (image.toByteData(format: ui.ImageByteFormat.png) as FutureOr<ByteData>);
Uint8List pngBytes = byteData.buffer.asUint8List(); Uint8List pngBytes = byteData.buffer.asUint8List();
return pngBytes; return pngBytes;
...@@ -61,18 +61,18 @@ class ScreenshotController { ...@@ -61,18 +61,18 @@ class ScreenshotController {
} }
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 = this RenderRepaintBoundary boundary = this
._containerKey ._containerKey!
.currentContext .currentContext!
.findRenderObject() as RenderRepaintBoundary; .findRenderObject() as RenderRepaintBoundary;
pixelRatio = pixelRatio ?? pixelRatio = pixelRatio ??
MediaQuery.of(_containerKey.currentContext).devicePixelRatio; MediaQuery.of(_containerKey!.currentContext!).devicePixelRatio;
ui.Image image = await boundary.toImage(pixelRatio: pixelRatio); ui.Image image = await boundary.toImage(pixelRatio: pixelRatio!);
return image; return image;
} catch (Exception) { } catch (Exception) {
throw (Exception); throw (Exception);
...@@ -82,10 +82,10 @@ class ScreenshotController { ...@@ -82,10 +82,10 @@ class ScreenshotController {
} }
class Screenshot<T> extends StatefulWidget { class Screenshot<T> extends StatefulWidget {
final Widget child; final Widget? child;
final ScreenshotController controller; final ScreenshotController? controller;
const Screenshot({ const Screenshot({
Key key, Key? key,
this.child, this.child,
this.controller, this.controller,
}) : super(key: key); }) : super(key: key);
...@@ -97,7 +97,7 @@ class Screenshot<T> extends StatefulWidget { ...@@ -97,7 +97,7 @@ class Screenshot<T> extends StatefulWidget {
} }
class ScreenshotState extends State<Screenshot> with TickerProviderStateMixin { class ScreenshotState extends State<Screenshot> with TickerProviderStateMixin {
ScreenshotController _controller; ScreenshotController? _controller;
@override @override
void initState() { void initState() {
...@@ -127,7 +127,7 @@ class ScreenshotState extends State<Screenshot> with TickerProviderStateMixin { ...@@ -127,7 +127,7 @@ class ScreenshotState extends State<Screenshot> with TickerProviderStateMixin {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return RepaintBoundary( return RepaintBoundary(
key: _controller._containerKey, key: _controller!._containerKey,
child: widget.child, child: widget.child,
); );
} }
......
...@@ -7,5 +7,5 @@ import 'file_manager_stub.dart' ...@@ -7,5 +7,5 @@ import 'file_manager_stub.dart'
abstract class PlatformFileManager { abstract class PlatformFileManager {
factory PlatformFileManager() => getFileManager(); 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(); ...@@ -8,7 +8,7 @@ PlatformFileManager getFileManager() => PlatformFilePickerWindows();
class PlatformFilePickerWindows implements PlatformFileManager { class PlatformFilePickerWindows implements PlatformFileManager {
@override @override
Future<String> saveFile(Uint8List fileContent, String path, Future<String> saveFile(Uint8List fileContent, String path,
{String name}) async { {String? name}) async {
name = name ?? "${DateTime.now().microsecondsSinceEpoch}.png"; name = name ?? "${DateTime.now().microsecondsSinceEpoch}.png";
File file = await File("$path/$name").create(recursive: true); File file = await File("$path/$name").create(recursive: true);
file.writeAsBytesSync(fileContent); file.writeAsBytesSync(fileContent);
......
...@@ -8,7 +8,7 @@ PlatformFileManager getFileManager() => PlatformFileManagerWeb(); ...@@ -8,7 +8,7 @@ PlatformFileManager getFileManager() => PlatformFileManagerWeb();
class PlatformFileManagerWeb implements PlatformFileManager { class PlatformFileManagerWeb implements PlatformFileManager {
@override @override
Future<String> saveFile(Uint8List fileContent, String path, Future<String> saveFile(Uint8List fileContent, String path,
{String name}) async { {String? name}) async {
throw UnsupportedError("File cannot be saved in current platform"); throw UnsupportedError("File cannot be saved in current platform");
// name = name ?? "${DateTime.now().microsecondsSinceEpoch}.png"; // name = name ?? "${DateTime.now().microsecondsSinceEpoch}.png";
// File file = await File("$path/$name").create(recursive: true); // File file = await File("$path/$name").create(recursive: true);
......
...@@ -7,49 +7,49 @@ packages: ...@@ -7,49 +7,49 @@ packages:
name: async name: async
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.5.0-nullsafety.3" version: "2.6.1"
boolean_selector: boolean_selector:
dependency: transitive dependency: transitive
description: description:
name: boolean_selector name: boolean_selector
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.0-nullsafety.3" version: "2.1.0"
characters: characters:
dependency: transitive dependency: transitive
description: description:
name: characters name: characters
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.0-nullsafety.5" version: "1.1.0"
charcode: charcode:
dependency: transitive dependency: transitive
description: description:
name: charcode name: charcode
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.2.0-nullsafety.3" version: "1.2.0"
clock: clock:
dependency: transitive dependency: transitive
description: description:
name: clock name: clock
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.0-nullsafety.3" version: "1.1.0"
collection: collection:
dependency: transitive dependency: transitive
description: description:
name: collection name: collection
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.15.0-nullsafety.5" version: "1.15.0"
fake_async: fake_async:
dependency: transitive dependency: transitive
description: description:
name: fake_async name: fake_async
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.2.0-nullsafety.3" version: "1.2.0"
flutter: flutter:
dependency: "direct main" dependency: "direct main"
description: flutter description: flutter
...@@ -66,21 +66,21 @@ packages: ...@@ -66,21 +66,21 @@ packages:
name: matcher name: matcher
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.12.10-nullsafety.3" version: "0.12.10"
meta: meta:
dependency: transitive dependency: transitive
description: description:
name: meta name: meta
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.3.0-nullsafety.6" version: "1.3.0"
path: path:
dependency: transitive dependency: transitive
description: description:
name: path name: path
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.8.0-nullsafety.3" version: "1.8.0"
sky_engine: sky_engine:
dependency: transitive dependency: transitive
description: flutter description: flutter
...@@ -92,55 +92,55 @@ packages: ...@@ -92,55 +92,55 @@ packages:
name: source_span name: source_span
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.8.0-nullsafety.4" version: "1.8.1"
stack_trace: stack_trace:
dependency: transitive dependency: transitive
description: description:
name: stack_trace name: stack_trace
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.10.0-nullsafety.6" version: "1.10.0"
stream_channel: stream_channel:
dependency: transitive dependency: transitive
description: description:
name: stream_channel name: stream_channel
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.0-nullsafety.3" version: "2.1.0"
string_scanner: string_scanner:
dependency: transitive dependency: transitive
description: description:
name: string_scanner name: string_scanner
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.0-nullsafety.3" version: "1.1.0"
term_glyph: term_glyph:
dependency: transitive dependency: transitive
description: description:
name: term_glyph name: term_glyph
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.2.0-nullsafety.3" version: "1.2.0"
test_api: test_api:
dependency: transitive dependency: transitive
description: description:
name: test_api name: test_api
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.2.19-nullsafety.6" version: "0.3.0"
typed_data: typed_data:
dependency: transitive dependency: transitive
description: description:
name: typed_data name: typed_data
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.3.0-nullsafety.5" version: "1.3.0"
vector_math: vector_math:
dependency: transitive dependency: transitive
description: description:
name: vector_math name: vector_math
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.0-nullsafety.5" version: "2.1.0"
sdks: 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 ...@@ -4,7 +4,7 @@ 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.12.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:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论