Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 8d2594d

Browse files
[ios_platform_images] Migrate to null safety (#3381)
1 parent 545c97f commit 8d2594d

File tree

6 files changed

+41
-19
lines changed

6 files changed

+41
-19
lines changed

packages/ios_platform_images/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.2.0-nullsafety
2+
3+
* Migrate to null safety.
4+
15
## 0.1.2+4
26

37
* Update Flutter SDK constraint.

packages/ios_platform_images/example/lib/main.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ class _MyAppState extends State<MyApp> {
1414
void initState() {
1515
super.initState();
1616

17-
IosPlatformImages.resolveURL("textfile", null)
18-
.then((value) => print(value));
17+
IosPlatformImages.resolveURL("textfile").then((value) => print(value));
1918
}
2019

2120
@override

packages/ios_platform_images/lib/ios_platform_images.dart

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2020 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
15
import 'dart:async';
26
import 'dart:typed_data';
37
import 'dart:ui' as ui;
@@ -9,13 +13,11 @@ import 'package:flutter/foundation.dart'
913
show SynchronousFuture, describeIdentity;
1014

1115
class _FutureImageStreamCompleter extends ImageStreamCompleter {
12-
final Future<double> futureScale;
13-
final InformationCollector informationCollector;
14-
15-
_FutureImageStreamCompleter(
16-
{Future<ui.Codec> codec, this.futureScale, this.informationCollector})
17-
: assert(codec != null),
18-
assert(futureScale != null) {
16+
_FutureImageStreamCompleter({
17+
required Future<ui.Codec> codec,
18+
required this.futureScale,
19+
this.informationCollector,
20+
}) {
1921
codec.then<void>(_onCodecReady, onError: (dynamic error, StackTrace stack) {
2022
reportError(
2123
context: ErrorDescription('resolving a single-frame image stream'),
@@ -27,6 +29,9 @@ class _FutureImageStreamCompleter extends ImageStreamCompleter {
2729
});
2830
}
2931

32+
final Future<double> futureScale;
33+
final InformationCollector? informationCollector;
34+
3035
Future<void> _onCodecReady(ui.Codec codec) async {
3136
try {
3237
ui.FrameInfo nextFrame = await codec.getNextFrame();
@@ -50,9 +55,7 @@ class _FutureMemoryImage extends ImageProvider<_FutureMemoryImage> {
5055
/// Constructor for FutureMemoryImage. [_futureBytes] is the bytes that will
5156
/// be loaded into an image and [_futureScale] is the scale that will be applied to
5257
/// that image to account for high-resolution images.
53-
const _FutureMemoryImage(this._futureBytes, this._futureScale)
54-
: assert(_futureBytes != null),
55-
assert(_futureScale != null);
58+
const _FutureMemoryImage(this._futureBytes, this._futureScale);
5659

5760
final Future<Uint8List> _futureBytes;
5861
final Future<double> _futureScale;
@@ -73,7 +76,9 @@ class _FutureMemoryImage extends ImageProvider<_FutureMemoryImage> {
7376
}
7477

7578
Future<ui.Codec> _loadAsync(
76-
_FutureMemoryImage key, DecoderCallback decode) async {
79+
_FutureMemoryImage key,
80+
DecoderCallback decode,
81+
) async {
7782
assert(key == this);
7883
return _futureBytes.then((Uint8List bytes) {
7984
return decode(bytes);
@@ -113,10 +118,19 @@ class IosPlatformImages {
113118
///
114119
/// See [https://developer.apple.com/documentation/uikit/uiimage/1624146-imagenamed?language=objc]
115120
static ImageProvider load(String name) {
116-
Future<Map> loadInfo = _channel.invokeMethod('loadImage', name);
121+
Future<Map?> loadInfo = _channel.invokeMapMethod('loadImage', name);
117122
Completer<Uint8List> bytesCompleter = Completer<Uint8List>();
118123
Completer<double> scaleCompleter = Completer<double>();
119124
loadInfo.then((map) {
125+
if (map == null) {
126+
scaleCompleter.completeError(
127+
Exception("Image couldn't be found: $name"),
128+
);
129+
bytesCompleter.completeError(
130+
Exception("Image couldn't be found: $name"),
131+
);
132+
return;
133+
}
120134
scaleCompleter.complete(map["scale"]);
121135
bytesCompleter.complete(map["data"]);
122136
});
@@ -129,7 +143,7 @@ class IosPlatformImages {
129143
/// Returns null if the resource can't be found.
130144
///
131145
/// See [https://developer.apple.com/documentation/foundation/nsbundle/1411540-urlforresource?language=objc]
132-
static Future<String> resolveURL(String name, [String ext]) {
133-
return _channel.invokeMethod<String>('resolveURL', [name, ext]);
146+
static Future<String?> resolveURL(String name, {String? extension}) {
147+
return _channel.invokeMethod<String>('resolveURL', [name, extension]);
134148
}
135149
}

packages/ios_platform_images/pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name: ios_platform_images
22
description: A plugin to share images between Flutter and iOS in add-to-app setups.
3-
version: 0.1.2+4
3+
version: 0.2.0-nullsafety
44
homepage: https://github.com/flutter/plugins/tree/master/packages/ios_platform_images/ios_platform_images
55

66
environment:
7-
sdk: ">=2.1.0 <3.0.0"
7+
sdk: ">=2.12.0-0 <3.0.0"
88
flutter: ">=1.12.13+hotfix.5"
99

1010
dependencies:
@@ -14,7 +14,7 @@ dependencies:
1414
dev_dependencies:
1515
flutter_test:
1616
sdk: flutter
17-
pedantic: ^1.8.0
17+
pedantic: ^1.10.0-nullsafety
1818

1919
# For information on the generic Dart part of this file, see the
2020
# following page: https://dart.dev/tools/pub/pubspec

packages/ios_platform_images/test/ios_platform_images_test.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2020 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
15
import 'package:flutter/services.dart';
26
import 'package:flutter_test/flutter_test.dart';
37
import 'package:ios_platform_images/ios_platform_images.dart';

script/nnbd_plugins.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ readonly NNBD_PLUGINS_LIST=(
1515
"flutter_plugin_android_lifecycle"
1616
"flutter_webview"
1717
"google_sign_in"
18+
"ios_platform_images"
1819
"local_auth"
1920
"path_provider"
2021
"package_info"

0 commit comments

Comments
 (0)