Skip to content
This repository was 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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 1 addition & 2 deletions packages/ios_platform_images/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ class _MyAppState extends State<MyApp> {
void initState() {
super.initState();

IosPlatformImages.resolveURL("textfile", null)
.then((value) => print(value));
IosPlatformImages.resolveURL("textfile").then((value) => print(value));
}

@override
Expand Down
42 changes: 28 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,10 +118,19 @@ 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) {
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"]);
});
Expand All @@ -129,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<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]);
}
}
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 @@ -15,6 +15,7 @@ readonly NNBD_PLUGINS_LIST=(
"flutter_plugin_android_lifecycle"
"flutter_webview"
"google_sign_in"
"ios_platform_images"
"local_auth"
"path_provider"
"package_info"
Expand Down