Skip to content

Commit

Permalink
migrate to null safety
Browse files Browse the repository at this point in the history
  • Loading branch information
yonatan-yna committed Jun 6, 2021
1 parent da94317 commit 36afd73
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 38 deletions.
30 changes: 15 additions & 15 deletions lib/screenshot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ import 'dart:ui' as ui;
///
///
class ScreenshotController {
GlobalKey _containerKey;
GlobalKey? _containerKey;
ScreenshotController() {
_containerKey = GlobalKey();
}

/// 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(
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -97,7 +97,7 @@ class Screenshot<T> extends StatefulWidget {
}

class ScreenshotState extends State<Screenshot> with TickerProviderStateMixin {
ScreenshotController _controller;
ScreenshotController? _controller;

@override
void initState() {
Expand Down Expand Up @@ -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,
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/platform_specific/file_manager/file_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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});
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/platform_specific/file_manager/non_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
38 changes: 19 additions & 19 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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"
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 36afd73

Please sign in to comment.