[ios_platform_images] Migrate to null safety (#3381)
diff --git a/packages/ios_platform_images/CHANGELOG.md b/packages/ios_platform_images/CHANGELOG.md
index 4b11b40..bae9844 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/example/lib/main.dart b/packages/ios_platform_images/example/lib/main.dart
index 655380f..394d983 100644
--- a/packages/ios_platform_images/example/lib/main.dart
+++ b/packages/ios_platform_images/example/lib/main.dart
@@ -14,8 +14,7 @@
void initState() {
super.initState();
- IosPlatformImages.resolveURL("textfile", null)
- .then((value) => print(value));
+ IosPlatformImages.resolveURL("textfile").then((value) => print(value));
}
@override
diff --git a/packages/ios_platform_images/lib/ios_platform_images.dart b/packages/ios_platform_images/lib/ios_platform_images.dart
index c7c1261..d4599be 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 @@
show SynchronousFuture, describeIdentity;
class _FutureImageStreamCompleter extends ImageStreamCompleter {
- final Future<double> futureScale;
- final InformationCollector informationCollector;
-
- _FutureImageStreamCompleter(
- {Future<ui.Codec> codec, this.futureScale, this.informationCollector})
- : assert(codec != null),
- assert(futureScale != null) {
+ _FutureImageStreamCompleter({
+ required Future<ui.Codec> codec,
+ required this.futureScale,
+ this.informationCollector,
+ }) {
codec.then<void>(_onCodecReady, onError: (dynamic error, StackTrace stack) {
reportError(
context: ErrorDescription('resolving a single-frame image stream'),
@@ -27,6 +29,9 @@
});
}
+ final Future<double> futureScale;
+ final InformationCollector? informationCollector;
+
Future<void> _onCodecReady(ui.Codec codec) async {
try {
ui.FrameInfo nextFrame = await codec.getNextFrame();
@@ -50,9 +55,7 @@
/// 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<Uint8List> _futureBytes;
final Future<double> _futureScale;
@@ -73,7 +76,9 @@
}
Future<ui.Codec> _loadAsync(
- _FutureMemoryImage key, DecoderCallback decode) async {
+ _FutureMemoryImage key,
+ DecoderCallback decode,
+ ) async {
assert(key == this);
return _futureBytes.then((Uint8List bytes) {
return decode(bytes);
@@ -113,10 +118,19 @@
///
/// See [https://developer.apple.com/documentation/uikit/uiimage/1624146-imagenamed?language=objc]
static ImageProvider load(String name) {
- Future<Map> loadInfo = _channel.invokeMethod('loadImage', name);
+ Future<Map?> loadInfo = _channel.invokeMapMethod('loadImage', name);
Completer<Uint8List> bytesCompleter = Completer<Uint8List>();
Completer<double> scaleCompleter = Completer<double>();
loadInfo.then((map) {
+ 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"]);
});
@@ -129,7 +143,7 @@
/// Returns null if the resource can't be found.
///
/// See [https://developer.apple.com/documentation/foundation/nsbundle/1411540-urlforresource?language=objc]
- static Future<String> resolveURL(String name, [String ext]) {
- return _channel.invokeMethod<String>('resolveURL', [name, ext]);
+ static Future<String?> resolveURL(String name, {String? extension}) {
+ return _channel.invokeMethod<String>('resolveURL', [name, extension]);
}
}
diff --git a/packages/ios_platform_images/pubspec.yaml b/packages/ios_platform_images/pubspec.yaml
index 7049b62..6284f7c 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 @@
dev_dependencies:
flutter_test:
sdk: flutter
- pedantic: ^1.8.0
+ 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/test/ios_platform_images_test.dart b/packages/ios_platform_images/test/ios_platform_images_test.dart
index fd87180..6ed7714 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';
diff --git a/script/nnbd_plugins.sh b/script/nnbd_plugins.sh
index 81ec693..c676573 100644
--- a/script/nnbd_plugins.sh
+++ b/script/nnbd_plugins.sh
@@ -15,6 +15,7 @@
"flutter_plugin_android_lifecycle"
"flutter_webview"
"google_sign_in"
+ "ios_platform_images"
"local_auth"
"path_provider"
"package_info"