From d1c7f2f8313c1b07ce61aca64cb527b6d082bca1 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Mon, 28 Dec 2020 15:10:50 -0500 Subject: [PATCH 1/9] migrate to null safety --- packages/ios_platform_images/CHANGELOG.md | 4 +++ .../lib/ios_platform_images.dart | 33 +++++++++++-------- packages/ios_platform_images/pubspec.yaml | 6 ++-- .../test/ios_platform_images_test.dart | 4 +++ 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/packages/ios_platform_images/CHANGELOG.md b/packages/ios_platform_images/CHANGELOG.md index 4b11b40f5510..bae98440f668 100644 --- a/packages/ios_platform_images/CHANGELOG.md +++ b/packages/ios_platform_images/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.2.0-nullsafety + +* Migrate to null safety. + ## 0.1.2+4 * Update Flutter SDK constraint. diff --git a/packages/ios_platform_images/lib/ios_platform_images.dart b/packages/ios_platform_images/lib/ios_platform_images.dart index c7c12616ec36..1f6b314dc65d 100644 --- a/packages/ios_platform_images/lib/ios_platform_images.dart +++ b/packages/ios_platform_images/lib/ios_platform_images.dart @@ -1,3 +1,7 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + import 'dart:async'; import 'dart:typed_data'; import 'dart:ui' as ui; @@ -9,13 +13,11 @@ import 'package:flutter/foundation.dart' show SynchronousFuture, describeIdentity; class _FutureImageStreamCompleter extends ImageStreamCompleter { - final Future futureScale; - final InformationCollector informationCollector; - - _FutureImageStreamCompleter( - {Future codec, this.futureScale, this.informationCollector}) - : assert(codec != null), - assert(futureScale != null) { + _FutureImageStreamCompleter({ + required Future codec, + required this.futureScale, + this.informationCollector, + }) { codec.then(_onCodecReady, onError: (dynamic error, StackTrace stack) { reportError( context: ErrorDescription('resolving a single-frame image stream'), @@ -27,6 +29,9 @@ class _FutureImageStreamCompleter extends ImageStreamCompleter { }); } + final Future futureScale; + final InformationCollector? informationCollector; + Future _onCodecReady(ui.Codec codec) async { try { ui.FrameInfo nextFrame = await codec.getNextFrame(); @@ -50,9 +55,7 @@ class _FutureMemoryImage extends ImageProvider<_FutureMemoryImage> { /// Constructor for FutureMemoryImage. [_futureBytes] is the bytes that will /// be loaded into an image and [_futureScale] is the scale that will be applied to /// that image to account for high-resolution images. - const _FutureMemoryImage(this._futureBytes, this._futureScale) - : assert(_futureBytes != null), - assert(_futureScale != null); + const _FutureMemoryImage(this._futureBytes, this._futureScale); final Future _futureBytes; final Future _futureScale; @@ -73,7 +76,9 @@ class _FutureMemoryImage extends ImageProvider<_FutureMemoryImage> { } Future _loadAsync( - _FutureMemoryImage key, DecoderCallback decode) async { + _FutureMemoryImage key, + DecoderCallback decode, + ) async { assert(key == this); return _futureBytes.then((Uint8List bytes) { return decode(bytes); @@ -113,11 +118,11 @@ class IosPlatformImages { /// /// See [https://developer.apple.com/documentation/uikit/uiimage/1624146-imagenamed?language=objc] static ImageProvider load(String name) { - Future loadInfo = _channel.invokeMethod('loadImage', name); + Future loadInfo = _channel.invokeMapMethod('loadImage', name); Completer bytesCompleter = Completer(); Completer scaleCompleter = Completer(); loadInfo.then((map) { - scaleCompleter.complete(map["scale"]); + scaleCompleter.complete(map!["scale"]); bytesCompleter.complete(map["data"]); }); return _FutureMemoryImage(bytesCompleter.future, scaleCompleter.future); @@ -129,7 +134,7 @@ class IosPlatformImages { /// Returns null if the resource can't be found. /// /// See [https://developer.apple.com/documentation/foundation/nsbundle/1411540-urlforresource?language=objc] - static Future resolveURL(String name, [String ext]) { + static Future resolveURL(String name, [String? ext]) { return _channel.invokeMethod('resolveURL', [name, ext]); } } diff --git a/packages/ios_platform_images/pubspec.yaml b/packages/ios_platform_images/pubspec.yaml index 7049b62cf00a..d4dfb2b549c3 100644 --- a/packages/ios_platform_images/pubspec.yaml +++ b/packages/ios_platform_images/pubspec.yaml @@ -1,10 +1,10 @@ name: ios_platform_images description: A plugin to share images between Flutter and iOS in add-to-app setups. -version: 0.1.2+4 +version: 0.2.0-nullsafety homepage: https://github.com/flutter/plugins/tree/master/packages/ios_platform_images/ios_platform_images environment: - sdk: ">=2.1.0 <3.0.0" + sdk: ">=2.12.0-0 <3.0.0" flutter: ">=1.12.13+hotfix.5" dependencies: @@ -14,7 +14,7 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter - pedantic: ^1.8.0 + pedantic: ^1.10.0-nullsafety.3 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec diff --git a/packages/ios_platform_images/test/ios_platform_images_test.dart b/packages/ios_platform_images/test/ios_platform_images_test.dart index fd87180e9ac0..6ed7714e95c2 100644 --- a/packages/ios_platform_images/test/ios_platform_images_test.dart +++ b/packages/ios_platform_images/test/ios_platform_images_test.dart @@ -1,3 +1,7 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:ios_platform_images/ios_platform_images.dart'; From 7e9810edc206ccf90eeb58b09e0a31eb029b4d03 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Wed, 30 Dec 2020 13:15:40 -0500 Subject: [PATCH 2/9] bump versions --- packages/ios_platform_images/example/pubspec.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ios_platform_images/example/pubspec.yaml b/packages/ios_platform_images/example/pubspec.yaml index fa0f9eb3aac6..f749fc857b0d 100644 --- a/packages/ios_platform_images/example/pubspec.yaml +++ b/packages/ios_platform_images/example/pubspec.yaml @@ -4,7 +4,7 @@ publish_to: 'none' homepage: https://github.com/flutter/plugins/tree/master/packages/ios_platform_images/ios_platform_images environment: - sdk: ">=2.1.0 <3.0.0" + sdk: ">=2.12.0-0 <3.0.0" dependencies: flutter: @@ -19,7 +19,7 @@ dev_dependencies: sdk: flutter ios_platform_images: path: ../ - pedantic: ^1.8.0 + pedantic: ^1.10.0-nullsafety.3 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec From 1add87f5027514079482b4007660d7401ab90a48 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Wed, 30 Dec 2020 14:37:29 -0500 Subject: [PATCH 3/9] add to nnbd plugins --- script/nnbd_plugins.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/script/nnbd_plugins.sh b/script/nnbd_plugins.sh index 0cab28abe2ab..bccb1805026d 100644 --- a/script/nnbd_plugins.sh +++ b/script/nnbd_plugins.sh @@ -11,6 +11,7 @@ readonly NNBD_PLUGINS_LIST=( "flutter_plugin_android_lifecycle" "flutter_webview" "google_sign_in" + "ios_platform_images" "local_auth" "path_provider" "plugin_platform_interface" From 24fec68cf7c68aae0cafb5d7557ab29b3be04ba9 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Wed, 30 Dec 2020 14:42:42 -0500 Subject: [PATCH 4/9] return nullable string --- packages/ios_platform_images/lib/ios_platform_images.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ios_platform_images/lib/ios_platform_images.dart b/packages/ios_platform_images/lib/ios_platform_images.dart index 1f6b314dc65d..7723eb6bec03 100644 --- a/packages/ios_platform_images/lib/ios_platform_images.dart +++ b/packages/ios_platform_images/lib/ios_platform_images.dart @@ -135,6 +135,6 @@ class IosPlatformImages { /// /// See [https://developer.apple.com/documentation/foundation/nsbundle/1411540-urlforresource?language=objc] static Future resolveURL(String name, [String? ext]) { - return _channel.invokeMethod('resolveURL', [name, ext]); + return _channel.invokeMethod('resolveURL', [name, ext]); } } From 95cb22993ea682fd910777debb56576e4ed65509 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Wed, 30 Dec 2020 14:43:25 -0500 Subject: [PATCH 5/9] not necessary to use ? --- packages/ios_platform_images/lib/ios_platform_images.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ios_platform_images/lib/ios_platform_images.dart b/packages/ios_platform_images/lib/ios_platform_images.dart index 7723eb6bec03..1f6b314dc65d 100644 --- a/packages/ios_platform_images/lib/ios_platform_images.dart +++ b/packages/ios_platform_images/lib/ios_platform_images.dart @@ -135,6 +135,6 @@ class IosPlatformImages { /// /// See [https://developer.apple.com/documentation/foundation/nsbundle/1411540-urlforresource?language=objc] static Future resolveURL(String name, [String? ext]) { - return _channel.invokeMethod('resolveURL', [name, ext]); + return _channel.invokeMethod('resolveURL', [name, ext]); } } From 39356a6dc20a7f184cbbc5d738cadee6c9045c9a Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Thu, 7 Jan 2021 14:27:25 -0500 Subject: [PATCH 6/9] use min dependencies --- packages/ios_platform_images/example/pubspec.yaml | 2 +- packages/ios_platform_images/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ios_platform_images/example/pubspec.yaml b/packages/ios_platform_images/example/pubspec.yaml index f749fc857b0d..cfd772eb3ca5 100644 --- a/packages/ios_platform_images/example/pubspec.yaml +++ b/packages/ios_platform_images/example/pubspec.yaml @@ -19,7 +19,7 @@ dev_dependencies: sdk: flutter ios_platform_images: path: ../ - pedantic: ^1.10.0-nullsafety.3 + pedantic: ^1.10.0-nullsafety # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec diff --git a/packages/ios_platform_images/pubspec.yaml b/packages/ios_platform_images/pubspec.yaml index d4dfb2b549c3..6284f7c96871 100644 --- a/packages/ios_platform_images/pubspec.yaml +++ b/packages/ios_platform_images/pubspec.yaml @@ -14,7 +14,7 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter - pedantic: ^1.10.0-nullsafety.3 + pedantic: ^1.10.0-nullsafety # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec From ce2fa400cf3e34a2861905b4dbdeb5bdce146549 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Tue, 12 Jan 2021 17:02:43 -0500 Subject: [PATCH 7/9] comple with error on null map --- .../ios_platform_images/lib/ios_platform_images.dart | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/ios_platform_images/lib/ios_platform_images.dart b/packages/ios_platform_images/lib/ios_platform_images.dart index 1f6b314dc65d..2f31df60fa83 100644 --- a/packages/ios_platform_images/lib/ios_platform_images.dart +++ b/packages/ios_platform_images/lib/ios_platform_images.dart @@ -122,7 +122,16 @@ class IosPlatformImages { Completer bytesCompleter = Completer(); Completer scaleCompleter = Completer(); loadInfo.then((map) { - scaleCompleter.complete(map!["scale"]); + if (map == null) { + scaleCompleter.completeError( + Exception("Image couldn't be found: $name"), + ); + bytesCompleter.completeError( + Exception("Image couldn't be found: $name"), + ); + return; + } + scaleCompleter.complete(map["scale"]); bytesCompleter.complete(map["data"]); }); return _FutureMemoryImage(bytesCompleter.future, scaleCompleter.future); From b6025ff401720f53509ffaa1d81755e348c292bd Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Mon, 8 Feb 2021 12:26:43 -0800 Subject: [PATCH 8/9] revert example and use named parameters --- packages/ios_platform_images/example/pubspec.yaml | 4 ++-- packages/ios_platform_images/lib/ios_platform_images.dart | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/ios_platform_images/example/pubspec.yaml b/packages/ios_platform_images/example/pubspec.yaml index cfd772eb3ca5..fa0f9eb3aac6 100644 --- a/packages/ios_platform_images/example/pubspec.yaml +++ b/packages/ios_platform_images/example/pubspec.yaml @@ -4,7 +4,7 @@ publish_to: 'none' homepage: https://github.com/flutter/plugins/tree/master/packages/ios_platform_images/ios_platform_images environment: - sdk: ">=2.12.0-0 <3.0.0" + sdk: ">=2.1.0 <3.0.0" dependencies: flutter: @@ -19,7 +19,7 @@ dev_dependencies: sdk: flutter ios_platform_images: path: ../ - pedantic: ^1.10.0-nullsafety + pedantic: ^1.8.0 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec diff --git a/packages/ios_platform_images/lib/ios_platform_images.dart b/packages/ios_platform_images/lib/ios_platform_images.dart index 2f31df60fa83..d4599be94a64 100644 --- a/packages/ios_platform_images/lib/ios_platform_images.dart +++ b/packages/ios_platform_images/lib/ios_platform_images.dart @@ -143,7 +143,7 @@ class IosPlatformImages { /// Returns null if the resource can't be found. /// /// See [https://developer.apple.com/documentation/foundation/nsbundle/1411540-urlforresource?language=objc] - static Future resolveURL(String name, [String? ext]) { - return _channel.invokeMethod('resolveURL', [name, ext]); + static Future resolveURL(String name, {String? extension}) { + return _channel.invokeMethod('resolveURL', [name, extension]); } } From cd5299c45e0ca3eed773c93590393b9ab4735e66 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Mon, 8 Feb 2021 12:42:52 -0800 Subject: [PATCH 9/9] fix main.dart --- packages/ios_platform_images/example/lib/main.dart | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/ios_platform_images/example/lib/main.dart b/packages/ios_platform_images/example/lib/main.dart index 655380f8d125..394d983ab66c 100644 --- a/packages/ios_platform_images/example/lib/main.dart +++ b/packages/ios_platform_images/example/lib/main.dart @@ -14,8 +14,7 @@ class _MyAppState extends State { void initState() { super.initState(); - IosPlatformImages.resolveURL("textfile", null) - .then((value) => print(value)); + IosPlatformImages.resolveURL("textfile").then((value) => print(value)); } @override