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

[ios_platform_images] Migrate to null safety #3381

Merged
merged 11 commits into from
Feb 8, 2021
4 changes: 4 additions & 0 deletions packages/ios_platform_images/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.2.0-nullsafety

* Migrate to null safety.

## 0.1.2+4

* Update Flutter SDK constraint.
Expand Down
4 changes: 2 additions & 2 deletions packages/ios_platform_images/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -19,7 +19,7 @@ dev_dependencies:
sdk: flutter
ios_platform_images:
path: ../
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
Expand Down
33 changes: 19 additions & 14 deletions packages/ios_platform_images/lib/ios_platform_images.dart
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,13 +13,11 @@ import 'package:flutter/foundation.dart'
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'),
Expand All @@ -27,6 +29,9 @@ class _FutureImageStreamCompleter extends ImageStreamCompleter {
});
}

final Future<double> futureScale;
final InformationCollector? informationCollector;

Future<void> _onCodecReady(ui.Codec codec) async {
try {
ui.FrameInfo nextFrame = await codec.getNextFrame();
Expand All @@ -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<Uint8List> _futureBytes;
final Future<double> _futureScale;
Expand All @@ -73,7 +76,9 @@ class _FutureMemoryImage extends ImageProvider<_FutureMemoryImage> {
}

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);
Expand Down Expand Up @@ -113,11 +118,11 @@ class IosPlatformImages {
///
/// 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) {
scaleCompleter.complete(map["scale"]);
scaleCompleter.complete(map!["scale"]);
bytesCompleter.complete(map["data"]);
blasten marked this conversation as resolved.
Show resolved Hide resolved
});
return _FutureMemoryImage(bytesCompleter.future, scaleCompleter.future);
Expand All @@ -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<String> resolveURL(String name, [String ext]) {
static Future<String?> resolveURL(String name, [String? ext]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're doing breaking changes anyway, and optional positional elements are strongly discouraged, should we take the opportunity to make this {String? extension}?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

return _channel.invokeMethod<String>('resolveURL', [name, ext]);
}
}
6 changes: 3 additions & 3 deletions packages/ios_platform_images/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -14,7 +14,7 @@ dependencies:
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
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
1 change: 1 addition & 0 deletions script/nnbd_plugins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down