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

Commit

Permalink
[ios_platform_images] Switch to new analysis options (#4784)
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartmorgan authored Feb 10, 2022
1 parent e2761fd commit 7e73aae
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 31 deletions.
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+4

* Internal code cleanup for stricter analysis options.

## 0.2.0+3

* Internal fix for unused field formal parameter.
Expand Down
1 change: 0 additions & 1 deletion packages/ios_platform_images/analysis_options.yaml

This file was deleted.

5 changes: 3 additions & 2 deletions packages/ios_platform_images/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class _MyAppState extends State<MyApp> {
void initState() {
super.initState();

IosPlatformImages.resolveURL("textfile").then((value) => print(value));
IosPlatformImages.resolveURL('textfile')
.then((String? value) => print(value));
}

@override
Expand All @@ -31,7 +32,7 @@ class _MyAppState extends State<MyApp> {
body: Center(
// "flutter" is a resource in Assets.xcassets.
child: Image(
image: IosPlatformImages.load("flutter"),
image: IosPlatformImages.load('flutter'),
semanticLabel: 'Flutter logo',
),
),
Expand Down
4 changes: 1 addition & 3 deletions packages/ios_platform_images/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ environment:
flutter: ">=2.5.0"

dependencies:
cupertino_icons: ^1.0.2
flutter:
sdk: flutter

cupertino_icons: ^1.0.2

dev_dependencies:
flutter_test:
sdk: flutter
Expand All @@ -22,7 +21,6 @@ dev_dependencies:
# The example app is bundled with the plugin so we use a path dependency on
# the parent directory to use the current plugin's version.
path: ../
pedantic: ^1.10.0

flutter:
uses-material-design: true
3 changes: 1 addition & 2 deletions packages/ios_platform_images/example/test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ void main() {
// Build our app and trigger a frame.
await tester.pumpWidget(MyApp());

// Verify that platform version is retrieved.
expect(
find.byWidgetPredicate(
(Widget widget) =>
widget is Image && (Platform.isIOS ? widget.image != null : true),
widget is Image && (!Platform.isIOS || widget.image != null),
),
findsOneWidget,
);
Expand Down
46 changes: 26 additions & 20 deletions packages/ios_platform_images/lib/ios_platform_images.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import 'dart:async';
import 'dart:typed_data';
import 'dart:ui' as ui;

import 'package:flutter/foundation.dart'
show SynchronousFuture, describeIdentity, immutable, objectRuntimeType;
import 'package:flutter/painting.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter/painting.dart';
import 'package:flutter/foundation.dart'
show SynchronousFuture, describeIdentity;

class _FutureImageStreamCompleter extends ImageStreamCompleter {
_FutureImageStreamCompleter({
required Future<ui.Codec> codec,
required this.futureScale,
}) {
codec.then<void>(_onCodecReady, onError: (dynamic error, StackTrace stack) {
codec.then<void>(_onCodecReady, onError: (Object error, StackTrace stack) {
reportError(
context: ErrorDescription('resolving a single-frame image stream'),
exception: error,
Expand All @@ -31,8 +31,8 @@ class _FutureImageStreamCompleter extends ImageStreamCompleter {

Future<void> _onCodecReady(ui.Codec codec) async {
try {
ui.FrameInfo nextFrame = await codec.getNextFrame();
double scale = await futureScale;
final ui.FrameInfo nextFrame = await codec.getNextFrame();
final double scale = await futureScale;
setImage(ImageInfo(image: nextFrame.image, scale: scale));
} catch (exception, stack) {
reportError(
Expand All @@ -47,6 +47,7 @@ class _FutureImageStreamCompleter extends ImageStreamCompleter {

/// Performs exactly like a [MemoryImage] but instead of taking in bytes it takes
/// in a future that represents bytes.
@immutable
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
Expand Down Expand Up @@ -83,11 +84,13 @@ class _FutureMemoryImage extends ImageProvider<_FutureMemoryImage> {

/// See [ImageProvider.operator==].
@override
bool operator ==(dynamic other) {
if (other.runtimeType != runtimeType) return false;
final _FutureMemoryImage typedOther = other;
return _futureBytes == typedOther._futureBytes &&
_futureScale == typedOther._futureScale;
bool operator ==(Object other) {
if (other.runtimeType != runtimeType) {
return false;
}
return other is _FutureMemoryImage &&
_futureBytes == other._futureBytes &&
_futureScale == other._futureScale;
}

/// See [ImageProvider.hashCode].
Expand All @@ -96,10 +99,11 @@ class _FutureMemoryImage extends ImageProvider<_FutureMemoryImage> {

/// See [ImageProvider.toString].
@override
String toString() =>
'$runtimeType(${describeIdentity(_futureBytes)}, scale: $_futureScale)';
String toString() => '${objectRuntimeType(this, '_FutureMemoryImage')}'
'(${describeIdentity(_futureBytes)}, scale: $_futureScale)';
}

// ignore: avoid_classes_with_only_static_members
/// Class to help loading of iOS platform images into Flutter.
///
/// For example, loading an image that is in `Assets.xcassts`.
Expand All @@ -114,10 +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.invokeMapMethod('loadImage', name);
Completer<Uint8List> bytesCompleter = Completer<Uint8List>();
Completer<double> scaleCompleter = Completer<double>();
loadInfo.then((map) {
final Future<Map<String, dynamic>?> loadInfo =
_channel.invokeMapMethod<String, dynamic>('loadImage', name);
final Completer<Uint8List> bytesCompleter = Completer<Uint8List>();
final Completer<double> scaleCompleter = Completer<double>();
loadInfo.then((Map<String, dynamic>? map) {
if (map == null) {
scaleCompleter.completeError(
Exception("Image couldn't be found: $name"),
Expand All @@ -127,8 +132,8 @@ class IosPlatformImages {
);
return;
}
scaleCompleter.complete(map["scale"]);
bytesCompleter.complete(map["data"]);
scaleCompleter.complete(map['scale']! as double);
bytesCompleter.complete(map['data']! as Uint8List);
});
return _FutureMemoryImage(bytesCompleter.future, scaleCompleter.future);
}
Expand All @@ -140,6 +145,7 @@ class IosPlatformImages {
///
/// See [https://developer.apple.com/documentation/foundation/nsbundle/1411540-urlforresource?language=objc]
static Future<String?> resolveURL(String name, {String? extension}) {
return _channel.invokeMethod<String>('resolveURL', [name, extension]);
return _channel
.invokeMethod<String>('resolveURL', <Object?>[name, extension]);
}
}
2 changes: 1 addition & 1 deletion packages/ios_platform_images/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: ios_platform_images
description: A plugin to share images between Flutter and iOS in add-to-app setups.
repository: https://github.com/flutter/plugins/tree/main/packages/ios_platform_images
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+ios_platform_images%22
version: 0.2.0+3
version: 0.2.0+4

environment:
sdk: ">=2.14.0 <3.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ void main() {
});

test('resolveURL', () async {
expect(await IosPlatformImages.resolveURL("foobar"), '42');
expect(await IosPlatformImages.resolveURL('foobar'), '42');
});
}
1 change: 0 additions & 1 deletion script/configs/custom_analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
- in_app_purchase/in_app_purchase
- in_app_purchase/in_app_purchase_android
- in_app_purchase/in_app_purchase_storekit
- ios_platform_images
- video_player/video_player
- video_player/video_player_platform_interface
- video_player/video_player_web

0 comments on commit 7e73aae

Please sign in to comment.