From 3a36c5e25218636f4cde8c6a791f4e1932094661 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Fri, 4 Feb 2022 22:07:13 -0700 Subject: [PATCH 01/64] Add loadSystemImage Implement method for loading system images or 'sfsymbols' requires iOS >13.0 --- .../example/test/widget_test.dart | 2 +- .../ios/Classes/IosPlatformImagesPlugin.m | 93 +++++++++++++++++++ .../lib/ios_platform_images.dart | 50 ++++++++++ 3 files changed, 144 insertions(+), 1 deletion(-) diff --git a/packages/ios_platform_images/example/test/widget_test.dart b/packages/ios_platform_images/example/test/widget_test.dart index f3cd4c68b65b..c4a7f8bfbad0 100644 --- a/packages/ios_platform_images/example/test/widget_test.dart +++ b/packages/ios_platform_images/example/test/widget_test.dart @@ -19,7 +19,7 @@ void main() { (Widget widget) => widget is Image && (!Platform.isIOS || widget.image != null), ), - findsOneWidget, + findsNWidgets(2), ); }); } diff --git a/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m b/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m index 5f7debc3fe07..6d27088d1a13 100644 --- a/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m +++ b/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m @@ -40,6 +40,99 @@ + (void)registerWithRegistrar:(NSObject *)registrar { NSURL *url = [[NSBundle mainBundle] URLForResource:name withExtension:extension]; result(url.absoluteString); return; + } else if ([@"loadSystemImage" isEqualToString:call.method]) { + NSString *name = call.arguments[0]; + NSNumber *pointSizeWithDouble = call.arguments[1]; + double pointSize = [pointSizeWithDouble doubleValue]; + NSNumber *weightIndex = call.arguments[2]; + NSNumber *scaleIndex = call.arguments[3]; + + // Up to 3 rgb values for primary, seconday and tertiary colors. + // see + // https://developer.apple.com/documentation/uikit/uiimagesymbolconfiguration/3810054-configurationwithpalettecolors + NSArray *rgbaValuesList = call.arguments[4]; + + NSMutableArray *colorArray = [[NSMutableArray alloc] init]; + + for (int i = 0; i < [rgbaValuesList count]; i += 4) { + UIColor *primaryColor = [UIColor colorWithRed:[rgbaValuesList[i] doubleValue] + green:[rgbaValuesList[i + 1] doubleValue] + blue:[rgbaValuesList[i + 2] doubleValue] + alpha:[rgbaValuesList[i + 3] doubleValue]]; + [colorArray addObject:primaryColor]; + } + + UIImageSymbolScale scale = UIImageSymbolScaleDefault; + + switch ([scaleIndex integerValue]) { + case 0: + scale = UIImageSymbolScaleSmall; + break; + case 1: + scale = UIImageSymbolScaleMedium; + break; + case 2: + scale = UIImageSymbolScaleLarge; + break; + default: + scale = UIImageSymbolScaleDefault; + break; + } + + UIImageSymbolWeight weight = UIImageSymbolWeightRegular; + + switch ([weightIndex integerValue]) { + case 0: + weight = UIImageSymbolWeightUltraLight; + break; + case 1: + weight = UIImageSymbolWeightThin; + break; + case 2: + weight = UIImageSymbolWeightLight; + break; + // 3 is regular + case 4: + weight = UIImageSymbolWeightMedium; + break; + case 5: + weight = UIImageSymbolWeightSemibold; + break; + case 6: + weight = UIImageSymbolWeightBold; + break; + case 7: + weight = UIImageSymbolWeightHeavy; + break; + case 8: + weight = UIImageSymbolWeightBlack; + break; + default: + weight = UIImageSymbolWeightRegular; + break; + } + + UIImageSymbolConfiguration *pointSizeConfig = + [UIImageSymbolConfiguration configurationWithPointSize:pointSize + weight:weight + scale:scale]; + + UIImageSymbolConfiguration *colorConfig = + [UIImageSymbolConfiguration configurationWithPaletteColors:colorArray]; + UIImageSymbolConfiguration *combinedConfig = + [pointSizeConfig configurationByApplyingConfiguration:colorConfig]; + + UIImage *image = [UIImage systemImageNamed:name withConfiguration:combinedConfig]; + NSData *data = UIImagePNGRepresentation(image); + if (data) { + result(@{ + @"scale" : @(image.scale), + @"data" : [FlutterStandardTypedData typedDataWithBytes:data], + }); + } else { + result(nil); + } + return; } result(FlutterMethodNotImplemented); }]; diff --git a/packages/ios_platform_images/lib/ios_platform_images.dart b/packages/ios_platform_images/lib/ios_platform_images.dart index b372d362f6f7..2b222cfadef1 100644 --- a/packages/ios_platform_images/lib/ios_platform_images.dart +++ b/packages/ios_platform_images/lib/ios_platform_images.dart @@ -136,6 +136,56 @@ class IosPlatformImages { return _FutureMemoryImage(bytesCompleter.future, scaleCompleter.future); } + /// Loads an image from the system. The equivalent would be: + /// `[UIImage systemImageNamed:name]`. + /// + /// Throws an exception if the image can't be found. + /// + /// See [https://developer.apple.com/documentation/uikit/uiimage/configuring_and_displaying_symbol_images_in_your_ui?language=objc] + static ImageProvider loadSystemImage( + String name, + List colors, + double pointSize, + int weightIndex, + int scaleIndex, + ) { + List colorsRGBA = colors + .expand((Color color) => [ + color.red.toDouble() / 255, + color.green.toDouble() / 255, + color.blue.toDouble() / 255, + color.alpha.toDouble() / 255, + ]) + .toList(); + + Future loadInfo = _channel.invokeMapMethod( + 'loadSystemImage', + [ + name, + pointSize, + weightIndex, + scaleIndex, + colorsRGBA, + ], + ); + Completer bytesCompleter = Completer(); + Completer scaleCompleter = Completer(); + loadInfo.then((map) { + if (map == null) { + scaleCompleter.completeError( + Exception("System image couldn't be found: $name"), + ); + bytesCompleter.completeError( + Exception("System image couldn't be found: $name"), + ); + return; + } + scaleCompleter.complete(map["scale"]); + bytesCompleter.complete(map["data"]); + }); + return _FutureMemoryImage(bytesCompleter.future, scaleCompleter.future); + } + /// Resolves an URL for a resource. The equivalent would be: /// `[[NSBundle mainBundle] URLForResource:name withExtension:ext]`. /// From a6a20c8fc2cc67884e63ca83f13cb2d5924e4ed5 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Thu, 10 Feb 2022 21:31:47 -0700 Subject: [PATCH 02/64] Add system image to example app --- .../ios_platform_images/example/lib/main.dart | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/ios_platform_images/example/lib/main.dart b/packages/ios_platform_images/example/lib/main.dart index 043bc69c944d..c422171829ae 100644 --- a/packages/ios_platform_images/example/lib/main.dart +++ b/packages/ios_platform_images/example/lib/main.dart @@ -28,16 +28,30 @@ class _MyAppState extends State { @override Widget build(BuildContext context) { + ThemeData theme = Theme.of(context); + Color iconColor = theme.iconTheme.color ?? theme.colorScheme.secondary; + return MaterialApp( home: Scaffold( appBar: AppBar( title: const Text('Plugin example app'), ), body: Center( - // "flutter" is a resource in Assets.xcassets. - child: Image( - image: IosPlatformImages.load('flutter'), - semanticLabel: 'Flutter logo', + // 'flutter' is a resource in Assets.xcassets, 'face.smiling' is an SFSymbol provided with iOS. + child: Column( + children: [ + Text('This is an icon from the iOS bundle'), + Image( + image: IosPlatformImages.load('flutter'), + semanticLabel: 'Flutter logo', + ), + Text('This is an icon from the iOS system'), + Image( + image: IosPlatformImages.loadSystemImage( + 'face.smiling', [iconColor], 100, 1, 1), + semanticLabel: 'Smiling face', + ), + ], ), ), ), From 91c65d79063068f45c4f06b8c8e366300c685f63 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Mon, 3 Oct 2022 02:08:55 -0700 Subject: [PATCH 03/64] Add integration tests --- .../integration_test/ios_platform_images.dart | 28 +++++++++++++++++++ .../ios_platform_images/example/pubspec.yaml | 2 ++ 2 files changed, 30 insertions(+) create mode 100644 packages/ios_platform_images/example/integration_test/ios_platform_images.dart diff --git a/packages/ios_platform_images/example/integration_test/ios_platform_images.dart b/packages/ios_platform_images/example/integration_test/ios_platform_images.dart new file mode 100644 index 000000000000..c4d66b3655b7 --- /dev/null +++ b/packages/ios_platform_images/example/integration_test/ios_platform_images.dart @@ -0,0 +1,28 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; + +import 'package:ios_platform_images_example/main.dart' as app; + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + testWidgets( + 'load ios bundled image', + (WidgetTester tester) async { + app.main(); + await tester.pumpAndSettle(); + + expect(find.bySemanticsLabel('Flutter logo'), findsOneWidget); + }, + ); + + testWidgets( + 'load ios system image', + (WidgetTester tester) async { + app.main(); + await tester.pumpAndSettle(); + + expect(find.bySemanticsLabel('Smiling face'), findsOneWidget); + }, + ); +} diff --git a/packages/ios_platform_images/example/pubspec.yaml b/packages/ios_platform_images/example/pubspec.yaml index 49b09bd8b637..86194662db5c 100644 --- a/packages/ios_platform_images/example/pubspec.yaml +++ b/packages/ios_platform_images/example/pubspec.yaml @@ -19,6 +19,8 @@ dependencies: path: ../ dev_dependencies: + integration_test: + sdk: flutter flutter_test: sdk: flutter From f1af677ec8cf6e520d049486325cccd07cc6e49d Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Thu, 10 Feb 2022 21:25:37 -0700 Subject: [PATCH 04/64] Add iOS check and method warning There could be some possible CI concerns if this method errors during an integration test on < iOS 13. --- .../ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m | 2 +- packages/ios_platform_images/lib/ios_platform_images.dart | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m b/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m index 6d27088d1a13..53dcecf303dc 100644 --- a/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m +++ b/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m @@ -40,7 +40,7 @@ + (void)registerWithRegistrar:(NSObject *)registrar { NSURL *url = [[NSBundle mainBundle] URLForResource:name withExtension:extension]; result(url.absoluteString); return; - } else if ([@"loadSystemImage" isEqualToString:call.method]) { + } else if ([@"loadSystemImage" isEqualToString:call.method] && @available(iOS 13, *)) { NSString *name = call.arguments[0]; NSNumber *pointSizeWithDouble = call.arguments[1]; double pointSize = [pointSizeWithDouble doubleValue]; diff --git a/packages/ios_platform_images/lib/ios_platform_images.dart b/packages/ios_platform_images/lib/ios_platform_images.dart index 2b222cfadef1..efd7cbad7080 100644 --- a/packages/ios_platform_images/lib/ios_platform_images.dart +++ b/packages/ios_platform_images/lib/ios_platform_images.dart @@ -141,6 +141,8 @@ class IosPlatformImages { /// /// Throws an exception if the image can't be found. /// + /// **This method requires at least iOS 13.0** + /// /// See [https://developer.apple.com/documentation/uikit/uiimage/configuring_and_displaying_symbol_images_in_your_ui?language=objc] static ImageProvider loadSystemImage( String name, From dcaaeb7dceb405a4ea30e1487e53a93983f45307 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Fri, 11 Feb 2022 11:36:53 -0700 Subject: [PATCH 05/64] Formatting fixes --- .../lib/ios_platform_images.dart | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/ios_platform_images/lib/ios_platform_images.dart b/packages/ios_platform_images/lib/ios_platform_images.dart index efd7cbad7080..db6780e669af 100644 --- a/packages/ios_platform_images/lib/ios_platform_images.dart +++ b/packages/ios_platform_images/lib/ios_platform_images.dart @@ -151,8 +151,8 @@ class IosPlatformImages { int weightIndex, int scaleIndex, ) { - List colorsRGBA = colors - .expand((Color color) => [ + final List colorsRGBA = colors + .expand((Color color) => [ color.red.toDouble() / 255, color.green.toDouble() / 255, color.blue.toDouble() / 255, @@ -160,9 +160,10 @@ class IosPlatformImages { ]) .toList(); - Future loadInfo = _channel.invokeMapMethod( + final Future?> loadInfo = + _channel.invokeMapMethod( 'loadSystemImage', - [ + [ name, pointSize, weightIndex, @@ -170,9 +171,9 @@ class IosPlatformImages { colorsRGBA, ], ); - Completer bytesCompleter = Completer(); - Completer scaleCompleter = Completer(); - loadInfo.then((map) { + final Completer bytesCompleter = Completer(); + final Completer scaleCompleter = Completer(); + loadInfo.then((Map? map) { if (map == null) { scaleCompleter.completeError( Exception("System image couldn't be found: $name"), @@ -182,8 +183,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); } From a1eef31bf1aec72f4ac91ba3e7800febbec16100 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Sun, 17 Jul 2022 04:01:34 -0600 Subject: [PATCH 06/64] Version bump, edit changelog.md --- packages/ios_platform_images/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/ios_platform_images/CHANGELOG.md b/packages/ios_platform_images/CHANGELOG.md index 63f10450cfd7..abe462ba791f 100644 --- a/packages/ios_platform_images/CHANGELOG.md +++ b/packages/ios_platform_images/CHANGELOG.md @@ -8,6 +8,10 @@ * Removes usage of deprecated [ImageProvider.load]. * Ignores unnecessary import warnings in preparation for [upcoming Flutter changes](https://github.com/flutter/flutter/pull/106316). +## 0.2.1 + +* Added `loadSystemImage` to load system images, also known as 'sfsymbols'. + ## 0.2.0+9 * Ignores the warning for the upcoming deprecation of `DecoderCallback`. From 4ab520844a752071730c206e130c0aef1e94b835 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Mon, 3 Oct 2022 02:09:11 -0700 Subject: [PATCH 07/64] Fix ios_platform_images example app formatting --- .../integration_test/ios_platform_images.dart | 4 ++++ packages/ios_platform_images/example/lib/main.dart | 14 +++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/ios_platform_images/example/integration_test/ios_platform_images.dart b/packages/ios_platform_images/example/integration_test/ios_platform_images.dart index c4d66b3655b7..77d3e95016c1 100644 --- a/packages/ios_platform_images/example/integration_test/ios_platform_images.dart +++ b/packages/ios_platform_images/example/integration_test/ios_platform_images.dart @@ -1,3 +1,7 @@ +// Copyright 2013 The Flutter 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_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; diff --git a/packages/ios_platform_images/example/lib/main.dart b/packages/ios_platform_images/example/lib/main.dart index c422171829ae..fb9706cb247b 100644 --- a/packages/ios_platform_images/example/lib/main.dart +++ b/packages/ios_platform_images/example/lib/main.dart @@ -22,14 +22,14 @@ class _MyAppState extends State { super.initState(); IosPlatformImages.resolveURL('textfile') - // ignore: avoid_print .then((String? value) => print(value)); } @override Widget build(BuildContext context) { - ThemeData theme = Theme.of(context); - Color iconColor = theme.iconTheme.color ?? theme.colorScheme.secondary; + final ThemeData theme = Theme.of(context); + final Color iconColor = + theme.iconTheme.color ?? theme.colorScheme.secondary; return MaterialApp( home: Scaffold( @@ -39,16 +39,16 @@ class _MyAppState extends State { body: Center( // 'flutter' is a resource in Assets.xcassets, 'face.smiling' is an SFSymbol provided with iOS. child: Column( - children: [ - Text('This is an icon from the iOS bundle'), + children: [ + const Text('This is an icon from the iOS bundle'), Image( image: IosPlatformImages.load('flutter'), semanticLabel: 'Flutter logo', ), - Text('This is an icon from the iOS system'), + const Text('This is an icon from the iOS system'), Image( image: IosPlatformImages.loadSystemImage( - 'face.smiling', [iconColor], 100, 1, 1), + 'face.smiling', [iconColor], 100, 1, 1), semanticLabel: 'Smiling face', ), ], From 6aea17a0f6f071e584e51034c411a387bbddf550 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Fri, 11 Feb 2022 17:56:31 -0700 Subject: [PATCH 08/64] Fix xcode_analyze and multicolor symbols --- .../integration_test/ios_platform_images.dart | 4 +- .../ios_platform_images/example/lib/main.dart | 24 ++- .../example/test/widget_test.dart | 2 +- .../ios/Classes/IosPlatformImagesPlugin.m | 200 ++++++++++-------- .../lib/ios_platform_images.dart | 14 +- 5 files changed, 141 insertions(+), 103 deletions(-) diff --git a/packages/ios_platform_images/example/integration_test/ios_platform_images.dart b/packages/ios_platform_images/example/integration_test/ios_platform_images.dart index 77d3e95016c1..08011756bc19 100644 --- a/packages/ios_platform_images/example/integration_test/ios_platform_images.dart +++ b/packages/ios_platform_images/example/integration_test/ios_platform_images.dart @@ -21,12 +21,14 @@ void main() { ); testWidgets( - 'load ios system image', + 'load ios system images', (WidgetTester tester) async { app.main(); await tester.pumpAndSettle(); expect(find.bySemanticsLabel('Smiling face'), findsOneWidget); + expect(find.bySemanticsLabel('Sprinting hare'), findsOneWidget); + expect(find.bySemanticsLabel('Ladybug'), findsOneWidget); }, ); } diff --git a/packages/ios_platform_images/example/lib/main.dart b/packages/ios_platform_images/example/lib/main.dart index fb9706cb247b..22a38edee64e 100644 --- a/packages/ios_platform_images/example/lib/main.dart +++ b/packages/ios_platform_images/example/lib/main.dart @@ -40,17 +40,33 @@ class _MyAppState extends State { // 'flutter' is a resource in Assets.xcassets, 'face.smiling' is an SFSymbol provided with iOS. child: Column( children: [ - const Text('This is an icon from the iOS bundle'), + const Text('This is an icon from the iOS asset bundle'), Image( image: IosPlatformImages.load('flutter'), semanticLabel: 'Flutter logo', ), - const Text('This is an icon from the iOS system'), + const Text('These are icons from the iOS system'), Image( - image: IosPlatformImages.loadSystemImage( - 'face.smiling', [iconColor], 100, 1, 1), + image: IosPlatformImages.loadSystemImage('face.smiling', 100, + colors: [iconColor]), semanticLabel: 'Smiling face', ), + Image( + image: IosPlatformImages.loadSystemImage( + 'hare.fill', + 100, + colors: [theme.colorScheme.secondary], + ), + semanticLabel: 'Sprinting hare', + ), + Image( + image: IosPlatformImages.loadSystemImage( + 'ladybug.fill', + 100, + preferMulticolor: true, + ), + semanticLabel: 'Ladybug', + ), ], ), ), diff --git a/packages/ios_platform_images/example/test/widget_test.dart b/packages/ios_platform_images/example/test/widget_test.dart index c4a7f8bfbad0..5e921779644f 100644 --- a/packages/ios_platform_images/example/test/widget_test.dart +++ b/packages/ios_platform_images/example/test/widget_test.dart @@ -19,7 +19,7 @@ void main() { (Widget widget) => widget is Image && (!Platform.isIOS || widget.image != null), ), - findsNWidgets(2), + findsNWidgets(4), ); }); } diff --git a/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m b/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m index 53dcecf303dc..5edc06841afa 100644 --- a/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m +++ b/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m @@ -40,99 +40,115 @@ + (void)registerWithRegistrar:(NSObject *)registrar { NSURL *url = [[NSBundle mainBundle] URLForResource:name withExtension:extension]; result(url.absoluteString); return; - } else if ([@"loadSystemImage" isEqualToString:call.method] && @available(iOS 13, *)) { - NSString *name = call.arguments[0]; - NSNumber *pointSizeWithDouble = call.arguments[1]; - double pointSize = [pointSizeWithDouble doubleValue]; - NSNumber *weightIndex = call.arguments[2]; - NSNumber *scaleIndex = call.arguments[3]; - - // Up to 3 rgb values for primary, seconday and tertiary colors. - // see - // https://developer.apple.com/documentation/uikit/uiimagesymbolconfiguration/3810054-configurationwithpalettecolors - NSArray *rgbaValuesList = call.arguments[4]; - - NSMutableArray *colorArray = [[NSMutableArray alloc] init]; - - for (int i = 0; i < [rgbaValuesList count]; i += 4) { - UIColor *primaryColor = [UIColor colorWithRed:[rgbaValuesList[i] doubleValue] - green:[rgbaValuesList[i + 1] doubleValue] - blue:[rgbaValuesList[i + 2] doubleValue] - alpha:[rgbaValuesList[i + 3] doubleValue]]; - [colorArray addObject:primaryColor]; + } else if ([@"loadSystemImage" isEqualToString:call.method]) { + if (@available(iOS 13, *)) { + NSString *name = call.arguments[0]; + NSNumber *pointSizeWithDouble = call.arguments[1]; + double pointSize = [pointSizeWithDouble doubleValue]; + NSNumber *weightIndex = call.arguments[2]; + NSNumber *scaleIndex = call.arguments[3]; + + // Up to 3 rgb values for primary, seconday and tertiary colors. + // see + // https://developer.apple.com/documentation/uikit/uiimagesymbolconfiguration/3810054-configurationwithpalettecolors + NSArray *rgbaValuesList = call.arguments[4]; + + NSMutableArray *colorArray = [[NSMutableArray alloc] init]; + + for (int i = 0; i < [rgbaValuesList count]; i += 4) { + UIColor *primaryColor = [UIColor colorWithRed:[rgbaValuesList[i] doubleValue] + green:[rgbaValuesList[i + 1] doubleValue] + blue:[rgbaValuesList[i + 2] doubleValue] + alpha:[rgbaValuesList[i + 3] doubleValue]]; + [colorArray addObject:primaryColor]; + } + + UIImageSymbolScale scale = UIImageSymbolScaleDefault; + + switch ([scaleIndex integerValue]) { + case 0: + scale = UIImageSymbolScaleSmall; + break; + case 1: + scale = UIImageSymbolScaleMedium; + break; + case 2: + scale = UIImageSymbolScaleLarge; + break; + default: + scale = UIImageSymbolScaleDefault; + break; + } + + UIImageSymbolWeight weight = UIImageSymbolWeightRegular; + + switch ([weightIndex integerValue]) { + case 0: + weight = UIImageSymbolWeightUltraLight; + break; + case 1: + weight = UIImageSymbolWeightThin; + break; + case 2: + weight = UIImageSymbolWeightLight; + break; + // 3 is regular + case 4: + weight = UIImageSymbolWeightMedium; + break; + case 5: + weight = UIImageSymbolWeightSemibold; + break; + case 6: + weight = UIImageSymbolWeightBold; + break; + case 7: + weight = UIImageSymbolWeightHeavy; + break; + case 8: + weight = UIImageSymbolWeightBlack; + break; + default: + weight = UIImageSymbolWeightRegular; + break; + } + + UIImageSymbolConfiguration *pointSizeConfig = + [UIImageSymbolConfiguration configurationWithPointSize:pointSize + weight:weight + scale:scale]; + + + UIImage *finalImage; + + if (@available(iOS 15, *)) { + NSNumber *preferMulticolor = call.arguments[5]; + UIImageSymbolConfiguration *colors; + + if ([preferMulticolor boolValue]) { + colors = [UIImageSymbolConfiguration configurationPreferringMulticolor]; + } else { + colors = [UIImageSymbolConfiguration configurationWithPaletteColors:colorArray]; + } + + UIImageSymbolConfiguration *final = [pointSizeConfig configurationByApplyingConfiguration:colors]; + finalImage = [UIImage systemImageNamed:name withConfiguration:final]; + } else { + UIImage *image = [UIImage systemImageNamed:name withConfiguration:pointSizeConfig]; + finalImage = [image imageWithTintColor: colorArray[0]]; + } + + NSData *data = UIImagePNGRepresentation(finalImage); + if (data) { + result(@{ + @"scale" : @(finalImage.scale), + @"data" : [FlutterStandardTypedData typedDataWithBytes:data], + }); + } else { + result(nil); + } + return; } - - UIImageSymbolScale scale = UIImageSymbolScaleDefault; - - switch ([scaleIndex integerValue]) { - case 0: - scale = UIImageSymbolScaleSmall; - break; - case 1: - scale = UIImageSymbolScaleMedium; - break; - case 2: - scale = UIImageSymbolScaleLarge; - break; - default: - scale = UIImageSymbolScaleDefault; - break; - } - - UIImageSymbolWeight weight = UIImageSymbolWeightRegular; - - switch ([weightIndex integerValue]) { - case 0: - weight = UIImageSymbolWeightUltraLight; - break; - case 1: - weight = UIImageSymbolWeightThin; - break; - case 2: - weight = UIImageSymbolWeightLight; - break; - // 3 is regular - case 4: - weight = UIImageSymbolWeightMedium; - break; - case 5: - weight = UIImageSymbolWeightSemibold; - break; - case 6: - weight = UIImageSymbolWeightBold; - break; - case 7: - weight = UIImageSymbolWeightHeavy; - break; - case 8: - weight = UIImageSymbolWeightBlack; - break; - default: - weight = UIImageSymbolWeightRegular; - break; - } - - UIImageSymbolConfiguration *pointSizeConfig = - [UIImageSymbolConfiguration configurationWithPointSize:pointSize - weight:weight - scale:scale]; - - UIImageSymbolConfiguration *colorConfig = - [UIImageSymbolConfiguration configurationWithPaletteColors:colorArray]; - UIImageSymbolConfiguration *combinedConfig = - [pointSizeConfig configurationByApplyingConfiguration:colorConfig]; - - UIImage *image = [UIImage systemImageNamed:name withConfiguration:combinedConfig]; - NSData *data = UIImagePNGRepresentation(image); - if (data) { - result(@{ - @"scale" : @(image.scale), - @"data" : [FlutterStandardTypedData typedDataWithBytes:data], - }); - } else { - result(nil); - } - return; } result(FlutterMethodNotImplemented); }]; diff --git a/packages/ios_platform_images/lib/ios_platform_images.dart b/packages/ios_platform_images/lib/ios_platform_images.dart index db6780e669af..c118d73cae7a 100644 --- a/packages/ios_platform_images/lib/ios_platform_images.dart +++ b/packages/ios_platform_images/lib/ios_platform_images.dart @@ -141,16 +141,19 @@ class IosPlatformImages { /// /// Throws an exception if the image can't be found. /// + /// TODO add docs explaining color behavior + /// /// **This method requires at least iOS 13.0** /// /// See [https://developer.apple.com/documentation/uikit/uiimage/configuring_and_displaying_symbol_images_in_your_ui?language=objc] static ImageProvider loadSystemImage( String name, - List colors, - double pointSize, - int weightIndex, - int scaleIndex, - ) { + double pointSize, { + List colors = const [], + bool preferMulticolor = false, + int weightIndex = 1, + int scaleIndex = 1, + }) { final List colorsRGBA = colors .expand((Color color) => [ color.red.toDouble() / 255, @@ -169,6 +172,7 @@ class IosPlatformImages { weightIndex, scaleIndex, colorsRGBA, + preferMulticolor, ], ); final Completer bytesCompleter = Completer(); From b622ca2608cd194a2c03125446d78d89f8935803 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Fri, 11 Feb 2022 17:56:41 -0700 Subject: [PATCH 09/64] Add color behavior docs --- .../lib/ios_platform_images.dart | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/ios_platform_images/lib/ios_platform_images.dart b/packages/ios_platform_images/lib/ios_platform_images.dart index c118d73cae7a..553afe66bce3 100644 --- a/packages/ios_platform_images/lib/ios_platform_images.dart +++ b/packages/ios_platform_images/lib/ios_platform_images.dart @@ -141,8 +141,19 @@ class IosPlatformImages { /// /// Throws an exception if the image can't be found. /// - /// TODO add docs explaining color behavior + /// [colors] takes a list of colors to be applied to the corresponding layer + /// of the icon, assuming that layer exists. An icon can have up to 3 layers, + /// if a layer color is not specified it will take the color of the most recent + /// valid index. /// + /// For more information see [https://developer.apple.com/documentation/uikit/uiimagesymbolconfiguration/3810054-configurationwithpalettecolors?language=objc] + /// + /// [preferMulticolor] overrides [colors] and asks iOS to provide its preset + /// multicolor varient of the symbol. Depending on the symbol, these colors + /// *may not be mutable*. To find out, use the SF Symbols app found at + /// [https://developer.apple.com/sf-symbols/] + /// + /// Multi-layer and multi-color symbols only work on iOS 15.0 and above. /// **This method requires at least iOS 13.0** /// /// See [https://developer.apple.com/documentation/uikit/uiimage/configuring_and_displaying_symbol_images_in_your_ui?language=objc] From 4ac71a388ddaa8b3a0387bd2caca562eae4a3c76 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Fri, 11 Feb 2022 18:03:54 -0700 Subject: [PATCH 10/64] Fix format --- .../ios/Classes/IosPlatformImagesPlugin.m | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m b/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m index 5edc06841afa..09c5ad710809 100644 --- a/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m +++ b/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m @@ -58,7 +58,7 @@ + (void)registerWithRegistrar:(NSObject *)registrar { for (int i = 0; i < [rgbaValuesList count]; i += 4) { UIColor *primaryColor = [UIColor colorWithRed:[rgbaValuesList[i] doubleValue] green:[rgbaValuesList[i + 1] doubleValue] - blue:[rgbaValuesList[i + 2] doubleValue] + blue:[rgbaValuesList[i + 2] doubleValue] alpha:[rgbaValuesList[i + 3] doubleValue]]; [colorArray addObject:primaryColor]; } @@ -116,11 +116,10 @@ + (void)registerWithRegistrar:(NSObject *)registrar { UIImageSymbolConfiguration *pointSizeConfig = [UIImageSymbolConfiguration configurationWithPointSize:pointSize weight:weight - scale:scale]; - + scale:scale]; UIImage *finalImage; - + if (@available(iOS 15, *)) { NSNumber *preferMulticolor = call.arguments[5]; UIImageSymbolConfiguration *colors; @@ -131,11 +130,12 @@ + (void)registerWithRegistrar:(NSObject *)registrar { colors = [UIImageSymbolConfiguration configurationWithPaletteColors:colorArray]; } - UIImageSymbolConfiguration *final = [pointSizeConfig configurationByApplyingConfiguration:colors]; + UIImageSymbolConfiguration *final = + [pointSizeConfig configurationByApplyingConfiguration:colors]; finalImage = [UIImage systemImageNamed:name withConfiguration:final]; } else { UIImage *image = [UIImage systemImageNamed:name withConfiguration:pointSizeConfig]; - finalImage = [image imageWithTintColor: colorArray[0]]; + finalImage = [image imageWithTintColor:colorArray[0]]; } NSData *data = UIImagePNGRepresentation(finalImage); From 29295667959cb2cf0cd086b9ee1c4c36ed46e3e1 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Fri, 18 Feb 2022 17:01:10 -0700 Subject: [PATCH 11/64] Throw ArgumentError when symbol not found As opposed to `Exception` previously. --- packages/ios_platform_images/lib/ios_platform_images.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ios_platform_images/lib/ios_platform_images.dart b/packages/ios_platform_images/lib/ios_platform_images.dart index 553afe66bce3..8d21defdbc79 100644 --- a/packages/ios_platform_images/lib/ios_platform_images.dart +++ b/packages/ios_platform_images/lib/ios_platform_images.dart @@ -191,10 +191,10 @@ class IosPlatformImages { loadInfo.then((Map? map) { if (map == null) { scaleCompleter.completeError( - Exception("System image couldn't be found: $name"), + ArgumentError("System image couldn't be found: $name"), ); bytesCompleter.completeError( - Exception("System image couldn't be found: $name"), + ArgumentError("System image couldn't be found: $name"), ); return; } From d7e63a97e3cc4d2b0f641d63b9477609289c58c5 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Fri, 18 Feb 2022 17:02:35 -0700 Subject: [PATCH 12/64] Add test for error case --- .../integration_test/ios_platform_images.dart | 11 +++++++++++ .../ios_platform_images/example/lib/main.dart | 15 +++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/packages/ios_platform_images/example/integration_test/ios_platform_images.dart b/packages/ios_platform_images/example/integration_test/ios_platform_images.dart index 08011756bc19..b4e1e922cf1f 100644 --- a/packages/ios_platform_images/example/integration_test/ios_platform_images.dart +++ b/packages/ios_platform_images/example/integration_test/ios_platform_images.dart @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'dart:math'; + import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; @@ -31,4 +33,13 @@ void main() { expect(find.bySemanticsLabel('Ladybug'), findsOneWidget); }, ); + + testWidgets( + 'ios system image error case', + (WidgetTester tester) async { + await tester.pumpWidget(app.IOSImageExampleError()); + + expect(find.bySemanticsLabel('Nonexistant Symbol'), findsNothing); + }, + ); } diff --git a/packages/ios_platform_images/example/lib/main.dart b/packages/ios_platform_images/example/lib/main.dart index 22a38edee64e..eef81695de24 100644 --- a/packages/ios_platform_images/example/lib/main.dart +++ b/packages/ios_platform_images/example/lib/main.dart @@ -74,3 +74,18 @@ class _MyAppState extends State { ); } } + +/// Example app containing an invalid symbol reference. +class IOSImageExampleError extends StatelessWidget { + @override + Widget build(BuildContext context) { + return MaterialApp( + home: Scaffold( + body: Image( + image: IosPlatformImages.loadSystemImage('nonexistent.sfsymbol', 100), + semanticLabel: 'Nonexistant Symbol', + ), + ), + ); + } +} From c083b6f8f2856b2a4ea1cca8480d9e09f5d14813 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Fri, 18 Feb 2022 21:08:52 -0700 Subject: [PATCH 13/64] Remove unused import --- .../example/integration_test/ios_platform_images.dart | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/ios_platform_images/example/integration_test/ios_platform_images.dart b/packages/ios_platform_images/example/integration_test/ios_platform_images.dart index b4e1e922cf1f..fb0b5ae53866 100644 --- a/packages/ios_platform_images/example/integration_test/ios_platform_images.dart +++ b/packages/ios_platform_images/example/integration_test/ios_platform_images.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:math'; - import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; From faae33fd023cc5c6a7f81a700810738df7f1e1e7 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Thu, 24 Feb 2022 08:53:30 -0700 Subject: [PATCH 14/64] Add clarification to docs - Document behavior with empty color list. - Note that Apple colors differ slightly when the device is set to dark or light mode. --- packages/ios_platform_images/lib/ios_platform_images.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/ios_platform_images/lib/ios_platform_images.dart b/packages/ios_platform_images/lib/ios_platform_images.dart index 8d21defdbc79..bfd21a99f856 100644 --- a/packages/ios_platform_images/lib/ios_platform_images.dart +++ b/packages/ios_platform_images/lib/ios_platform_images.dart @@ -144,7 +144,7 @@ class IosPlatformImages { /// [colors] takes a list of colors to be applied to the corresponding layer /// of the icon, assuming that layer exists. An icon can have up to 3 layers, /// if a layer color is not specified it will take the color of the most recent - /// valid index. + /// valid index. Defaults to an empty list (black). /// /// For more information see [https://developer.apple.com/documentation/uikit/uiimagesymbolconfiguration/3810054-configurationwithpalettecolors?language=objc] /// @@ -152,6 +152,8 @@ class IosPlatformImages { /// multicolor varient of the symbol. Depending on the symbol, these colors /// *may not be mutable*. To find out, use the SF Symbols app found at /// [https://developer.apple.com/sf-symbols/] + /// Also note that regardless of mutability, the symbols default colors are + /// affected by the devices theme preference. /// /// Multi-layer and multi-color symbols only work on iOS 15.0 and above. /// **This method requires at least iOS 13.0** From 249f966e8f59d0f9d738537344d442ab164bcde0 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Thu, 24 Feb 2022 08:54:34 -0700 Subject: [PATCH 15/64] Add multicolor icon to example app --- packages/ios_platform_images/example/lib/main.dart | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/ios_platform_images/example/lib/main.dart b/packages/ios_platform_images/example/lib/main.dart index eef81695de24..fe80db8a5580 100644 --- a/packages/ios_platform_images/example/lib/main.dart +++ b/packages/ios_platform_images/example/lib/main.dart @@ -53,9 +53,13 @@ class _MyAppState extends State { ), Image( image: IosPlatformImages.loadSystemImage( - 'hare.fill', + 'hammer.circle.fill', 100, - colors: [theme.colorScheme.secondary], + scaleIndex: 1, + colors: [ + theme.colorScheme.primary, + theme.colorScheme.primary.withAlpha(100), + ], ), semanticLabel: 'Sprinting hare', ), From 59caf132f30226de1412624ee7d4496c9f7537ba Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Thu, 24 Feb 2022 08:56:20 -0700 Subject: [PATCH 16/64] Switch weight from int to FontWeight --- packages/ios_platform_images/lib/ios_platform_images.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ios_platform_images/lib/ios_platform_images.dart b/packages/ios_platform_images/lib/ios_platform_images.dart index bfd21a99f856..a37301541179 100644 --- a/packages/ios_platform_images/lib/ios_platform_images.dart +++ b/packages/ios_platform_images/lib/ios_platform_images.dart @@ -164,7 +164,7 @@ class IosPlatformImages { double pointSize, { List colors = const [], bool preferMulticolor = false, - int weightIndex = 1, + ui.FontWeight weight = FontWeight.normal, int scaleIndex = 1, }) { final List colorsRGBA = colors @@ -182,7 +182,7 @@ class IosPlatformImages { [ name, pointSize, - weightIndex, + weight.index, scaleIndex, colorsRGBA, preferMulticolor, From f8c7f65b27fb43bf4bbb3832ad9389269b1c79e9 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Fri, 25 Feb 2022 16:53:55 -0700 Subject: [PATCH 17/64] Fix crash on *)registrar { finalImage = [UIImage systemImageNamed:name withConfiguration:final]; } else { UIImage *image = [UIImage systemImageNamed:name withConfiguration:pointSizeConfig]; - finalImage = [image imageWithTintColor:colorArray[0]]; + finalImage = [image imageWithTintColor:colorArray.count>0 ? colorArray[0] : nil]; } NSData *data = UIImagePNGRepresentation(finalImage); From 99f449f030b9878898da9fd67dfe7fe063783d2e Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Mon, 28 Feb 2022 19:46:54 -0700 Subject: [PATCH 18/64] Remove scale index --- .../ios/Classes/IosPlatformImagesPlugin.m | 24 +++---------------- .../lib/ios_platform_images.dart | 2 -- 2 files changed, 3 insertions(+), 23 deletions(-) diff --git a/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m b/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m index 1c7f00d6d6e4..dfc09f2a8231 100644 --- a/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m +++ b/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m @@ -46,12 +46,11 @@ + (void)registerWithRegistrar:(NSObject *)registrar { NSNumber *pointSizeWithDouble = call.arguments[1]; double pointSize = [pointSizeWithDouble doubleValue]; NSNumber *weightIndex = call.arguments[2]; - NSNumber *scaleIndex = call.arguments[3]; // Up to 3 rgb values for primary, seconday and tertiary colors. // see // https://developer.apple.com/documentation/uikit/uiimagesymbolconfiguration/3810054-configurationwithpalettecolors - NSArray *rgbaValuesList = call.arguments[4]; + NSArray *rgbaValuesList = call.arguments[3]; NSMutableArray *colorArray = [[NSMutableArray alloc] init]; @@ -63,23 +62,6 @@ + (void)registerWithRegistrar:(NSObject *)registrar { [colorArray addObject:primaryColor]; } - UIImageSymbolScale scale = UIImageSymbolScaleDefault; - - switch ([scaleIndex integerValue]) { - case 0: - scale = UIImageSymbolScaleSmall; - break; - case 1: - scale = UIImageSymbolScaleMedium; - break; - case 2: - scale = UIImageSymbolScaleLarge; - break; - default: - scale = UIImageSymbolScaleDefault; - break; - } - UIImageSymbolWeight weight = UIImageSymbolWeightRegular; switch ([weightIndex integerValue]) { @@ -116,12 +98,12 @@ + (void)registerWithRegistrar:(NSObject *)registrar { UIImageSymbolConfiguration *pointSizeConfig = [UIImageSymbolConfiguration configurationWithPointSize:pointSize weight:weight - scale:scale]; + scale: UIImageSymbolScaleDefault]; UIImage *finalImage; if (@available(iOS 15, *)) { - NSNumber *preferMulticolor = call.arguments[5]; + NSNumber *preferMulticolor = call.arguments[4]; UIImageSymbolConfiguration *colors; if ([preferMulticolor boolValue]) { diff --git a/packages/ios_platform_images/lib/ios_platform_images.dart b/packages/ios_platform_images/lib/ios_platform_images.dart index a37301541179..0daf3605a0e1 100644 --- a/packages/ios_platform_images/lib/ios_platform_images.dart +++ b/packages/ios_platform_images/lib/ios_platform_images.dart @@ -165,7 +165,6 @@ class IosPlatformImages { List colors = const [], bool preferMulticolor = false, ui.FontWeight weight = FontWeight.normal, - int scaleIndex = 1, }) { final List colorsRGBA = colors .expand((Color color) => [ @@ -183,7 +182,6 @@ class IosPlatformImages { name, pointSize, weight.index, - scaleIndex, colorsRGBA, preferMulticolor, ], From ba62957fc56818503d97f92d5d35abd2820c63f0 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Mon, 28 Feb 2022 22:20:50 -0700 Subject: [PATCH 19/64] Correct formatting --- packages/ios_platform_images/example/lib/main.dart | 1 - .../ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/ios_platform_images/example/lib/main.dart b/packages/ios_platform_images/example/lib/main.dart index fe80db8a5580..6efa47e3ec17 100644 --- a/packages/ios_platform_images/example/lib/main.dart +++ b/packages/ios_platform_images/example/lib/main.dart @@ -55,7 +55,6 @@ class _MyAppState extends State { image: IosPlatformImages.loadSystemImage( 'hammer.circle.fill', 100, - scaleIndex: 1, colors: [ theme.colorScheme.primary, theme.colorScheme.primary.withAlpha(100), diff --git a/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m b/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m index dfc09f2a8231..f426c8580842 100644 --- a/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m +++ b/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m @@ -98,7 +98,7 @@ + (void)registerWithRegistrar:(NSObject *)registrar { UIImageSymbolConfiguration *pointSizeConfig = [UIImageSymbolConfiguration configurationWithPointSize:pointSize weight:weight - scale: UIImageSymbolScaleDefault]; + scale:UIImageSymbolScaleDefault]; UIImage *finalImage; @@ -117,7 +117,7 @@ + (void)registerWithRegistrar:(NSObject *)registrar { finalImage = [UIImage systemImageNamed:name withConfiguration:final]; } else { UIImage *image = [UIImage systemImageNamed:name withConfiguration:pointSizeConfig]; - finalImage = [image imageWithTintColor:colorArray.count>0 ? colorArray[0] : nil]; + finalImage = [image imageWithTintColor:colorArray.count > 0 ? colorArray[0] : nil]; } NSData *data = UIImagePNGRepresentation(finalImage); From d60108b7dffbf1e30bad368e00568120f9f7a3e2 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Tue, 1 Mar 2022 12:34:51 -0700 Subject: [PATCH 20/64] Documentation fixes --- .../lib/ios_platform_images.dart | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/ios_platform_images/lib/ios_platform_images.dart b/packages/ios_platform_images/lib/ios_platform_images.dart index 0daf3605a0e1..88a333d86f05 100644 --- a/packages/ios_platform_images/lib/ios_platform_images.dart +++ b/packages/ios_platform_images/lib/ios_platform_images.dart @@ -141,22 +141,29 @@ class IosPlatformImages { /// /// Throws an exception if the image can't be found. /// - /// [colors] takes a list of colors to be applied to the corresponding layer + /// The [name] is the symbol name as defined by iOS. You can browse a list of + /// symbols in the SF Symbols app (see below). + /// + /// The [pointSize] is the size of the image in iOS font points. + /// + /// The [colors] variable is a list of colors to be applied to the corresponding layer /// of the icon, assuming that layer exists. An icon can have up to 3 layers, /// if a layer color is not specified it will take the color of the most recent /// valid index. Defaults to an empty list (black). /// /// For more information see [https://developer.apple.com/documentation/uikit/uiimagesymbolconfiguration/3810054-configurationwithpalettecolors?language=objc] /// - /// [preferMulticolor] overrides [colors] and asks iOS to provide its preset - /// multicolor varient of the symbol. Depending on the symbol, these colors + /// If true, [preferMulticolor] overrides [colors] and asks iOS to provide its + /// preset multicolor variant of the symbol. Depending on the symbol, these colors /// *may not be mutable*. To find out, use the SF Symbols app found at - /// [https://developer.apple.com/sf-symbols/] + /// [https://developer.apple.com/sf-symbols/]. /// Also note that regardless of mutability, the symbols default colors are /// affected by the devices theme preference. /// + /// The [weight] is the weight or thickness of the icon. The default is [FontWeight.normal]. + /// /// Multi-layer and multi-color symbols only work on iOS 15.0 and above. - /// **This method requires at least iOS 13.0** + /// **This method requires at least iOS 13.0.** /// /// See [https://developer.apple.com/documentation/uikit/uiimage/configuring_and_displaying_symbol_images_in_your_ui?language=objc] static ImageProvider loadSystemImage( From 7ca9f6ab7462995914a4cbd647154d66959418d6 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Tue, 1 Mar 2022 13:04:38 -0700 Subject: [PATCH 21/64] Error when passed both colors and preferMulticolor --- packages/ios_platform_images/lib/ios_platform_images.dart | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/ios_platform_images/lib/ios_platform_images.dart b/packages/ios_platform_images/lib/ios_platform_images.dart index 88a333d86f05..299e970a5e9a 100644 --- a/packages/ios_platform_images/lib/ios_platform_images.dart +++ b/packages/ios_platform_images/lib/ios_platform_images.dart @@ -173,6 +173,14 @@ class IosPlatformImages { bool preferMulticolor = false, ui.FontWeight weight = FontWeight.normal, }) { + if (preferMulticolor) { + if (colors != const []) { + throw ArgumentError( + 'preferMulticolor and colors cannot be used together.', + ); + } + } + final List colorsRGBA = colors .expand((Color color) => [ color.red.toDouble() / 255, From fd62ca73b7b9304b04c69ecd8fe033f4e871b438 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Wed, 9 Mar 2022 13:14:55 -0700 Subject: [PATCH 22/64] Convert requested size from pixels to points MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There’s a magic number of 85% used here to attempt to shrink the image size to match other Material icons, since Apple adds about 15% padding to the outside of a symbol. For any higher level implementation of this API, the Image should be wrapped in a SizedBox to create exact constraints in the same manner that the Icon class does. It is not reasonable to expect a pixel accurate response from this method as it is merely rendering a font glyph which may not be square. --- .../ios/Classes/IosPlatformImagesPlugin.m | 6 ++++-- packages/ios_platform_images/lib/ios_platform_images.dart | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m b/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m index f426c8580842..2b5c33370e9f 100644 --- a/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m +++ b/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m @@ -43,8 +43,10 @@ + (void)registerWithRegistrar:(NSObject *)registrar { } else if ([@"loadSystemImage" isEqualToString:call.method]) { if (@available(iOS 13, *)) { NSString *name = call.arguments[0]; - NSNumber *pointSizeWithDouble = call.arguments[1]; - double pointSize = [pointSizeWithDouble doubleValue]; + NSNumber *pixelSizeWithDouble = call.arguments[1]; + // iOS adds 15% padding to the outside of the image so we scale down to match the requested + // size. + double pointSize = [pixelSizeWithDouble doubleValue] * 0.85; NSNumber *weightIndex = call.arguments[2]; // Up to 3 rgb values for primary, seconday and tertiary colors. diff --git a/packages/ios_platform_images/lib/ios_platform_images.dart b/packages/ios_platform_images/lib/ios_platform_images.dart index 299e970a5e9a..34062f4129b9 100644 --- a/packages/ios_platform_images/lib/ios_platform_images.dart +++ b/packages/ios_platform_images/lib/ios_platform_images.dart @@ -168,7 +168,7 @@ class IosPlatformImages { /// See [https://developer.apple.com/documentation/uikit/uiimage/configuring_and_displaying_symbol_images_in_your_ui?language=objc] static ImageProvider loadSystemImage( String name, - double pointSize, { + double size, { List colors = const [], bool preferMulticolor = false, ui.FontWeight weight = FontWeight.normal, @@ -195,7 +195,7 @@ class IosPlatformImages { 'loadSystemImage', [ name, - pointSize, + size, weight.index, colorsRGBA, preferMulticolor, From e164d6bfc79294ad7808bec3c1eeacf14c8b8277 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Wed, 9 Mar 2022 14:03:36 -0700 Subject: [PATCH 23/64] Use Object? instead of dynamic for null-safety --- packages/ios_platform_images/lib/ios_platform_images.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/ios_platform_images/lib/ios_platform_images.dart b/packages/ios_platform_images/lib/ios_platform_images.dart index 34062f4129b9..2d00cd80ad06 100644 --- a/packages/ios_platform_images/lib/ios_platform_images.dart +++ b/packages/ios_platform_images/lib/ios_platform_images.dart @@ -190,10 +190,10 @@ class IosPlatformImages { ]) .toList(); - final Future?> loadInfo = - _channel.invokeMapMethod( + final Future?> loadInfo = + _channel.invokeMapMethod( 'loadSystemImage', - [ + [ name, size, weight.index, @@ -203,7 +203,7 @@ class IosPlatformImages { ); final Completer bytesCompleter = Completer(); final Completer scaleCompleter = Completer(); - loadInfo.then((Map? map) { + loadInfo.then((Map? map) { if (map == null) { scaleCompleter.completeError( ArgumentError("System image couldn't be found: $name"), From f9641ec7b1c10914ce4a70eff6f53672a91b3db3 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Tue, 22 Mar 2022 13:53:13 -0700 Subject: [PATCH 24/64] Correct changelog --- packages/ios_platform_images/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ios_platform_images/CHANGELOG.md b/packages/ios_platform_images/CHANGELOG.md index abe462ba791f..101a73de8120 100644 --- a/packages/ios_platform_images/CHANGELOG.md +++ b/packages/ios_platform_images/CHANGELOG.md @@ -10,7 +10,7 @@ ## 0.2.1 -* Added `loadSystemImage` to load system images, also known as 'sfsymbols'. +* Adds `loadSystemImage` to load system images, also known as 'sfsymbols'. ## 0.2.0+9 From 8fbd4bd99efe84de4ab670d3d77ef9cb16e72e68 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Tue, 30 Aug 2022 14:26:01 -0700 Subject: [PATCH 25/64] Remove ios_platform_images text exemption From 2eefe60f36bfda02208c1b21bedb02f29ee7b25e Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Sat, 26 Mar 2022 22:42:40 -0700 Subject: [PATCH 26/64] Tidy up IosPlatformImagesPlugin.m MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mainly formatting, only potential behavior change is that I replaced ‘nil’ with UIColor blackColor when calling imageWithTintColor. --- .../ios/Classes/IosPlatformImagesPlugin.m | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m b/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m index 2b5c33370e9f..cc9a6686dea7 100644 --- a/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m +++ b/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m @@ -43,16 +43,16 @@ + (void)registerWithRegistrar:(NSObject *)registrar { } else if ([@"loadSystemImage" isEqualToString:call.method]) { if (@available(iOS 13, *)) { NSString *name = call.arguments[0]; - NSNumber *pixelSizeWithDouble = call.arguments[1]; + double pixelSize = [(NSNumber *)(call.arguments[1]) doubleValue]; // iOS adds 15% padding to the outside of the image so we scale down to match the requested // size. - double pointSize = [pixelSizeWithDouble doubleValue] * 0.85; + double pointSize = pixelSize * 0.85; NSNumber *weightIndex = call.arguments[2]; // Up to 3 rgb values for primary, seconday and tertiary colors. // see // https://developer.apple.com/documentation/uikit/uiimagesymbolconfiguration/3810054-configurationwithpalettecolors - NSArray *rgbaValuesList = call.arguments[3]; + NSArray *rgbaValuesList = call.arguments[3]; NSMutableArray *colorArray = [[NSMutableArray alloc] init]; @@ -76,7 +76,6 @@ + (void)registerWithRegistrar:(NSObject *)registrar { case 2: weight = UIImageSymbolWeightLight; break; - // 3 is regular case 4: weight = UIImageSymbolWeightMedium; break; @@ -92,6 +91,7 @@ + (void)registerWithRegistrar:(NSObject *)registrar { case 8: weight = UIImageSymbolWeightBlack; break; + case 3: default: weight = UIImageSymbolWeightRegular; break; @@ -106,20 +106,18 @@ + (void)registerWithRegistrar:(NSObject *)registrar { if (@available(iOS 15, *)) { NSNumber *preferMulticolor = call.arguments[4]; - UIImageSymbolConfiguration *colors; - - if ([preferMulticolor boolValue]) { - colors = [UIImageSymbolConfiguration configurationPreferringMulticolor]; - } else { - colors = [UIImageSymbolConfiguration configurationWithPaletteColors:colorArray]; - } + UIImageSymbolConfiguration *colors = + [preferMulticolor boolValue] + ? [UIImageSymbolConfiguration configurationPreferringMulticolor] + : [UIImageSymbolConfiguration configurationWithPaletteColors:colorArray]; UIImageSymbolConfiguration *final = [pointSizeConfig configurationByApplyingConfiguration:colors]; finalImage = [UIImage systemImageNamed:name withConfiguration:final]; } else { UIImage *image = [UIImage systemImageNamed:name withConfiguration:pointSizeConfig]; - finalImage = [image imageWithTintColor:colorArray.count > 0 ? colorArray[0] : nil]; + finalImage = [image + imageWithTintColor:colorArray.count > 0 ? colorArray[0] : [UIColor blackColor]]; } NSData *data = UIImagePNGRepresentation(finalImage); From fde300e8d5cb49fefa1ee6b905d9fcada5931cc3 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Tue, 30 Aug 2022 14:26:11 -0700 Subject: [PATCH 27/64] Add missing newline in exclude_integration_ios From 4e207c0922d5abdc157e5cad13489c0356c153e4 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Sat, 26 Mar 2022 22:55:06 -0700 Subject: [PATCH 28/64] Simplify pointSize variable definition --- .../ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m b/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m index cc9a6686dea7..5b68c54bf9b2 100644 --- a/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m +++ b/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m @@ -43,10 +43,9 @@ + (void)registerWithRegistrar:(NSObject *)registrar { } else if ([@"loadSystemImage" isEqualToString:call.method]) { if (@available(iOS 13, *)) { NSString *name = call.arguments[0]; - double pixelSize = [(NSNumber *)(call.arguments[1]) doubleValue]; // iOS adds 15% padding to the outside of the image so we scale down to match the requested // size. - double pointSize = pixelSize * 0.85; + double pointSize = [(NSNumber *)(call.arguments[1]) doubleValue] * 0.85; NSNumber *weightIndex = call.arguments[2]; // Up to 3 rgb values for primary, seconday and tertiary colors. From b1531fc069a4105187cc577831836ff59ca272a5 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Mon, 28 Mar 2022 00:52:14 -0700 Subject: [PATCH 29/64] Correct array type --- .../ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m b/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m index 5b68c54bf9b2..fdd60acb9124 100644 --- a/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m +++ b/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m @@ -51,7 +51,7 @@ + (void)registerWithRegistrar:(NSObject *)registrar { // Up to 3 rgb values for primary, seconday and tertiary colors. // see // https://developer.apple.com/documentation/uikit/uiimagesymbolconfiguration/3810054-configurationwithpalettecolors - NSArray *rgbaValuesList = call.arguments[3]; + NSArray *rgbaValuesList = call.arguments[3]; NSMutableArray *colorArray = [[NSMutableArray alloc] init]; From 22ea52922a14c82c9f0d36e738fcd9cabc88fcb8 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Mon, 28 Mar 2022 00:52:53 -0700 Subject: [PATCH 30/64] Fix error case test --- .../example/integration_test/ios_platform_images.dart | 7 +++++-- packages/ios_platform_images/example/lib/main.dart | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/ios_platform_images/example/integration_test/ios_platform_images.dart b/packages/ios_platform_images/example/integration_test/ios_platform_images.dart index fb0b5ae53866..fe0698d59186 100644 --- a/packages/ios_platform_images/example/integration_test/ios_platform_images.dart +++ b/packages/ios_platform_images/example/integration_test/ios_platform_images.dart @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'dart:ui'; + import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; @@ -35,9 +37,10 @@ void main() { testWidgets( 'ios system image error case', (WidgetTester tester) async { - await tester.pumpWidget(app.IOSImageExampleError()); + app.IOSImageErrorExample(); + await tester.pumpAndSettle(); - expect(find.bySemanticsLabel('Nonexistant Symbol'), findsNothing); + expect(find.byType(Image), findsNothing); }, ); } diff --git a/packages/ios_platform_images/example/lib/main.dart b/packages/ios_platform_images/example/lib/main.dart index 6efa47e3ec17..3bc325227732 100644 --- a/packages/ios_platform_images/example/lib/main.dart +++ b/packages/ios_platform_images/example/lib/main.dart @@ -79,7 +79,7 @@ class _MyAppState extends State { } /// Example app containing an invalid symbol reference. -class IOSImageExampleError extends StatelessWidget { +class IOSImageErrorExample extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( From 4f1f0f681e83a5db330617a4e0d530d9cd786108 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Mon, 3 Oct 2022 02:09:28 -0700 Subject: [PATCH 31/64] Add test_driver --- .../example/test_driver/integration_test.dart | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 packages/ios_platform_images/example/test_driver/integration_test.dart diff --git a/packages/ios_platform_images/example/test_driver/integration_test.dart b/packages/ios_platform_images/example/test_driver/integration_test.dart new file mode 100644 index 000000000000..4f10f2a522f3 --- /dev/null +++ b/packages/ios_platform_images/example/test_driver/integration_test.dart @@ -0,0 +1,7 @@ +// Copyright 2013 The Flutter 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:integration_test/integration_test_driver.dart'; + +Future main() => integrationDriver(); From adbef2a6637c7b61df751aeea2ac055acac97213 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Thu, 12 May 2022 03:19:22 -0600 Subject: [PATCH 32/64] Xcode updates --- .../ios/Flutter/AppFrameworkInfo.plist | 2 +- .../ios_platform_images/example/ios/Podfile | 2 +- .../ios/Runner.xcodeproj/project.pbxproj | 45 ++++++++++++++----- .../xcshareddata/xcschemes/Runner.xcscheme | 2 +- .../example/ios/Runner/Info.plist | 2 + 5 files changed, 39 insertions(+), 14 deletions(-) diff --git a/packages/ios_platform_images/example/ios/Flutter/AppFrameworkInfo.plist b/packages/ios_platform_images/example/ios/Flutter/AppFrameworkInfo.plist index f2872cf474ee..4f8d4d2456f3 100644 --- a/packages/ios_platform_images/example/ios/Flutter/AppFrameworkInfo.plist +++ b/packages/ios_platform_images/example/ios/Flutter/AppFrameworkInfo.plist @@ -21,6 +21,6 @@ CFBundleVersion 1.0 MinimumOSVersion - 9.0 + 11.0 diff --git a/packages/ios_platform_images/example/ios/Podfile b/packages/ios_platform_images/example/ios/Podfile index 397864535f5d..fdcc671eb341 100644 --- a/packages/ios_platform_images/example/ios/Podfile +++ b/packages/ios_platform_images/example/ios/Podfile @@ -1,5 +1,5 @@ # Uncomment this line to define a global platform for your project -# platform :ios, '9.0' +# platform :ios, '11.0' # CocoaPods analytics sends network stats synchronously affecting flutter build latency. ENV['COCOAPODS_DISABLE_STATS'] = 'true' diff --git a/packages/ios_platform_images/example/ios/Runner.xcodeproj/project.pbxproj b/packages/ios_platform_images/example/ios/Runner.xcodeproj/project.pbxproj index 02e41bc13711..f217bcd92656 100644 --- a/packages/ios_platform_images/example/ios/Runner.xcodeproj/project.pbxproj +++ b/packages/ios_platform_images/example/ios/Runner.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 50; objects = { /* Begin PBXBuildFile section */ @@ -219,7 +219,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1020; + LastUpgradeCheck = 1300; ORGANIZATIONNAME = "The Flutter Authors"; TargetAttributes = { 97C146ED1CF9000F007C117D = { @@ -297,10 +297,12 @@ ); inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/integration_test/integration_test.framework", "${BUILT_PRODUCTS_DIR}/ios_platform_images/ios_platform_images.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/integration_test.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ios_platform_images.framework", ); runOnlyForDeploymentPostprocessing = 0; @@ -457,7 +459,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; @@ -479,7 +481,10 @@ "$(PROJECT_DIR)/Flutter", ); INFOPLIST_FILE = Runner/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); LIBRARY_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/Flutter", @@ -539,7 +544,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -588,7 +593,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; @@ -611,7 +616,10 @@ "$(PROJECT_DIR)/Flutter", ); INFOPLIST_FILE = Runner/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); LIBRARY_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/Flutter", @@ -638,7 +646,10 @@ "$(PROJECT_DIR)/Flutter", ); INFOPLIST_FILE = Runner/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); LIBRARY_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/Flutter", @@ -659,7 +670,11 @@ CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = S8QB4VV633; INFOPLIST_FILE = RunnerTests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_BUNDLE_IDENTIFIER = dev.flutter.plugins.RunnerTests; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/Runner"; @@ -674,7 +689,11 @@ CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = S8QB4VV633; INFOPLIST_FILE = RunnerTests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_BUNDLE_IDENTIFIER = dev.flutter.plugins.RunnerTests; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/Runner"; @@ -689,7 +708,11 @@ CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = S8QB4VV633; INFOPLIST_FILE = RunnerTests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_BUNDLE_IDENTIFIER = dev.flutter.plugins.RunnerTests; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/Runner"; diff --git a/packages/ios_platform_images/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/packages/ios_platform_images/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index 6de5fabfee04..7ae2cb4d4e54 100644 --- a/packages/ios_platform_images/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/packages/ios_platform_images/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ UIViewControllerBasedStatusBarAppearance + CADisableMinimumFrameDurationOnPhone + From ff45b5bfab9d796f8d317f669fb82f9b7063a14a Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Mon, 30 May 2022 19:47:01 -0600 Subject: [PATCH 33/64] Rename integration test file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DartCode seems to only notice files with ‘test’ in their name. --- ...ios_platform_images_integration_test.dart} | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) rename packages/ios_platform_images/example/integration_test/{ios_platform_images.dart => ios_platform_images_integration_test.dart} (51%) diff --git a/packages/ios_platform_images/example/integration_test/ios_platform_images.dart b/packages/ios_platform_images/example/integration_test/ios_platform_images_integration_test.dart similarity index 51% rename from packages/ios_platform_images/example/integration_test/ios_platform_images.dart rename to packages/ios_platform_images/example/integration_test/ios_platform_images_integration_test.dart index fe0698d59186..ec23419fa6ca 100644 --- a/packages/ios_platform_images/example/integration_test/ios_platform_images.dart +++ b/packages/ios_platform_images/example/integration_test/ios_platform_images_integration_test.dart @@ -2,10 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:ui'; +import 'dart:async'; +import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; +import 'package:ios_platform_images/ios_platform_images.dart'; import 'package:ios_platform_images_example/main.dart' as app; @@ -34,13 +36,30 @@ void main() { }, ); - testWidgets( + test( 'ios system image error case', - (WidgetTester tester) async { - app.IOSImageErrorExample(); - await tester.pumpAndSettle(); + () async { + final Completer _completer = Completer(); + + final ImageProvider imageProvider = + IosPlatformImages.loadSystemImage('invalid_symbol', 10); + + final Function errorCallback = expectAsync1((Object exception) async { + expect(exception, isArgumentError); + }, count: 2); + + // await expectLater( imageProvider.obtainKey(ImageConfiguration.empty), + // throwsArgumentError); + + imageProvider.resolve(ImageConfiguration.empty).completer?.addListener( + ImageStreamListener( + (ImageInfo info, bool _) => _completer.complete(info), + onError: (Object exception, StackTrace? _) => + errorCallback.call(), + ), + ); - expect(find.byType(Image), findsNothing); + // await expectLater(_completer.future, throwsArgumentError); }, ); } From 17d6cf05c4e95b1ea4d1e6ba89eb0def6fe5a7f7 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Mon, 30 May 2022 20:41:26 -0600 Subject: [PATCH 34/64] Change test strategy to completer --- .../ios_platform_images_integration_test.dart | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/packages/ios_platform_images/example/integration_test/ios_platform_images_integration_test.dart b/packages/ios_platform_images/example/integration_test/ios_platform_images_integration_test.dart index ec23419fa6ca..db64b9fa85c1 100644 --- a/packages/ios_platform_images/example/integration_test/ios_platform_images_integration_test.dart +++ b/packages/ios_platform_images/example/integration_test/ios_platform_images_integration_test.dart @@ -44,22 +44,15 @@ void main() { final ImageProvider imageProvider = IosPlatformImages.loadSystemImage('invalid_symbol', 10); - final Function errorCallback = expectAsync1((Object exception) async { - expect(exception, isArgumentError); - }, count: 2); - - // await expectLater( imageProvider.obtainKey(ImageConfiguration.empty), - // throwsArgumentError); - imageProvider.resolve(ImageConfiguration.empty).completer?.addListener( ImageStreamListener( (ImageInfo info, bool _) => _completer.complete(info), onError: (Object exception, StackTrace? _) => - errorCallback.call(), + _completer.completeError(exception), ), ); - // await expectLater(_completer.future, throwsArgumentError); + await expectLater(_completer.future, throwsArgumentError); }, ); } From db91e29feeaaa5d664968c154c2213d347c8673d Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Tue, 31 May 2022 14:48:32 -0600 Subject: [PATCH 35/64] Delete unused error example --- .../ios_platform_images/example/lib/main.dart | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/packages/ios_platform_images/example/lib/main.dart b/packages/ios_platform_images/example/lib/main.dart index 3bc325227732..b0839f895836 100644 --- a/packages/ios_platform_images/example/lib/main.dart +++ b/packages/ios_platform_images/example/lib/main.dart @@ -77,18 +77,3 @@ class _MyAppState extends State { ); } } - -/// Example app containing an invalid symbol reference. -class IOSImageErrorExample extends StatelessWidget { - @override - Widget build(BuildContext context) { - return MaterialApp( - home: Scaffold( - body: Image( - image: IosPlatformImages.loadSystemImage('nonexistent.sfsymbol', 100), - semanticLabel: 'Nonexistant Symbol', - ), - ), - ); - } -} From b6f3feb33730d79f1293b1b234d20ebe9cc5d7ae Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Fri, 19 Aug 2022 09:22:46 -0700 Subject: [PATCH 36/64] Working pigeon implementation --- .../ios_platform_images_integration_test.dart | 9 +- ...agesPlugin.h => FLTPlatformImagesPlugin.h} | 4 +- .../ios/Classes/FLTPlatformImagesPlugin.m | 89 +++++++++ .../ios/Classes/IosPlatformImagesPlugin.m | 138 ------------- .../ios/Classes/PlatformImagesApi.g.h | 48 +++++ .../ios/Classes/PlatformImagesApi.g.m | 185 ++++++++++++++++++ .../lib/ios_platform_images.dart | 67 +++---- .../lib/platform_images_api.g.dart | 160 +++++++++++++++ .../ios_platform_images/pigeons/copyright.txt | 3 + .../pigeons/platform_images.dart | 35 ++++ packages/ios_platform_images/pubspec.yaml | 5 +- 11 files changed, 556 insertions(+), 187 deletions(-) rename packages/ios_platform_images/ios/Classes/{IosPlatformImagesPlugin.h => FLTPlatformImagesPlugin.h} (55%) create mode 100644 packages/ios_platform_images/ios/Classes/FLTPlatformImagesPlugin.m delete mode 100644 packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m create mode 100644 packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h create mode 100644 packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m create mode 100644 packages/ios_platform_images/lib/platform_images_api.g.dart create mode 100644 packages/ios_platform_images/pigeons/copyright.txt create mode 100644 packages/ios_platform_images/pigeons/platform_images.dart diff --git a/packages/ios_platform_images/example/integration_test/ios_platform_images_integration_test.dart b/packages/ios_platform_images/example/integration_test/ios_platform_images_integration_test.dart index db64b9fa85c1..c07f2d3ea68e 100644 --- a/packages/ios_platform_images/example/integration_test/ios_platform_images_integration_test.dart +++ b/packages/ios_platform_images/example/integration_test/ios_platform_images_integration_test.dart @@ -36,9 +36,9 @@ void main() { }, ); - test( + testWidgets( 'ios system image error case', - () async { + (WidgetTester tester) async { final Completer _completer = Completer(); final ImageProvider imageProvider = @@ -47,8 +47,9 @@ void main() { imageProvider.resolve(ImageConfiguration.empty).completer?.addListener( ImageStreamListener( (ImageInfo info, bool _) => _completer.complete(info), - onError: (Object exception, StackTrace? _) => - _completer.completeError(exception), + onError: (Object exception, StackTrace? stack) => () { + _completer.completeError(exception); + }, ), ); diff --git a/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.h b/packages/ios_platform_images/ios/Classes/FLTPlatformImagesPlugin.h similarity index 55% rename from packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.h rename to packages/ios_platform_images/ios/Classes/FLTPlatformImagesPlugin.h index f3c8efe9bd6a..3e06fa7ae6f6 100644 --- a/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.h +++ b/packages/ios_platform_images/ios/Classes/FLTPlatformImagesPlugin.h @@ -4,7 +4,5 @@ #import -/// A plugin for Flutter that allows Flutter to load images in a platform -/// specific way on iOS. -@interface IosPlatformImagesPlugin : NSObject +@interface FLTPlatformImagesPlugin : NSObject @end diff --git a/packages/ios_platform_images/ios/Classes/FLTPlatformImagesPlugin.m b/packages/ios_platform_images/ios/Classes/FLTPlatformImagesPlugin.m new file mode 100644 index 000000000000..01034020cc3a --- /dev/null +++ b/packages/ios_platform_images/ios/Classes/FLTPlatformImagesPlugin.m @@ -0,0 +1,89 @@ +#import "FLTPlatformImagesPlugin.h" +#import "PlatformImagesApi.g.h" + +@implementation FLTPlatformImagesPlugin + ++ (void)registerWithRegistrar:(NSObject *)registrar { + FLTPlatformImagesPlugin *instance = [[FLTPlatformImagesPlugin alloc] init]; + [registrar publish:instance]; + FLTPlatformImagesApiSetup(registrar.messenger, instance); +} + +- (nullable FLTPlatformImage *)getSystemImageName:(NSString *)name size:(NSNumber *)size weight:(FLTFontWeight)weight colorsRGBA:(NSArray *)colorsRGBA preferMulticolor:(NSNumber *)preferMulticolor error:(FlutterError *_Nullable *_Nonnull)error { + if (@available(iOS 13, *)) { + // iOS adds ~15% padding to the outside of the image so we scale down to match the requested + // size. + double pointSize = [size doubleValue] * 0.85; + + // Up to 3 rgb values for primary, seconday and tertiary colors. + // see + // https://developer.apple.com/documentation/uikit/uiimagesymbolconfiguration/3810054-configurationwithpalettecolors + + NSMutableArray *colorArray = [[NSMutableArray alloc] init]; + + for (int i = 0; i < [colorsRGBA count]; i += 4) { + UIColor *primaryColor = [UIColor colorWithRed:[colorsRGBA[i] doubleValue] + green:[colorsRGBA[i + 1] doubleValue] + blue:[colorsRGBA[i + 2] doubleValue] + alpha:[colorsRGBA[i + 3] doubleValue]]; + [colorArray addObject:primaryColor]; + } + + UIImageSymbolWeight uiWeight = [ self weightFromFLTFontWeight: weight ]; + + UIImageSymbolConfiguration *pointSizeConfig = + [UIImageSymbolConfiguration configurationWithPointSize:pointSize + weight:uiWeight + scale:UIImageSymbolScaleDefault]; + + UIImage *finalImage; + + if (@available(iOS 15, *)) { + UIImageSymbolConfiguration *colors = + [preferMulticolor boolValue] + ? [UIImageSymbolConfiguration configurationPreferringMulticolor] + : [UIImageSymbolConfiguration configurationWithPaletteColors:colorArray]; + + UIImageSymbolConfiguration *final = + [pointSizeConfig configurationByApplyingConfiguration:colors]; + finalImage = [UIImage systemImageNamed:name withConfiguration:final]; + } else { + UIImage *image = [UIImage systemImageNamed:name withConfiguration:pointSizeConfig]; + finalImage = [image + imageWithTintColor:colorArray.count > 0 ? colorArray[0] : [UIColor blackColor]]; + } + + NSData *data = UIImagePNGRepresentation(finalImage); + return [ FLTPlatformImage makeWithScale:@(finalImage.scale) bytes:data ]; + } + return nil; +} + +- (nullable FLTPlatformImage *)getPlatformImageName:(NSString *)name error:(FlutterError *_Nullable *_Nonnull)error { + UIImage *image = [UIImage imageNamed:name]; + NSData *data = UIImagePNGRepresentation(image); + + return [ FLTPlatformImage makeWithScale:@(image.scale) bytes:data ]; +} + +- (nullable NSString *)resolveURLName:(NSString *)name extension:(nullable NSString *)extension error:(FlutterError *_Nullable *_Nonnull)error { + NSURL *url = [[NSBundle mainBundle] URLForResource:name withExtension:extension]; + return url.absoluteString; +} + + +- (UIImageSymbolWeight) weightFromFLTFontWeight:(FLTFontWeight) flutterFontWeight API_AVAILABLE(ios(13)) { + switch (flutterFontWeight) { + case FLTFontWeightUltraLight: return UIImageSymbolWeightUltraLight; + case FLTFontWeightThin: return UIImageSymbolWeightThin; + case FLTFontWeightLight: return UIImageSymbolWeightLight; + case FLTFontWeightRegular: return UIImageSymbolWeightRegular; + case FLTFontWeightMedium: return UIImageSymbolWeightMedium; + case FLTFontWeightSemibold: return UIImageSymbolWeightSemibold; + case FLTFontWeightBold: return UIImageSymbolWeightBold; + case FLTFontWeightHeavy: return UIImageSymbolWeightHeavy; + case FLTFontWeightBlack: return UIImageSymbolWeightBlack; + } +} + +@end diff --git a/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m b/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m deleted file mode 100644 index fdd60acb9124..000000000000 --- a/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m +++ /dev/null @@ -1,138 +0,0 @@ -// Copyright 2013 The Flutter 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 "IosPlatformImagesPlugin.h" - -#if !__has_feature(objc_arc) -#error ARC must be enabled! -#endif - -@interface IosPlatformImagesPlugin () -@end - -@implementation IosPlatformImagesPlugin - -+ (void)registerWithRegistrar:(NSObject *)registrar { - FlutterMethodChannel *channel = - [FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/ios_platform_images" - binaryMessenger:[registrar messenger]]; - - [channel setMethodCallHandler:^(FlutterMethodCall *call, FlutterResult result) { - if ([@"loadImage" isEqualToString:call.method]) { - NSString *name = call.arguments; - UIImage *image = [UIImage imageNamed:name]; - NSData *data = UIImagePNGRepresentation(image); - if (data) { - result(@{ - @"scale" : @(image.scale), - @"data" : [FlutterStandardTypedData typedDataWithBytes:data], - }); - } else { - result(nil); - } - return; - } else if ([@"resolveURL" isEqualToString:call.method]) { - NSArray *args = call.arguments; - NSString *name = args[0]; - NSString *extension = (args[1] == (id)NSNull.null) ? nil : args[1]; - - NSURL *url = [[NSBundle mainBundle] URLForResource:name withExtension:extension]; - result(url.absoluteString); - return; - } else if ([@"loadSystemImage" isEqualToString:call.method]) { - if (@available(iOS 13, *)) { - NSString *name = call.arguments[0]; - // iOS adds 15% padding to the outside of the image so we scale down to match the requested - // size. - double pointSize = [(NSNumber *)(call.arguments[1]) doubleValue] * 0.85; - NSNumber *weightIndex = call.arguments[2]; - - // Up to 3 rgb values for primary, seconday and tertiary colors. - // see - // https://developer.apple.com/documentation/uikit/uiimagesymbolconfiguration/3810054-configurationwithpalettecolors - NSArray *rgbaValuesList = call.arguments[3]; - - NSMutableArray *colorArray = [[NSMutableArray alloc] init]; - - for (int i = 0; i < [rgbaValuesList count]; i += 4) { - UIColor *primaryColor = [UIColor colorWithRed:[rgbaValuesList[i] doubleValue] - green:[rgbaValuesList[i + 1] doubleValue] - blue:[rgbaValuesList[i + 2] doubleValue] - alpha:[rgbaValuesList[i + 3] doubleValue]]; - [colorArray addObject:primaryColor]; - } - - UIImageSymbolWeight weight = UIImageSymbolWeightRegular; - - switch ([weightIndex integerValue]) { - case 0: - weight = UIImageSymbolWeightUltraLight; - break; - case 1: - weight = UIImageSymbolWeightThin; - break; - case 2: - weight = UIImageSymbolWeightLight; - break; - case 4: - weight = UIImageSymbolWeightMedium; - break; - case 5: - weight = UIImageSymbolWeightSemibold; - break; - case 6: - weight = UIImageSymbolWeightBold; - break; - case 7: - weight = UIImageSymbolWeightHeavy; - break; - case 8: - weight = UIImageSymbolWeightBlack; - break; - case 3: - default: - weight = UIImageSymbolWeightRegular; - break; - } - - UIImageSymbolConfiguration *pointSizeConfig = - [UIImageSymbolConfiguration configurationWithPointSize:pointSize - weight:weight - scale:UIImageSymbolScaleDefault]; - - UIImage *finalImage; - - if (@available(iOS 15, *)) { - NSNumber *preferMulticolor = call.arguments[4]; - UIImageSymbolConfiguration *colors = - [preferMulticolor boolValue] - ? [UIImageSymbolConfiguration configurationPreferringMulticolor] - : [UIImageSymbolConfiguration configurationWithPaletteColors:colorArray]; - - UIImageSymbolConfiguration *final = - [pointSizeConfig configurationByApplyingConfiguration:colors]; - finalImage = [UIImage systemImageNamed:name withConfiguration:final]; - } else { - UIImage *image = [UIImage systemImageNamed:name withConfiguration:pointSizeConfig]; - finalImage = [image - imageWithTintColor:colorArray.count > 0 ? colorArray[0] : [UIColor blackColor]]; - } - - NSData *data = UIImagePNGRepresentation(finalImage); - if (data) { - result(@{ - @"scale" : @(finalImage.scale), - @"data" : [FlutterStandardTypedData typedDataWithBytes:data], - }); - } else { - result(nil); - } - return; - } - } - result(FlutterMethodNotImplemented); - }]; -} - -@end diff --git a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h new file mode 100644 index 000000000000..8d97b6d328c3 --- /dev/null +++ b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h @@ -0,0 +1,48 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// Autogenerated from Pigeon (v3.2.3), do not edit directly. +// See also: https://pub.dev/packages/pigeon +#import +@protocol FlutterBinaryMessenger; +@protocol FlutterMessageCodec; +@class FlutterError; +@class FlutterStandardTypedData; + +NS_ASSUME_NONNULL_BEGIN + +typedef NS_ENUM(NSUInteger, FLTFontWeight) { + FLTFontWeightUltraLight = 0, + FLTFontWeightThin = 1, + FLTFontWeightLight = 2, + FLTFontWeightRegular = 3, + FLTFontWeightMedium = 4, + FLTFontWeightSemibold = 5, + FLTFontWeightBold = 6, + FLTFontWeightHeavy = 7, + FLTFontWeightBlack = 8, +}; + +@class FLTPlatformImage; + +@interface FLTPlatformImage : NSObject ++ (instancetype)makeWithScale:(nullable NSNumber *)scale + bytes:(nullable FlutterStandardTypedData *)bytes; +@property(nonatomic, strong, nullable) NSNumber * scale; +@property(nonatomic, strong, nullable) FlutterStandardTypedData * bytes; +@end + +/// The codec used by FLTPlatformImagesApi. +NSObject *FLTPlatformImagesApiGetCodec(void); + +@protocol FLTPlatformImagesApi +/// @return `nil` only when `error != nil`. +- (nullable FLTPlatformImage *)getSystemImageName:(NSString *)name size:(NSNumber *)size weight:(FLTFontWeight)weight colorsRGBA:(NSArray *)colorsRGBA preferMulticolor:(NSNumber *)preferMulticolor error:(FlutterError *_Nullable *_Nonnull)error; +/// @return `nil` only when `error != nil`. +- (nullable FLTPlatformImage *)getPlatformImageName:(NSString *)name error:(FlutterError *_Nullable *_Nonnull)error; +- (nullable NSString *)resolveURLName:(NSString *)name extension:(nullable NSString *)extension error:(FlutterError *_Nullable *_Nonnull)error; +@end + +extern void FLTPlatformImagesApiSetup(id binaryMessenger, NSObject *_Nullable api); + +NS_ASSUME_NONNULL_END diff --git a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m new file mode 100644 index 000000000000..34e357872255 --- /dev/null +++ b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m @@ -0,0 +1,185 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// Autogenerated from Pigeon (v3.2.3), do not edit directly. +// See also: https://pub.dev/packages/pigeon +#import "PlatformImagesApi.g.h" +#import + +#if !__has_feature(objc_arc) +#error File requires ARC to be enabled. +#endif + +static NSDictionary *wrapResult(id result, FlutterError *error) { + NSDictionary *errorDict = (NSDictionary *)[NSNull null]; + if (error) { + errorDict = @{ + @"code": (error.code ?: [NSNull null]), + @"message": (error.message ?: [NSNull null]), + @"details": (error.details ?: [NSNull null]), + }; + } + return @{ + @"result": (result ?: [NSNull null]), + @"error": errorDict, + }; +} +static id GetNullableObject(NSDictionary* dict, id key) { + id result = dict[key]; + return (result == [NSNull null]) ? nil : result; +} +static id GetNullableObjectAtIndex(NSArray* array, NSInteger key) { + id result = array[key]; + return (result == [NSNull null]) ? nil : result; +} + + +@interface FLTPlatformImage () ++ (FLTPlatformImage *)fromMap:(NSDictionary *)dict; ++ (nullable FLTPlatformImage *)nullableFromMap:(NSDictionary *)dict; +- (NSDictionary *)toMap; +@end + +@implementation FLTPlatformImage ++ (instancetype)makeWithScale:(nullable NSNumber *)scale + bytes:(nullable FlutterStandardTypedData *)bytes { + FLTPlatformImage* pigeonResult = [[FLTPlatformImage alloc] init]; + pigeonResult.scale = scale; + pigeonResult.bytes = bytes; + return pigeonResult; +} ++ (FLTPlatformImage *)fromMap:(NSDictionary *)dict { + FLTPlatformImage *pigeonResult = [[FLTPlatformImage alloc] init]; + pigeonResult.scale = GetNullableObject(dict, @"scale"); + pigeonResult.bytes = GetNullableObject(dict, @"bytes"); + return pigeonResult; +} ++ (nullable FLTPlatformImage *)nullableFromMap:(NSDictionary *)dict { return (dict) ? [FLTPlatformImage fromMap:dict] : nil; } +- (NSDictionary *)toMap { + return @{ + @"scale" : (self.scale ?: [NSNull null]), + @"bytes" : (self.bytes ?: [NSNull null]), + }; +} +@end + +@interface FLTPlatformImagesApiCodecReader : FlutterStandardReader +@end +@implementation FLTPlatformImagesApiCodecReader +- (nullable id)readValueOfType:(UInt8)type +{ + switch (type) { + case 128: + return [FLTPlatformImage fromMap:[self readValue]]; + + default: + return [super readValueOfType:type]; + + } +} +@end + +@interface FLTPlatformImagesApiCodecWriter : FlutterStandardWriter +@end +@implementation FLTPlatformImagesApiCodecWriter +- (void)writeValue:(id)value +{ + if ([value isKindOfClass:[FLTPlatformImage class]]) { + [self writeByte:128]; + [self writeValue:[value toMap]]; + } else +{ + [super writeValue:value]; + } +} +@end + +@interface FLTPlatformImagesApiCodecReaderWriter : FlutterStandardReaderWriter +@end +@implementation FLTPlatformImagesApiCodecReaderWriter +- (FlutterStandardWriter *)writerWithData:(NSMutableData *)data { + return [[FLTPlatformImagesApiCodecWriter alloc] initWithData:data]; +} +- (FlutterStandardReader *)readerWithData:(NSData *)data { + return [[FLTPlatformImagesApiCodecReader alloc] initWithData:data]; +} +@end + +NSObject *FLTPlatformImagesApiGetCodec() { + static dispatch_once_t sPred = 0; + static FlutterStandardMessageCodec *sSharedObject = nil; + dispatch_once(&sPred, ^{ + FLTPlatformImagesApiCodecReaderWriter *readerWriter = [[FLTPlatformImagesApiCodecReaderWriter alloc] init]; + sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; + }); + return sSharedObject; +} + + +void FLTPlatformImagesApiSetup(id binaryMessenger, NSObject *api) { + { + FlutterBasicMessageChannel *channel = + [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.PlatformImagesApi.getSystemImage" + binaryMessenger:binaryMessenger + codec:FLTPlatformImagesApiGetCodec() ]; + if (api) { + NSCAssert([api respondsToSelector:@selector(getSystemImageName:size:weight:colorsRGBA:preferMulticolor:error:)], @"FLTPlatformImagesApi api (%@) doesn't respond to @selector(getSystemImageName:size:weight:colorsRGBA:preferMulticolor:error:)", api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + NSString *arg_name = GetNullableObjectAtIndex(args, 0); + NSNumber *arg_size = GetNullableObjectAtIndex(args, 1); + FLTFontWeight arg_weight = [GetNullableObjectAtIndex(args, 2) integerValue]; + NSArray *arg_colorsRGBA = GetNullableObjectAtIndex(args, 3); + NSNumber *arg_preferMulticolor = GetNullableObjectAtIndex(args, 4); + FlutterError *error; + FLTPlatformImage *output = [api getSystemImageName:arg_name size:arg_size weight:arg_weight colorsRGBA:arg_colorsRGBA preferMulticolor:arg_preferMulticolor error:&error]; + callback(wrapResult(output, error)); + }]; + } + else { + [channel setMessageHandler:nil]; + } + } + { + FlutterBasicMessageChannel *channel = + [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.PlatformImagesApi.getPlatformImage" + binaryMessenger:binaryMessenger + codec:FLTPlatformImagesApiGetCodec() ]; + if (api) { + NSCAssert([api respondsToSelector:@selector(getPlatformImageName:error:)], @"FLTPlatformImagesApi api (%@) doesn't respond to @selector(getPlatformImageName:error:)", api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + NSString *arg_name = GetNullableObjectAtIndex(args, 0); + FlutterError *error; + FLTPlatformImage *output = [api getPlatformImageName:arg_name error:&error]; + callback(wrapResult(output, error)); + }]; + } + else { + [channel setMessageHandler:nil]; + } + } + { + FlutterBasicMessageChannel *channel = + [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.PlatformImagesApi.resolveURL" + binaryMessenger:binaryMessenger + codec:FLTPlatformImagesApiGetCodec() ]; + if (api) { + NSCAssert([api respondsToSelector:@selector(resolveURLName:extension:error:)], @"FLTPlatformImagesApi api (%@) doesn't respond to @selector(resolveURLName:extension:error:)", api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + NSString *arg_name = GetNullableObjectAtIndex(args, 0); + NSString *arg_extension = GetNullableObjectAtIndex(args, 1); + FlutterError *error; + NSString *output = [api resolveURLName:arg_name extension:arg_extension error:&error]; + callback(wrapResult(output, error)); + }]; + } + else { + [channel setMessageHandler:nil]; + } + } +} diff --git a/packages/ios_platform_images/lib/ios_platform_images.dart b/packages/ios_platform_images/lib/ios_platform_images.dart index 2d00cd80ad06..e34362a90c02 100644 --- a/packages/ios_platform_images/lib/ios_platform_images.dart +++ b/packages/ios_platform_images/lib/ios_platform_images.dart @@ -8,7 +8,8 @@ import 'dart:ui' as ui; import 'package:flutter/foundation.dart' show SynchronousFuture, describeIdentity, immutable, objectRuntimeType; import 'package:flutter/rendering.dart'; -import 'package:flutter/services.dart'; + +import 'package:ios_platform_images/platform_images_api.g.dart'; class _FutureImageStreamCompleter extends ImageStreamCompleter { _FutureImageStreamCompleter({ @@ -106,8 +107,10 @@ class _FutureMemoryImage extends ImageProvider<_FutureMemoryImage> { /// /// For example, loading an image that is in `Assets.xcassts`. class IosPlatformImages { - static const MethodChannel _channel = - MethodChannel('plugins.flutter.io/ios_platform_images'); + static final PlatformImagesApi _api = PlatformImagesApi(); + + /// Empty registerWith method. + static void registerWith() {} /// Loads an image from asset catalogs. The equivalent would be: /// `[UIImage imageNamed:name]`. @@ -116,24 +119,8 @@ class IosPlatformImages { /// /// See [https://developer.apple.com/documentation/uikit/uiimage/1624146-imagenamed?language=objc] static ImageProvider load(String name) { - final Future?> loadInfo = - _channel.invokeMapMethod('loadImage', name); - final Completer bytesCompleter = Completer(); - final Completer scaleCompleter = Completer(); - loadInfo.then((Map? 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']! as double); - bytesCompleter.complete(map['data']! as Uint8List); - }); - return _FutureMemoryImage(bytesCompleter.future, scaleCompleter.future); + final Future image = _api.getPlatformImage(name); + return _platformImageToFutureMemoryImage(image, name); } /// Loads an image from the system. The equivalent would be: @@ -171,7 +158,7 @@ class IosPlatformImages { double size, { List colors = const [], bool preferMulticolor = false, - ui.FontWeight weight = FontWeight.normal, + FontWeight weight = FontWeight.regular, }) { if (preferMulticolor) { if (colors != const []) { @@ -190,35 +177,34 @@ class IosPlatformImages { ]) .toList(); - final Future?> loadInfo = - _channel.invokeMapMethod( - 'loadSystemImage', - [ - name, - size, - weight.index, - colorsRGBA, - preferMulticolor, - ], - ); + final Future image = + _api.getSystemImage(name, size, weight, colorsRGBA, preferMulticolor); + + return _platformImageToFutureMemoryImage(image, name); + } + + static _FutureMemoryImage _platformImageToFutureMemoryImage( + Future image, String name) { final Completer bytesCompleter = Completer(); final Completer scaleCompleter = Completer(); - loadInfo.then((Map? map) { - if (map == null) { + image.then((PlatformImage image) { + if (image == null || image.bytes == null || image.scale == null) { scaleCompleter.completeError( - ArgumentError("System image couldn't be found: $name"), + ArgumentError("Image couldn't be found: $name"), ); bytesCompleter.completeError( - ArgumentError("System image couldn't be found: $name"), + ArgumentError("Image couldn't be found: $name"), ); return; } - scaleCompleter.complete(map['scale']! as double); - bytesCompleter.complete(map['data']! as Uint8List); + + scaleCompleter.complete(image.scale); + bytesCompleter.complete(image.bytes); }); return _FutureMemoryImage(bytesCompleter.future, scaleCompleter.future); } + // TODO(cadenkriese): reimplement /// Resolves an URL for a resource. The equivalent would be: /// `[[NSBundle mainBundle] URLForResource:name withExtension:ext]`. /// @@ -226,7 +212,6 @@ class IosPlatformImages { /// /// See [https://developer.apple.com/documentation/foundation/nsbundle/1411540-urlforresource?language=objc] static Future resolveURL(String name, {String? extension}) { - return _channel - .invokeMethod('resolveURL', [name, extension]); + return _api.resolveURL(name, extension); } } diff --git a/packages/ios_platform_images/lib/platform_images_api.g.dart b/packages/ios_platform_images/lib/platform_images_api.g.dart new file mode 100644 index 000000000000..d22611fcae9f --- /dev/null +++ b/packages/ios_platform_images/lib/platform_images_api.g.dart @@ -0,0 +1,160 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// Autogenerated from Pigeon (v3.2.3), do not edit directly. +// See also: https://pub.dev/packages/pigeon +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import +import 'dart:async'; +import 'dart:typed_data' show Uint8List, Int32List, Int64List, Float64List; + +import 'package:flutter/foundation.dart' show WriteBuffer, ReadBuffer; +import 'package:flutter/services.dart'; + +enum FontWeight { + ultraLight, + thin, + light, + regular, + medium, + semibold, + bold, + heavy, + black, +} + +class PlatformImage { + PlatformImage({ + this.scale, + this.bytes, + }); + + double? scale; + Uint8List? bytes; + + Object encode() { + final Map pigeonMap = {}; + pigeonMap['scale'] = scale; + pigeonMap['bytes'] = bytes; + return pigeonMap; + } + + static PlatformImage decode(Object message) { + final Map pigeonMap = message as Map; + return PlatformImage( + scale: pigeonMap['scale'] as double?, + bytes: pigeonMap['bytes'] as Uint8List?, + ); + } +} + +class _PlatformImagesApiCodec extends StandardMessageCodec { + const _PlatformImagesApiCodec(); + @override + void writeValue(WriteBuffer buffer, Object? value) { + if (value is PlatformImage) { + buffer.putUint8(128); + writeValue(buffer, value.encode()); + } else +{ + super.writeValue(buffer, value); + } + } + @override + Object? readValueOfType(int type, ReadBuffer buffer) { + switch (type) { + case 128: + return PlatformImage.decode(readValue(buffer)!); + + default: + return super.readValueOfType(type, buffer); + + } + } +} + +class PlatformImagesApi { + /// Constructor for [PlatformImagesApi]. The [binaryMessenger] named argument is + /// available for dependency injection. If it is left null, the default + /// BinaryMessenger will be used which routes to the host platform. + PlatformImagesApi({BinaryMessenger? binaryMessenger}) : _binaryMessenger = binaryMessenger; + + final BinaryMessenger? _binaryMessenger; + + static const MessageCodec codec = _PlatformImagesApiCodec(); + + Future getSystemImage(String arg_name, double arg_size, FontWeight arg_weight, List arg_colorsRGBA, bool arg_preferMulticolor) async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.PlatformImagesApi.getSystemImage', codec, binaryMessenger: _binaryMessenger); + final Map? replyMap = + await channel.send([arg_name, arg_size, arg_weight.index, arg_colorsRGBA, arg_preferMulticolor]) as Map?; + if (replyMap == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyMap['error'] != null) { + final Map error = (replyMap['error'] as Map?)!; + throw PlatformException( + code: (error['code'] as String?)!, + message: error['message'] as String?, + details: error['details'], + ); + } else if (replyMap['result'] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (replyMap['result'] as PlatformImage?)!; + } + } + + Future getPlatformImage(String arg_name) async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.PlatformImagesApi.getPlatformImage', codec, binaryMessenger: _binaryMessenger); + final Map? replyMap = + await channel.send([arg_name]) as Map?; + if (replyMap == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyMap['error'] != null) { + final Map error = (replyMap['error'] as Map?)!; + throw PlatformException( + code: (error['code'] as String?)!, + message: error['message'] as String?, + details: error['details'], + ); + } else if (replyMap['result'] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (replyMap['result'] as PlatformImage?)!; + } + } + + Future resolveURL(String arg_name, String? arg_extension) async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.PlatformImagesApi.resolveURL', codec, binaryMessenger: _binaryMessenger); + final Map? replyMap = + await channel.send([arg_name, arg_extension]) as Map?; + if (replyMap == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyMap['error'] != null) { + final Map error = (replyMap['error'] as Map?)!; + throw PlatformException( + code: (error['code'] as String?)!, + message: error['message'] as String?, + details: error['details'], + ); + } else { + return (replyMap['result'] as String?); + } + } +} diff --git a/packages/ios_platform_images/pigeons/copyright.txt b/packages/ios_platform_images/pigeons/copyright.txt new file mode 100644 index 000000000000..fb682b1ab965 --- /dev/null +++ b/packages/ios_platform_images/pigeons/copyright.txt @@ -0,0 +1,3 @@ +Copyright 2013 The Flutter Authors. All rights reserved. +Use of this source code is governed by a BSD-style license that can be +found in the LICENSE file. \ No newline at end of file diff --git a/packages/ios_platform_images/pigeons/platform_images.dart b/packages/ios_platform_images/pigeons/platform_images.dart new file mode 100644 index 000000000000..f19a318b69ea --- /dev/null +++ b/packages/ios_platform_images/pigeons/platform_images.dart @@ -0,0 +1,35 @@ +import 'package:pigeon/pigeon.dart'; + +@ConfigurePigeon(PigeonOptions( + dartOut: 'lib/platform_images_api.g.dart', + objcHeaderOut: 'ios/Classes/PlatformImagesApi.g.h', + objcSourceOut: 'ios/Classes/PlatformImagesApi.g.m', + objcOptions: ObjcOptions( + prefix: 'FLT', + ), + copyrightHeader: 'pigeons/copyright.txt', +)) +class PlatformImage { + double? scale; + Uint8List? bytes; +} + +enum FontWeight { + ultraLight, + thin, + light, + regular, + medium, + semibold, + bold, + heavy, + black, +} + +@HostApi() +abstract class PlatformImagesApi { + PlatformImage getSystemImage(String name, double size, FontWeight weight, + List colorsRGBA, bool preferMulticolor); + PlatformImage getPlatformImage(String name); + String? resolveURL(String name, String? extension); +} diff --git a/packages/ios_platform_images/pubspec.yaml b/packages/ios_platform_images/pubspec.yaml index 6a321fed4875..3fdafc21ebf5 100644 --- a/packages/ios_platform_images/pubspec.yaml +++ b/packages/ios_platform_images/pubspec.yaml @@ -12,7 +12,8 @@ flutter: plugin: platforms: ios: - pluginClass: IosPlatformImagesPlugin + dartPluginClass: IosPlatformImages + pluginClass: FLTPlatformImagesPlugin dependencies: flutter: @@ -21,3 +22,5 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter + pedantic: ^1.10.0 + pigeon: ^3.2.3 From a43b25d1a2a9f2bb15f28194909d91f7ba35997d Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Tue, 30 Aug 2022 14:31:11 -0700 Subject: [PATCH 37/64] Re-enable integration tests for ios_platform_images --- script/configs/exclude_integration_ios.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/script/configs/exclude_integration_ios.yaml b/script/configs/exclude_integration_ios.yaml index 2d535cd4f0dc..ab49ae45ffbc 100644 --- a/script/configs/exclude_integration_ios.yaml +++ b/script/configs/exclude_integration_ios.yaml @@ -1,5 +1,3 @@ -# Currently missing: https://github.com/flutter/flutter/issues/82208 -- ios_platform_images # Can't use Flutter integration tests due to native modal UI. - file_selector_ios - file_selector \ No newline at end of file From f5855fb892dc65841651ac67c6c59239b372726c Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Tue, 30 Aug 2022 14:59:27 -0700 Subject: [PATCH 38/64] Run format --- .../ios/Classes/FLTPlatformImagesPlugin.m | 151 ++++++++++-------- .../ios/Classes/PlatformImagesApi.g.h | 23 ++- .../ios/Classes/PlatformImagesApi.g.m | 103 ++++++------ .../lib/ios_platform_images.dart | 1 - .../lib/platform_images_api.g.dart | 52 +++--- 5 files changed, 189 insertions(+), 141 deletions(-) diff --git a/packages/ios_platform_images/ios/Classes/FLTPlatformImagesPlugin.m b/packages/ios_platform_images/ios/Classes/FLTPlatformImagesPlugin.m index 01034020cc3a..9ea697a128f7 100644 --- a/packages/ios_platform_images/ios/Classes/FLTPlatformImagesPlugin.m +++ b/packages/ios_platform_images/ios/Classes/FLTPlatformImagesPlugin.m @@ -9,81 +9,98 @@ + (void)registerWithRegistrar:(NSObject *)registrar { FLTPlatformImagesApiSetup(registrar.messenger, instance); } -- (nullable FLTPlatformImage *)getSystemImageName:(NSString *)name size:(NSNumber *)size weight:(FLTFontWeight)weight colorsRGBA:(NSArray *)colorsRGBA preferMulticolor:(NSNumber *)preferMulticolor error:(FlutterError *_Nullable *_Nonnull)error { - if (@available(iOS 13, *)) { - // iOS adds ~15% padding to the outside of the image so we scale down to match the requested - // size. - double pointSize = [size doubleValue] * 0.85; - - // Up to 3 rgb values for primary, seconday and tertiary colors. - // see - // https://developer.apple.com/documentation/uikit/uiimagesymbolconfiguration/3810054-configurationwithpalettecolors - - NSMutableArray *colorArray = [[NSMutableArray alloc] init]; - - for (int i = 0; i < [colorsRGBA count]; i += 4) { - UIColor *primaryColor = [UIColor colorWithRed:[colorsRGBA[i] doubleValue] - green:[colorsRGBA[i + 1] doubleValue] - blue:[colorsRGBA[i + 2] doubleValue] - alpha:[colorsRGBA[i + 3] doubleValue]]; - [colorArray addObject:primaryColor]; - } - - UIImageSymbolWeight uiWeight = [ self weightFromFLTFontWeight: weight ]; - - UIImageSymbolConfiguration *pointSizeConfig = - [UIImageSymbolConfiguration configurationWithPointSize:pointSize - weight:uiWeight - scale:UIImageSymbolScaleDefault]; - - UIImage *finalImage; - - if (@available(iOS 15, *)) { - UIImageSymbolConfiguration *colors = - [preferMulticolor boolValue] - ? [UIImageSymbolConfiguration configurationPreferringMulticolor] - : [UIImageSymbolConfiguration configurationWithPaletteColors:colorArray]; - - UIImageSymbolConfiguration *final = - [pointSizeConfig configurationByApplyingConfiguration:colors]; - finalImage = [UIImage systemImageNamed:name withConfiguration:final]; - } else { - UIImage *image = [UIImage systemImageNamed:name withConfiguration:pointSizeConfig]; - finalImage = [image - imageWithTintColor:colorArray.count > 0 ? colorArray[0] : [UIColor blackColor]]; - } - - NSData *data = UIImagePNGRepresentation(finalImage); - return [ FLTPlatformImage makeWithScale:@(finalImage.scale) bytes:data ]; +- (nullable FLTPlatformImage *)getSystemImageName:(NSString *)name + size:(NSNumber *)size + weight:(FLTFontWeight)weight + colorsRGBA:(NSArray *)colorsRGBA + preferMulticolor:(NSNumber *)preferMulticolor + error:(FlutterError *_Nullable *_Nonnull)error { + if (@available(iOS 13, *)) { + // iOS adds ~15% padding to the outside of the image so we scale down to match the requested + // size. + double pointSize = [size doubleValue] * 0.85; + + // Up to 3 rgb values for primary, seconday and tertiary colors. + // see + // https://developer.apple.com/documentation/uikit/uiimagesymbolconfiguration/3810054-configurationwithpalettecolors + + NSMutableArray *colorArray = [[NSMutableArray alloc] init]; + + for (int i = 0; i < [colorsRGBA count]; i += 4) { + UIColor *primaryColor = [UIColor colorWithRed:[colorsRGBA[i] doubleValue] + green:[colorsRGBA[i + 1] doubleValue] + blue:[colorsRGBA[i + 2] doubleValue] + alpha:[colorsRGBA[i + 3] doubleValue]]; + [colorArray addObject:primaryColor]; } - return nil; -} -- (nullable FLTPlatformImage *)getPlatformImageName:(NSString *)name error:(FlutterError *_Nullable *_Nonnull)error { - UIImage *image = [UIImage imageNamed:name]; - NSData *data = UIImagePNGRepresentation(image); + UIImageSymbolWeight uiWeight = [self weightFromFLTFontWeight:weight]; + + UIImageSymbolConfiguration *pointSizeConfig = + [UIImageSymbolConfiguration configurationWithPointSize:pointSize + weight:uiWeight + scale:UIImageSymbolScaleDefault]; + + UIImage *finalImage; - return [ FLTPlatformImage makeWithScale:@(image.scale) bytes:data ]; + if (@available(iOS 15, *)) { + UIImageSymbolConfiguration *colors = + [preferMulticolor boolValue] + ? [UIImageSymbolConfiguration configurationPreferringMulticolor] + : [UIImageSymbolConfiguration configurationWithPaletteColors:colorArray]; + + UIImageSymbolConfiguration *final = + [pointSizeConfig configurationByApplyingConfiguration:colors]; + finalImage = [UIImage systemImageNamed:name withConfiguration:final]; + } else { + UIImage *image = [UIImage systemImageNamed:name withConfiguration:pointSizeConfig]; + finalImage = + [image imageWithTintColor:colorArray.count > 0 ? colorArray[0] : [UIColor blackColor]]; + } + + NSData *data = UIImagePNGRepresentation(finalImage); + return [FLTPlatformImage makeWithScale:@(finalImage.scale) bytes:data]; + } + return nil; } -- (nullable NSString *)resolveURLName:(NSString *)name extension:(nullable NSString *)extension error:(FlutterError *_Nullable *_Nonnull)error { - NSURL *url = [[NSBundle mainBundle] URLForResource:name withExtension:extension]; - return url.absoluteString; +- (nullable FLTPlatformImage *)getPlatformImageName:(NSString *)name + error:(FlutterError *_Nullable *_Nonnull)error { + UIImage *image = [UIImage imageNamed:name]; + NSData *data = UIImagePNGRepresentation(image); + + return [FLTPlatformImage makeWithScale:@(image.scale) bytes:data]; } +- (nullable NSString *)resolveURLName:(NSString *)name + extension:(nullable NSString *)extension + error:(FlutterError *_Nullable *_Nonnull)error { + NSURL *url = [[NSBundle mainBundle] URLForResource:name withExtension:extension]; + return url.absoluteString; +} -- (UIImageSymbolWeight) weightFromFLTFontWeight:(FLTFontWeight) flutterFontWeight API_AVAILABLE(ios(13)) { - switch (flutterFontWeight) { - case FLTFontWeightUltraLight: return UIImageSymbolWeightUltraLight; - case FLTFontWeightThin: return UIImageSymbolWeightThin; - case FLTFontWeightLight: return UIImageSymbolWeightLight; - case FLTFontWeightRegular: return UIImageSymbolWeightRegular; - case FLTFontWeightMedium: return UIImageSymbolWeightMedium; - case FLTFontWeightSemibold: return UIImageSymbolWeightSemibold; - case FLTFontWeightBold: return UIImageSymbolWeightBold; - case FLTFontWeightHeavy: return UIImageSymbolWeightHeavy; - case FLTFontWeightBlack: return UIImageSymbolWeightBlack; - } +- (UIImageSymbolWeight)weightFromFLTFontWeight:(FLTFontWeight)flutterFontWeight + API_AVAILABLE(ios(13)) { + switch (flutterFontWeight) { + case FLTFontWeightUltraLight: + return UIImageSymbolWeightUltraLight; + case FLTFontWeightThin: + return UIImageSymbolWeightThin; + case FLTFontWeightLight: + return UIImageSymbolWeightLight; + case FLTFontWeightRegular: + return UIImageSymbolWeightRegular; + case FLTFontWeightMedium: + return UIImageSymbolWeightMedium; + case FLTFontWeightSemibold: + return UIImageSymbolWeightSemibold; + case FLTFontWeightBold: + return UIImageSymbolWeightBold; + case FLTFontWeightHeavy: + return UIImageSymbolWeightHeavy; + case FLTFontWeightBlack: + return UIImageSymbolWeightBlack; + } } @end diff --git a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h index 8d97b6d328c3..9457a2054f48 100644 --- a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h +++ b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h @@ -27,9 +27,9 @@ typedef NS_ENUM(NSUInteger, FLTFontWeight) { @interface FLTPlatformImage : NSObject + (instancetype)makeWithScale:(nullable NSNumber *)scale - bytes:(nullable FlutterStandardTypedData *)bytes; -@property(nonatomic, strong, nullable) NSNumber * scale; -@property(nonatomic, strong, nullable) FlutterStandardTypedData * bytes; + bytes:(nullable FlutterStandardTypedData *)bytes; +@property(nonatomic, strong, nullable) NSNumber *scale; +@property(nonatomic, strong, nullable) FlutterStandardTypedData *bytes; @end /// The codec used by FLTPlatformImagesApi. @@ -37,12 +37,21 @@ NSObject *FLTPlatformImagesApiGetCodec(void); @protocol FLTPlatformImagesApi /// @return `nil` only when `error != nil`. -- (nullable FLTPlatformImage *)getSystemImageName:(NSString *)name size:(NSNumber *)size weight:(FLTFontWeight)weight colorsRGBA:(NSArray *)colorsRGBA preferMulticolor:(NSNumber *)preferMulticolor error:(FlutterError *_Nullable *_Nonnull)error; +- (nullable FLTPlatformImage *)getSystemImageName:(NSString *)name + size:(NSNumber *)size + weight:(FLTFontWeight)weight + colorsRGBA:(NSArray *)colorsRGBA + preferMulticolor:(NSNumber *)preferMulticolor + error:(FlutterError *_Nullable *_Nonnull)error; /// @return `nil` only when `error != nil`. -- (nullable FLTPlatformImage *)getPlatformImageName:(NSString *)name error:(FlutterError *_Nullable *_Nonnull)error; -- (nullable NSString *)resolveURLName:(NSString *)name extension:(nullable NSString *)extension error:(FlutterError *_Nullable *_Nonnull)error; +- (nullable FLTPlatformImage *)getPlatformImageName:(NSString *)name + error:(FlutterError *_Nullable *_Nonnull)error; +- (nullable NSString *)resolveURLName:(NSString *)name + extension:(nullable NSString *)extension + error:(FlutterError *_Nullable *_Nonnull)error; @end -extern void FLTPlatformImagesApiSetup(id binaryMessenger, NSObject *_Nullable api); +extern void FLTPlatformImagesApiSetup(id binaryMessenger, + NSObject *_Nullable api); NS_ASSUME_NONNULL_END diff --git a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m index 34e357872255..16a10eb551d4 100644 --- a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m +++ b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m @@ -14,26 +14,25 @@ NSDictionary *errorDict = (NSDictionary *)[NSNull null]; if (error) { errorDict = @{ - @"code": (error.code ?: [NSNull null]), - @"message": (error.message ?: [NSNull null]), - @"details": (error.details ?: [NSNull null]), - }; + @"code" : (error.code ?: [NSNull null]), + @"message" : (error.message ?: [NSNull null]), + @"details" : (error.details ?: [NSNull null]), + }; } return @{ - @"result": (result ?: [NSNull null]), - @"error": errorDict, - }; + @"result" : (result ?: [NSNull null]), + @"error" : errorDict, + }; } -static id GetNullableObject(NSDictionary* dict, id key) { +static id GetNullableObject(NSDictionary *dict, id key) { id result = dict[key]; return (result == [NSNull null]) ? nil : result; } -static id GetNullableObjectAtIndex(NSArray* array, NSInteger key) { +static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) { id result = array[key]; return (result == [NSNull null]) ? nil : result; } - @interface FLTPlatformImage () + (FLTPlatformImage *)fromMap:(NSDictionary *)dict; + (nullable FLTPlatformImage *)nullableFromMap:(NSDictionary *)dict; @@ -42,8 +41,8 @@ - (NSDictionary *)toMap; @implementation FLTPlatformImage + (instancetype)makeWithScale:(nullable NSNumber *)scale - bytes:(nullable FlutterStandardTypedData *)bytes { - FLTPlatformImage* pigeonResult = [[FLTPlatformImage alloc] init]; + bytes:(nullable FlutterStandardTypedData *)bytes { + FLTPlatformImage *pigeonResult = [[FLTPlatformImage alloc] init]; pigeonResult.scale = scale; pigeonResult.bytes = bytes; return pigeonResult; @@ -54,7 +53,9 @@ + (FLTPlatformImage *)fromMap:(NSDictionary *)dict { pigeonResult.bytes = GetNullableObject(dict, @"bytes"); return pigeonResult; } -+ (nullable FLTPlatformImage *)nullableFromMap:(NSDictionary *)dict { return (dict) ? [FLTPlatformImage fromMap:dict] : nil; } ++ (nullable FLTPlatformImage *)nullableFromMap:(NSDictionary *)dict { + return (dict) ? [FLTPlatformImage fromMap:dict] : nil; +} - (NSDictionary *)toMap { return @{ @"scale" : (self.scale ?: [NSNull null]), @@ -66,15 +67,13 @@ - (NSDictionary *)toMap { @interface FLTPlatformImagesApiCodecReader : FlutterStandardReader @end @implementation FLTPlatformImagesApiCodecReader -- (nullable id)readValueOfType:(UInt8)type -{ +- (nullable id)readValueOfType:(UInt8)type { switch (type) { - case 128: + case 128: return [FLTPlatformImage fromMap:[self readValue]]; - - default: + + default: return [super readValueOfType:type]; - } } @end @@ -82,13 +81,11 @@ - (nullable id)readValueOfType:(UInt8)type @interface FLTPlatformImagesApiCodecWriter : FlutterStandardWriter @end @implementation FLTPlatformImagesApiCodecWriter -- (void)writeValue:(id)value -{ +- (void)writeValue:(id)value { if ([value isKindOfClass:[FLTPlatformImage class]]) { [self writeByte:128]; [self writeValue:[value toMap]]; - } else -{ + } else { [super writeValue:value]; } } @@ -109,22 +106,26 @@ - (FlutterStandardReader *)readerWithData:(NSData *)data { static dispatch_once_t sPred = 0; static FlutterStandardMessageCodec *sSharedObject = nil; dispatch_once(&sPred, ^{ - FLTPlatformImagesApiCodecReaderWriter *readerWriter = [[FLTPlatformImagesApiCodecReaderWriter alloc] init]; + FLTPlatformImagesApiCodecReaderWriter *readerWriter = + [[FLTPlatformImagesApiCodecReaderWriter alloc] init]; sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; }); return sSharedObject; } - -void FLTPlatformImagesApiSetup(id binaryMessenger, NSObject *api) { +void FLTPlatformImagesApiSetup(id binaryMessenger, + NSObject *api) { { - FlutterBasicMessageChannel *channel = - [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.PlatformImagesApi.getSystemImage" + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.PlatformImagesApi.getSystemImage" binaryMessenger:binaryMessenger - codec:FLTPlatformImagesApiGetCodec() ]; + codec:FLTPlatformImagesApiGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(getSystemImageName:size:weight:colorsRGBA:preferMulticolor:error:)], @"FLTPlatformImagesApi api (%@) doesn't respond to @selector(getSystemImageName:size:weight:colorsRGBA:preferMulticolor:error:)", api); + NSCAssert([api respondsToSelector:@selector + (getSystemImageName:size:weight:colorsRGBA:preferMulticolor:error:)], + @"FLTPlatformImagesApi api (%@) doesn't respond to " + @"@selector(getSystemImageName:size:weight:colorsRGBA:preferMulticolor:error:)", + api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; NSString *arg_name = GetNullableObjectAtIndex(args, 0); @@ -133,22 +134,28 @@ void FLTPlatformImagesApiSetup(id binaryMessenger, NSObj NSArray *arg_colorsRGBA = GetNullableObjectAtIndex(args, 3); NSNumber *arg_preferMulticolor = GetNullableObjectAtIndex(args, 4); FlutterError *error; - FLTPlatformImage *output = [api getSystemImageName:arg_name size:arg_size weight:arg_weight colorsRGBA:arg_colorsRGBA preferMulticolor:arg_preferMulticolor error:&error]; + FLTPlatformImage *output = [api getSystemImageName:arg_name + size:arg_size + weight:arg_weight + colorsRGBA:arg_colorsRGBA + preferMulticolor:arg_preferMulticolor + error:&error]; callback(wrapResult(output, error)); }]; - } - else { + } else { [channel setMessageHandler:nil]; } } { - FlutterBasicMessageChannel *channel = - [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.PlatformImagesApi.getPlatformImage" + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.PlatformImagesApi.getPlatformImage" binaryMessenger:binaryMessenger - codec:FLTPlatformImagesApiGetCodec() ]; + codec:FLTPlatformImagesApiGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(getPlatformImageName:error:)], @"FLTPlatformImagesApi api (%@) doesn't respond to @selector(getPlatformImageName:error:)", api); + NSCAssert([api respondsToSelector:@selector(getPlatformImageName:error:)], + @"FLTPlatformImagesApi api (%@) doesn't respond to " + @"@selector(getPlatformImageName:error:)", + api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; NSString *arg_name = GetNullableObjectAtIndex(args, 0); @@ -156,19 +163,20 @@ void FLTPlatformImagesApiSetup(id binaryMessenger, NSObj FLTPlatformImage *output = [api getPlatformImageName:arg_name error:&error]; callback(wrapResult(output, error)); }]; - } - else { + } else { [channel setMessageHandler:nil]; } } { - FlutterBasicMessageChannel *channel = - [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.PlatformImagesApi.resolveURL" + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.PlatformImagesApi.resolveURL" binaryMessenger:binaryMessenger - codec:FLTPlatformImagesApiGetCodec() ]; + codec:FLTPlatformImagesApiGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(resolveURLName:extension:error:)], @"FLTPlatformImagesApi api (%@) doesn't respond to @selector(resolveURLName:extension:error:)", api); + NSCAssert([api respondsToSelector:@selector(resolveURLName:extension:error:)], + @"FLTPlatformImagesApi api (%@) doesn't respond to " + @"@selector(resolveURLName:extension:error:)", + api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; NSString *arg_name = GetNullableObjectAtIndex(args, 0); @@ -177,8 +185,7 @@ void FLTPlatformImagesApiSetup(id binaryMessenger, NSObj NSString *output = [api resolveURLName:arg_name extension:arg_extension error:&error]; callback(wrapResult(output, error)); }]; - } - else { + } else { [channel setMessageHandler:nil]; } } diff --git a/packages/ios_platform_images/lib/ios_platform_images.dart b/packages/ios_platform_images/lib/ios_platform_images.dart index e34362a90c02..c6871f566156 100644 --- a/packages/ios_platform_images/lib/ios_platform_images.dart +++ b/packages/ios_platform_images/lib/ios_platform_images.dart @@ -204,7 +204,6 @@ class IosPlatformImages { return _FutureMemoryImage(bytesCompleter.future, scaleCompleter.future); } - // TODO(cadenkriese): reimplement /// Resolves an URL for a resource. The equivalent would be: /// `[[NSBundle mainBundle] URLForResource:name withExtension:ext]`. /// diff --git a/packages/ios_platform_images/lib/platform_images_api.g.dart b/packages/ios_platform_images/lib/platform_images_api.g.dart index d22611fcae9f..2ba4c7aaccc6 100644 --- a/packages/ios_platform_images/lib/platform_images_api.g.dart +++ b/packages/ios_platform_images/lib/platform_images_api.g.dart @@ -54,20 +54,19 @@ class _PlatformImagesApiCodec extends StandardMessageCodec { if (value is PlatformImage) { buffer.putUint8(128); writeValue(buffer, value.encode()); - } else -{ + } else { super.writeValue(buffer, value); } } + @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: + case 128: return PlatformImage.decode(readValue(buffer)!); - - default: + + default: return super.readValueOfType(type, buffer); - } } } @@ -76,24 +75,37 @@ class PlatformImagesApi { /// Constructor for [PlatformImagesApi]. The [binaryMessenger] named argument is /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. - PlatformImagesApi({BinaryMessenger? binaryMessenger}) : _binaryMessenger = binaryMessenger; + PlatformImagesApi({BinaryMessenger? binaryMessenger}) + : _binaryMessenger = binaryMessenger; final BinaryMessenger? _binaryMessenger; static const MessageCodec codec = _PlatformImagesApiCodec(); - Future getSystemImage(String arg_name, double arg_size, FontWeight arg_weight, List arg_colorsRGBA, bool arg_preferMulticolor) async { + Future getSystemImage( + String arg_name, + double arg_size, + FontWeight arg_weight, + List arg_colorsRGBA, + bool arg_preferMulticolor) async { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.PlatformImagesApi.getSystemImage', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_name, arg_size, arg_weight.index, arg_colorsRGBA, arg_preferMulticolor]) as Map?; + 'dev.flutter.pigeon.PlatformImagesApi.getSystemImage', codec, + binaryMessenger: _binaryMessenger); + final Map? replyMap = await channel.send([ + arg_name, + arg_size, + arg_weight.index, + arg_colorsRGBA, + arg_preferMulticolor + ]) as Map?; if (replyMap == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); } else if (replyMap['error'] != null) { - final Map error = (replyMap['error'] as Map?)!; + final Map error = + (replyMap['error'] as Map?)!; throw PlatformException( code: (error['code'] as String?)!, message: error['message'] as String?, @@ -111,7 +123,8 @@ class PlatformImagesApi { Future getPlatformImage(String arg_name) async { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.PlatformImagesApi.getPlatformImage', codec, binaryMessenger: _binaryMessenger); + 'dev.flutter.pigeon.PlatformImagesApi.getPlatformImage', codec, + binaryMessenger: _binaryMessenger); final Map? replyMap = await channel.send([arg_name]) as Map?; if (replyMap == null) { @@ -120,7 +133,8 @@ class PlatformImagesApi { message: 'Unable to establish connection on channel.', ); } else if (replyMap['error'] != null) { - final Map error = (replyMap['error'] as Map?)!; + final Map error = + (replyMap['error'] as Map?)!; throw PlatformException( code: (error['code'] as String?)!, message: error['message'] as String?, @@ -138,16 +152,18 @@ class PlatformImagesApi { Future resolveURL(String arg_name, String? arg_extension) async { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.PlatformImagesApi.resolveURL', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_name, arg_extension]) as Map?; + 'dev.flutter.pigeon.PlatformImagesApi.resolveURL', codec, + binaryMessenger: _binaryMessenger); + final Map? replyMap = await channel + .send([arg_name, arg_extension]) as Map?; if (replyMap == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); } else if (replyMap['error'] != null) { - final Map error = (replyMap['error'] as Map?)!; + final Map error = + (replyMap['error'] as Map?)!; throw PlatformException( code: (error['code'] as String?)!, message: error['message'] as String?, From 8c4cba9709527702647a456d71b34dbcd6864dfb Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Sat, 10 Sep 2022 23:48:31 -0700 Subject: [PATCH 39/64] Fix casting error --- .../ios_platform_images/ios/Classes/FLTPlatformImagesPlugin.m | 3 ++- packages/ios_platform_images/pubspec.yaml | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/ios_platform_images/ios/Classes/FLTPlatformImagesPlugin.m b/packages/ios_platform_images/ios/Classes/FLTPlatformImagesPlugin.m index 9ea697a128f7..1a6f03fbf0cd 100644 --- a/packages/ios_platform_images/ios/Classes/FLTPlatformImagesPlugin.m +++ b/packages/ios_platform_images/ios/Classes/FLTPlatformImagesPlugin.m @@ -67,7 +67,8 @@ - (nullable FLTPlatformImage *)getSystemImageName:(NSString *)name - (nullable FLTPlatformImage *)getPlatformImageName:(NSString *)name error:(FlutterError *_Nullable *_Nonnull)error { UIImage *image = [UIImage imageNamed:name]; - NSData *data = UIImagePNGRepresentation(image); + FlutterStandardTypedData *data = + [FlutterStandardTypedData typedDataWithBytes:UIImagePNGRepresentation(image)]; return [FLTPlatformImage makeWithScale:@(image.scale) bytes:data]; } diff --git a/packages/ios_platform_images/pubspec.yaml b/packages/ios_platform_images/pubspec.yaml index 3fdafc21ebf5..2553de4a267a 100644 --- a/packages/ios_platform_images/pubspec.yaml +++ b/packages/ios_platform_images/pubspec.yaml @@ -22,5 +22,7 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter + integration_test: + sdk: flutter pedantic: ^1.10.0 - pigeon: ^3.2.3 + pigeon: ^4.2.0 From fe2ed61e6426745ba3a094e0c14b2f7537fbf90c Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Thu, 6 Oct 2022 01:52:33 -0700 Subject: [PATCH 40/64] Rewrite dart test --- .../ios_platform_images_integration_test.dart | 8 +- packages/ios_platform_images/pubspec.yaml | 2 + .../test/ios_platform_images_test.dart | 38 ++++-- .../test/ios_platform_images_test.mocks.dart | 122 ++++++++++++++++++ 4 files changed, 155 insertions(+), 15 deletions(-) create mode 100644 packages/ios_platform_images/test/ios_platform_images_test.mocks.dart diff --git a/packages/ios_platform_images/example/integration_test/ios_platform_images_integration_test.dart b/packages/ios_platform_images/example/integration_test/ios_platform_images_integration_test.dart index c07f2d3ea68e..712aa9ad1b98 100644 --- a/packages/ios_platform_images/example/integration_test/ios_platform_images_integration_test.dart +++ b/packages/ios_platform_images/example/integration_test/ios_platform_images_integration_test.dart @@ -39,21 +39,21 @@ void main() { testWidgets( 'ios system image error case', (WidgetTester tester) async { - final Completer _completer = Completer(); + final Completer completer = Completer(); final ImageProvider imageProvider = IosPlatformImages.loadSystemImage('invalid_symbol', 10); imageProvider.resolve(ImageConfiguration.empty).completer?.addListener( ImageStreamListener( - (ImageInfo info, bool _) => _completer.complete(info), + (ImageInfo info, bool _) => completer.complete(info), onError: (Object exception, StackTrace? stack) => () { - _completer.completeError(exception); + completer.completeError(exception); }, ), ); - await expectLater(_completer.future, throwsArgumentError); + await expectLater(completer.future, throwsArgumentError); }, ); } diff --git a/packages/ios_platform_images/pubspec.yaml b/packages/ios_platform_images/pubspec.yaml index 2553de4a267a..100fa752f112 100644 --- a/packages/ios_platform_images/pubspec.yaml +++ b/packages/ios_platform_images/pubspec.yaml @@ -20,9 +20,11 @@ dependencies: sdk: flutter dev_dependencies: + build_runner: ^2.2.1 flutter_test: sdk: flutter integration_test: sdk: flutter + mockito: ^5.3.2 pedantic: ^1.10.0 pigeon: ^4.2.0 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 76b012002dfa..d0d69c3c75eb 100644 --- a/packages/ios_platform_images/test/ios_platform_images_test.dart +++ b/packages/ios_platform_images/test/ios_platform_images_test.dart @@ -2,27 +2,43 @@ // 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/foundation.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:ios_platform_images/ios_platform_images.dart'; +import 'package:ios_platform_images/platform_images_api.g.dart'; +import 'package:mockito/annotations.dart'; +import 'package:mockito/mockito.dart'; +@GenerateNiceMocks(>[MockSpec()]) +import 'ios_platform_images_test.mocks.dart'; void main() { - const MethodChannel channel = - MethodChannel('plugins.flutter.io/ios_platform_images'); + final MockPlatformImagesApi api = MockPlatformImagesApi(); TestWidgetsFlutterBinding.ensureInitialized(); + final PlatformImage fakePlatformImage = PlatformImage(bytes: Uint8List(1)); + final PlatformImage fakeSystemImage = PlatformImage(bytes: Uint8List(2)); + setUp(() { - channel.setMockMethodCallHandler((MethodCall methodCall) async { - return '42'; - }); + when(api.resolveURL('foobar', null)).thenAnswer((_) async => '42'); + when(api.getPlatformImage('platformImage')) + .thenAnswer((_) async => fakePlatformImage); + when(api.getSystemImage( + 'systemImage', 2, FontWeight.bold, [1, 1, 1], true)) + .thenAnswer((_) async => fakeSystemImage); }); - tearDown(() { - channel.setMockMethodCallHandler(null); + test('resolveURL', () async { + expect(await api.resolveURL('foobar', null), '42'); }); - test('resolveURL', () async { - expect(await IosPlatformImages.resolveURL('foobar'), '42'); + test('getPlatformImage', () async { + expect(await api.getPlatformImage('platformImage'), fakePlatformImage); + }); + + test('getSystemImage', () async { + expect( + await api.getSystemImage( + 'systemImage', 2, FontWeight.bold, [1, 1, 1], true), + fakeSystemImage); }); } diff --git a/packages/ios_platform_images/test/ios_platform_images_test.mocks.dart b/packages/ios_platform_images/test/ios_platform_images_test.mocks.dart new file mode 100644 index 000000000000..2b35a019e3d2 --- /dev/null +++ b/packages/ios_platform_images/test/ios_platform_images_test.mocks.dart @@ -0,0 +1,122 @@ +// Mocks generated by Mockito 5.3.2 from annotations +// in ios_platform_images/example/ios/.symlinks/plugins/ios_platform_images/test/ios_platform_images_test.dart. +// Do not manually edit this file. + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:async' as _i3; + +import 'package:ios_platform_images/platform_images_api.g.dart' as _i2; +import 'package:mockito/mockito.dart' as _i1; + +// ignore_for_file: type=lint +// ignore_for_file: avoid_redundant_argument_values +// ignore_for_file: avoid_setters_without_getters +// ignore_for_file: comment_references +// ignore_for_file: implementation_imports +// ignore_for_file: invalid_use_of_visible_for_testing_member +// ignore_for_file: prefer_const_constructors +// ignore_for_file: unnecessary_parenthesis +// ignore_for_file: camel_case_types +// ignore_for_file: subtype_of_sealed_class + +class _FakePlatformImage_0 extends _i1.SmartFake implements _i2.PlatformImage { + _FakePlatformImage_0( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +/// A class which mocks [PlatformImagesApi]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockPlatformImagesApi extends _i1.Mock implements _i2.PlatformImagesApi { + @override + _i3.Future<_i2.PlatformImage> getSystemImage( + String? arg_name, + double? arg_size, + _i2.FontWeight? arg_weight, + List? arg_colorsRGBA, + bool? arg_preferMulticolor, + ) => + (super.noSuchMethod( + Invocation.method( + #getSystemImage, + [ + arg_name, + arg_size, + arg_weight, + arg_colorsRGBA, + arg_preferMulticolor, + ], + ), + returnValue: _i3.Future<_i2.PlatformImage>.value(_FakePlatformImage_0( + this, + Invocation.method( + #getSystemImage, + [ + arg_name, + arg_size, + arg_weight, + arg_colorsRGBA, + arg_preferMulticolor, + ], + ), + )), + returnValueForMissingStub: + _i3.Future<_i2.PlatformImage>.value(_FakePlatformImage_0( + this, + Invocation.method( + #getSystemImage, + [ + arg_name, + arg_size, + arg_weight, + arg_colorsRGBA, + arg_preferMulticolor, + ], + ), + )), + ) as _i3.Future<_i2.PlatformImage>); + @override + _i3.Future<_i2.PlatformImage> getPlatformImage(String? arg_name) => + (super.noSuchMethod( + Invocation.method( + #getPlatformImage, + [arg_name], + ), + returnValue: _i3.Future<_i2.PlatformImage>.value(_FakePlatformImage_0( + this, + Invocation.method( + #getPlatformImage, + [arg_name], + ), + )), + returnValueForMissingStub: + _i3.Future<_i2.PlatformImage>.value(_FakePlatformImage_0( + this, + Invocation.method( + #getPlatformImage, + [arg_name], + ), + )), + ) as _i3.Future<_i2.PlatformImage>); + @override + _i3.Future resolveURL( + String? arg_name, + String? arg_extension, + ) => + (super.noSuchMethod( + Invocation.method( + #resolveURL, + [ + arg_name, + arg_extension, + ], + ), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); +} From 1e42c3f9bb8dd19f5dfa91c168b7c132e5dabe1d Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Thu, 6 Oct 2022 02:02:12 -0700 Subject: [PATCH 41/64] Add missing license notices --- .../ios_platform_images/ios/Classes/FLTPlatformImagesPlugin.m | 4 ++++ packages/ios_platform_images/pigeons/platform_images.dart | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/packages/ios_platform_images/ios/Classes/FLTPlatformImagesPlugin.m b/packages/ios_platform_images/ios/Classes/FLTPlatformImagesPlugin.m index 1a6f03fbf0cd..608799b2b106 100644 --- a/packages/ios_platform_images/ios/Classes/FLTPlatformImagesPlugin.m +++ b/packages/ios_platform_images/ios/Classes/FLTPlatformImagesPlugin.m @@ -1,3 +1,7 @@ +// Copyright 2013 The Flutter 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 "FLTPlatformImagesPlugin.h" #import "PlatformImagesApi.g.h" diff --git a/packages/ios_platform_images/pigeons/platform_images.dart b/packages/ios_platform_images/pigeons/platform_images.dart index f19a318b69ea..715737e998ad 100644 --- a/packages/ios_platform_images/pigeons/platform_images.dart +++ b/packages/ios_platform_images/pigeons/platform_images.dart @@ -1,3 +1,7 @@ +// Copyright 2013 The Flutter 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:pigeon/pigeon.dart'; @ConfigurePigeon(PigeonOptions( From 9fb5be86ef6de57af05a4808ae2c6c3bb6099279 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Thu, 6 Oct 2022 16:07:29 -0700 Subject: [PATCH 42/64] Fix dart formatting --- packages/ios_platform_images/example/pubspec.yaml | 4 ++-- packages/ios_platform_images/lib/ios_platform_images.dart | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/ios_platform_images/example/pubspec.yaml b/packages/ios_platform_images/example/pubspec.yaml index 86194662db5c..96153d0c3ed0 100644 --- a/packages/ios_platform_images/example/pubspec.yaml +++ b/packages/ios_platform_images/example/pubspec.yaml @@ -19,10 +19,10 @@ dependencies: path: ../ dev_dependencies: - integration_test: - sdk: flutter flutter_test: sdk: flutter + integration_test: + sdk: flutter flutter: uses-material-design: true diff --git a/packages/ios_platform_images/lib/ios_platform_images.dart b/packages/ios_platform_images/lib/ios_platform_images.dart index c6871f566156..20ce9b67d317 100644 --- a/packages/ios_platform_images/lib/ios_platform_images.dart +++ b/packages/ios_platform_images/lib/ios_platform_images.dart @@ -9,7 +9,7 @@ import 'package:flutter/foundation.dart' show SynchronousFuture, describeIdentity, immutable, objectRuntimeType; import 'package:flutter/rendering.dart'; -import 'package:ios_platform_images/platform_images_api.g.dart'; +import './platform_images_api.g.dart'; class _FutureImageStreamCompleter extends ImageStreamCompleter { _FutureImageStreamCompleter({ From 30e5af9b285bb578fe3bbc7c9e7e1ad9f17263a1 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Thu, 6 Oct 2022 16:15:16 -0700 Subject: [PATCH 43/64] Update & regenerate Pigeon --- .../ios/Classes/PlatformImagesApi.g.h | 27 ++--- .../ios/Classes/PlatformImagesApi.g.m | 105 ++++++++---------- .../lib/platform_images_api.g.dart | 58 ++++------ packages/ios_platform_images/pubspec.yaml | 2 +- 4 files changed, 80 insertions(+), 112 deletions(-) diff --git a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h index 9457a2054f48..93717394f0d9 100644 --- a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h +++ b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v3.2.3), do not edit directly. +// Autogenerated from Pigeon (v4.2.1), do not edit directly. // See also: https://pub.dev/packages/pigeon #import @protocol FlutterBinaryMessenger; @@ -27,31 +27,22 @@ typedef NS_ENUM(NSUInteger, FLTFontWeight) { @interface FLTPlatformImage : NSObject + (instancetype)makeWithScale:(nullable NSNumber *)scale - bytes:(nullable FlutterStandardTypedData *)bytes; -@property(nonatomic, strong, nullable) NSNumber *scale; -@property(nonatomic, strong, nullable) FlutterStandardTypedData *bytes; + bytes:(nullable FlutterStandardTypedData *)bytes; +@property(nonatomic, strong, nullable) NSNumber * scale; +@property(nonatomic, strong, nullable) FlutterStandardTypedData * bytes; @end -/// The codec used by FLTPlatformImagesApi. +///The codec used by FLTPlatformImagesApi. NSObject *FLTPlatformImagesApiGetCodec(void); @protocol FLTPlatformImagesApi /// @return `nil` only when `error != nil`. -- (nullable FLTPlatformImage *)getSystemImageName:(NSString *)name - size:(NSNumber *)size - weight:(FLTFontWeight)weight - colorsRGBA:(NSArray *)colorsRGBA - preferMulticolor:(NSNumber *)preferMulticolor - error:(FlutterError *_Nullable *_Nonnull)error; +- (nullable FLTPlatformImage *)getSystemImageName:(NSString *)name size:(NSNumber *)size weight:(FLTFontWeight)weight colorsRGBA:(NSArray *)colorsRGBA preferMulticolor:(NSNumber *)preferMulticolor error:(FlutterError *_Nullable *_Nonnull)error; /// @return `nil` only when `error != nil`. -- (nullable FLTPlatformImage *)getPlatformImageName:(NSString *)name - error:(FlutterError *_Nullable *_Nonnull)error; -- (nullable NSString *)resolveURLName:(NSString *)name - extension:(nullable NSString *)extension - error:(FlutterError *_Nullable *_Nonnull)error; +- (nullable FLTPlatformImage *)getPlatformImageName:(NSString *)name error:(FlutterError *_Nullable *_Nonnull)error; +- (nullable NSString *)resolveURLName:(NSString *)name extension:(nullable NSString *)extension error:(FlutterError *_Nullable *_Nonnull)error; @end -extern void FLTPlatformImagesApiSetup(id binaryMessenger, - NSObject *_Nullable api); +extern void FLTPlatformImagesApiSetup(id binaryMessenger, NSObject *_Nullable api); NS_ASSUME_NONNULL_END diff --git a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m index 16a10eb551d4..385c56e355e4 100644 --- a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m +++ b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v3.2.3), do not edit directly. +// Autogenerated from Pigeon (v4.2.1), do not edit directly. // See also: https://pub.dev/packages/pigeon #import "PlatformImagesApi.g.h" #import @@ -14,25 +14,26 @@ NSDictionary *errorDict = (NSDictionary *)[NSNull null]; if (error) { errorDict = @{ - @"code" : (error.code ?: [NSNull null]), - @"message" : (error.message ?: [NSNull null]), - @"details" : (error.details ?: [NSNull null]), - }; + @"code": (error.code ?: [NSNull null]), + @"message": (error.message ?: [NSNull null]), + @"details": (error.details ?: [NSNull null]), + }; } return @{ - @"result" : (result ?: [NSNull null]), - @"error" : errorDict, - }; + @"result": (result ?: [NSNull null]), + @"error": errorDict, + }; } -static id GetNullableObject(NSDictionary *dict, id key) { +static id GetNullableObject(NSDictionary* dict, id key) { id result = dict[key]; return (result == [NSNull null]) ? nil : result; } -static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) { +static id GetNullableObjectAtIndex(NSArray* array, NSInteger key) { id result = array[key]; return (result == [NSNull null]) ? nil : result; } + @interface FLTPlatformImage () + (FLTPlatformImage *)fromMap:(NSDictionary *)dict; + (nullable FLTPlatformImage *)nullableFromMap:(NSDictionary *)dict; @@ -41,8 +42,8 @@ - (NSDictionary *)toMap; @implementation FLTPlatformImage + (instancetype)makeWithScale:(nullable NSNumber *)scale - bytes:(nullable FlutterStandardTypedData *)bytes { - FLTPlatformImage *pigeonResult = [[FLTPlatformImage alloc] init]; + bytes:(nullable FlutterStandardTypedData *)bytes { + FLTPlatformImage* pigeonResult = [[FLTPlatformImage alloc] init]; pigeonResult.scale = scale; pigeonResult.bytes = bytes; return pigeonResult; @@ -53,9 +54,7 @@ + (FLTPlatformImage *)fromMap:(NSDictionary *)dict { pigeonResult.bytes = GetNullableObject(dict, @"bytes"); return pigeonResult; } -+ (nullable FLTPlatformImage *)nullableFromMap:(NSDictionary *)dict { - return (dict) ? [FLTPlatformImage fromMap:dict] : nil; -} ++ (nullable FLTPlatformImage *)nullableFromMap:(NSDictionary *)dict { return (dict) ? [FLTPlatformImage fromMap:dict] : nil; } - (NSDictionary *)toMap { return @{ @"scale" : (self.scale ?: [NSNull null]), @@ -67,13 +66,15 @@ - (NSDictionary *)toMap { @interface FLTPlatformImagesApiCodecReader : FlutterStandardReader @end @implementation FLTPlatformImagesApiCodecReader -- (nullable id)readValueOfType:(UInt8)type { +- (nullable id)readValueOfType:(UInt8)type +{ switch (type) { - case 128: + case 128: return [FLTPlatformImage fromMap:[self readValue]]; - - default: + + default: return [super readValueOfType:type]; + } } @end @@ -81,11 +82,13 @@ - (nullable id)readValueOfType:(UInt8)type { @interface FLTPlatformImagesApiCodecWriter : FlutterStandardWriter @end @implementation FLTPlatformImagesApiCodecWriter -- (void)writeValue:(id)value { +- (void)writeValue:(id)value +{ if ([value isKindOfClass:[FLTPlatformImage class]]) { [self writeByte:128]; [self writeValue:[value toMap]]; - } else { + } else +{ [super writeValue:value]; } } @@ -106,26 +109,22 @@ - (FlutterStandardReader *)readerWithData:(NSData *)data { static dispatch_once_t sPred = 0; static FlutterStandardMessageCodec *sSharedObject = nil; dispatch_once(&sPred, ^{ - FLTPlatformImagesApiCodecReaderWriter *readerWriter = - [[FLTPlatformImagesApiCodecReaderWriter alloc] init]; + FLTPlatformImagesApiCodecReaderWriter *readerWriter = [[FLTPlatformImagesApiCodecReaderWriter alloc] init]; sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; }); return sSharedObject; } -void FLTPlatformImagesApiSetup(id binaryMessenger, - NSObject *api) { + +void FLTPlatformImagesApiSetup(id binaryMessenger, NSObject *api) { { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.PlatformImagesApi.getSystemImage" + FlutterBasicMessageChannel *channel = + [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.PlatformImagesApi.getSystemImage" binaryMessenger:binaryMessenger - codec:FLTPlatformImagesApiGetCodec()]; + codec:FLTPlatformImagesApiGetCodec() ]; if (api) { - NSCAssert([api respondsToSelector:@selector - (getSystemImageName:size:weight:colorsRGBA:preferMulticolor:error:)], - @"FLTPlatformImagesApi api (%@) doesn't respond to " - @"@selector(getSystemImageName:size:weight:colorsRGBA:preferMulticolor:error:)", - api); + NSCAssert([api respondsToSelector:@selector(getSystemImageName:size:weight:colorsRGBA:preferMulticolor:error:)], @"FLTPlatformImagesApi api (%@) doesn't respond to @selector(getSystemImageName:size:weight:colorsRGBA:preferMulticolor:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; NSString *arg_name = GetNullableObjectAtIndex(args, 0); @@ -134,28 +133,22 @@ void FLTPlatformImagesApiSetup(id binaryMessenger, NSArray *arg_colorsRGBA = GetNullableObjectAtIndex(args, 3); NSNumber *arg_preferMulticolor = GetNullableObjectAtIndex(args, 4); FlutterError *error; - FLTPlatformImage *output = [api getSystemImageName:arg_name - size:arg_size - weight:arg_weight - colorsRGBA:arg_colorsRGBA - preferMulticolor:arg_preferMulticolor - error:&error]; + FLTPlatformImage *output = [api getSystemImageName:arg_name size:arg_size weight:arg_weight colorsRGBA:arg_colorsRGBA preferMulticolor:arg_preferMulticolor error:&error]; callback(wrapResult(output, error)); }]; - } else { + } + else { [channel setMessageHandler:nil]; } } { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.PlatformImagesApi.getPlatformImage" + FlutterBasicMessageChannel *channel = + [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.PlatformImagesApi.getPlatformImage" binaryMessenger:binaryMessenger - codec:FLTPlatformImagesApiGetCodec()]; + codec:FLTPlatformImagesApiGetCodec() ]; if (api) { - NSCAssert([api respondsToSelector:@selector(getPlatformImageName:error:)], - @"FLTPlatformImagesApi api (%@) doesn't respond to " - @"@selector(getPlatformImageName:error:)", - api); + NSCAssert([api respondsToSelector:@selector(getPlatformImageName:error:)], @"FLTPlatformImagesApi api (%@) doesn't respond to @selector(getPlatformImageName:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; NSString *arg_name = GetNullableObjectAtIndex(args, 0); @@ -163,20 +156,19 @@ void FLTPlatformImagesApiSetup(id binaryMessenger, FLTPlatformImage *output = [api getPlatformImageName:arg_name error:&error]; callback(wrapResult(output, error)); }]; - } else { + } + else { [channel setMessageHandler:nil]; } } { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.PlatformImagesApi.resolveURL" + FlutterBasicMessageChannel *channel = + [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.PlatformImagesApi.resolveURL" binaryMessenger:binaryMessenger - codec:FLTPlatformImagesApiGetCodec()]; + codec:FLTPlatformImagesApiGetCodec() ]; if (api) { - NSCAssert([api respondsToSelector:@selector(resolveURLName:extension:error:)], - @"FLTPlatformImagesApi api (%@) doesn't respond to " - @"@selector(resolveURLName:extension:error:)", - api); + NSCAssert([api respondsToSelector:@selector(resolveURLName:extension:error:)], @"FLTPlatformImagesApi api (%@) doesn't respond to @selector(resolveURLName:extension:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; NSString *arg_name = GetNullableObjectAtIndex(args, 0); @@ -185,7 +177,8 @@ void FLTPlatformImagesApiSetup(id binaryMessenger, NSString *output = [api resolveURLName:arg_name extension:arg_extension error:&error]; callback(wrapResult(output, error)); }]; - } else { + } + else { [channel setMessageHandler:nil]; } } diff --git a/packages/ios_platform_images/lib/platform_images_api.g.dart b/packages/ios_platform_images/lib/platform_images_api.g.dart index 2ba4c7aaccc6..e121c2e3b180 100644 --- a/packages/ios_platform_images/lib/platform_images_api.g.dart +++ b/packages/ios_platform_images/lib/platform_images_api.g.dart @@ -1,13 +1,13 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v3.2.3), do not edit directly. +// Autogenerated from Pigeon (v4.2.1), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import import 'dart:async'; -import 'dart:typed_data' show Uint8List, Int32List, Int64List, Float64List; +import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; -import 'package:flutter/foundation.dart' show WriteBuffer, ReadBuffer; +import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; enum FontWeight { @@ -54,19 +54,20 @@ class _PlatformImagesApiCodec extends StandardMessageCodec { if (value is PlatformImage) { buffer.putUint8(128); writeValue(buffer, value.encode()); - } else { + } else +{ super.writeValue(buffer, value); } } - @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: + case 128: return PlatformImage.decode(readValue(buffer)!); - - default: + + default: return super.readValueOfType(type, buffer); + } } } @@ -75,37 +76,24 @@ class PlatformImagesApi { /// Constructor for [PlatformImagesApi]. The [binaryMessenger] named argument is /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. - PlatformImagesApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; + PlatformImagesApi({BinaryMessenger? binaryMessenger}) : _binaryMessenger = binaryMessenger; final BinaryMessenger? _binaryMessenger; static const MessageCodec codec = _PlatformImagesApiCodec(); - Future getSystemImage( - String arg_name, - double arg_size, - FontWeight arg_weight, - List arg_colorsRGBA, - bool arg_preferMulticolor) async { + Future getSystemImage(String arg_name, double arg_size, FontWeight arg_weight, List arg_colorsRGBA, bool arg_preferMulticolor) async { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.PlatformImagesApi.getSystemImage', codec, - binaryMessenger: _binaryMessenger); - final Map? replyMap = await channel.send([ - arg_name, - arg_size, - arg_weight.index, - arg_colorsRGBA, - arg_preferMulticolor - ]) as Map?; + 'dev.flutter.pigeon.PlatformImagesApi.getSystemImage', codec, binaryMessenger: _binaryMessenger); + final Map? replyMap = + await channel.send([arg_name, arg_size, arg_weight.index, arg_colorsRGBA, arg_preferMulticolor]) as Map?; if (replyMap == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + final Map error = (replyMap['error'] as Map?)!; throw PlatformException( code: (error['code'] as String?)!, message: error['message'] as String?, @@ -123,8 +111,7 @@ class PlatformImagesApi { Future getPlatformImage(String arg_name) async { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.PlatformImagesApi.getPlatformImage', codec, - binaryMessenger: _binaryMessenger); + 'dev.flutter.pigeon.PlatformImagesApi.getPlatformImage', codec, binaryMessenger: _binaryMessenger); final Map? replyMap = await channel.send([arg_name]) as Map?; if (replyMap == null) { @@ -133,8 +120,7 @@ class PlatformImagesApi { message: 'Unable to establish connection on channel.', ); } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + final Map error = (replyMap['error'] as Map?)!; throw PlatformException( code: (error['code'] as String?)!, message: error['message'] as String?, @@ -152,18 +138,16 @@ class PlatformImagesApi { Future resolveURL(String arg_name, String? arg_extension) async { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.PlatformImagesApi.resolveURL', codec, - binaryMessenger: _binaryMessenger); - final Map? replyMap = await channel - .send([arg_name, arg_extension]) as Map?; + 'dev.flutter.pigeon.PlatformImagesApi.resolveURL', codec, binaryMessenger: _binaryMessenger); + final Map? replyMap = + await channel.send([arg_name, arg_extension]) as Map?; if (replyMap == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + final Map error = (replyMap['error'] as Map?)!; throw PlatformException( code: (error['code'] as String?)!, message: error['message'] as String?, diff --git a/packages/ios_platform_images/pubspec.yaml b/packages/ios_platform_images/pubspec.yaml index 100fa752f112..b8a45a3477f0 100644 --- a/packages/ios_platform_images/pubspec.yaml +++ b/packages/ios_platform_images/pubspec.yaml @@ -27,4 +27,4 @@ dev_dependencies: sdk: flutter mockito: ^5.3.2 pedantic: ^1.10.0 - pigeon: ^4.2.0 + pigeon: ^4.2.1 From 6f7438d8584a94515c896f2de9b0bc719b3db23b Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Fri, 7 Oct 2022 09:23:38 -0700 Subject: [PATCH 44/64] Fix formatting & xcode-analyze --- .../ios/Classes/FLTPlatformImagesPlugin.m | 6 +- .../ios/Classes/PlatformImagesApi.g.h | 25 +++-- .../ios/Classes/PlatformImagesApi.g.m | 103 ++++++++++-------- .../lib/platform_images_api.g.dart | 52 ++++++--- 4 files changed, 111 insertions(+), 75 deletions(-) diff --git a/packages/ios_platform_images/ios/Classes/FLTPlatformImagesPlugin.m b/packages/ios_platform_images/ios/Classes/FLTPlatformImagesPlugin.m index 608799b2b106..bb25936d7db0 100644 --- a/packages/ios_platform_images/ios/Classes/FLTPlatformImagesPlugin.m +++ b/packages/ios_platform_images/ios/Classes/FLTPlatformImagesPlugin.m @@ -5,6 +5,9 @@ #import "FLTPlatformImagesPlugin.h" #import "PlatformImagesApi.g.h" +@interface FLTPlatformImagesPlugin () +@end + @implementation FLTPlatformImagesPlugin + (void)registerWithRegistrar:(NSObject *)registrar { @@ -62,7 +65,8 @@ - (nullable FLTPlatformImage *)getSystemImageName:(NSString *)name [image imageWithTintColor:colorArray.count > 0 ? colorArray[0] : [UIColor blackColor]]; } - NSData *data = UIImagePNGRepresentation(finalImage); + FlutterStandardTypedData *data = + [FlutterStandardTypedData typedDataWithBytes:UIImagePNGRepresentation(finalImage)]; return [FLTPlatformImage makeWithScale:@(finalImage.scale) bytes:data]; } return nil; diff --git a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h index 93717394f0d9..90ed3dd45690 100644 --- a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h +++ b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h @@ -27,22 +27,31 @@ typedef NS_ENUM(NSUInteger, FLTFontWeight) { @interface FLTPlatformImage : NSObject + (instancetype)makeWithScale:(nullable NSNumber *)scale - bytes:(nullable FlutterStandardTypedData *)bytes; -@property(nonatomic, strong, nullable) NSNumber * scale; -@property(nonatomic, strong, nullable) FlutterStandardTypedData * bytes; + bytes:(nullable FlutterStandardTypedData *)bytes; +@property(nonatomic, strong, nullable) NSNumber *scale; +@property(nonatomic, strong, nullable) FlutterStandardTypedData *bytes; @end -///The codec used by FLTPlatformImagesApi. +/// The codec used by FLTPlatformImagesApi. NSObject *FLTPlatformImagesApiGetCodec(void); @protocol FLTPlatformImagesApi /// @return `nil` only when `error != nil`. -- (nullable FLTPlatformImage *)getSystemImageName:(NSString *)name size:(NSNumber *)size weight:(FLTFontWeight)weight colorsRGBA:(NSArray *)colorsRGBA preferMulticolor:(NSNumber *)preferMulticolor error:(FlutterError *_Nullable *_Nonnull)error; +- (nullable FLTPlatformImage *)getSystemImageName:(NSString *)name + size:(NSNumber *)size + weight:(FLTFontWeight)weight + colorsRGBA:(NSArray *)colorsRGBA + preferMulticolor:(NSNumber *)preferMulticolor + error:(FlutterError *_Nullable *_Nonnull)error; /// @return `nil` only when `error != nil`. -- (nullable FLTPlatformImage *)getPlatformImageName:(NSString *)name error:(FlutterError *_Nullable *_Nonnull)error; -- (nullable NSString *)resolveURLName:(NSString *)name extension:(nullable NSString *)extension error:(FlutterError *_Nullable *_Nonnull)error; +- (nullable FLTPlatformImage *)getPlatformImageName:(NSString *)name + error:(FlutterError *_Nullable *_Nonnull)error; +- (nullable NSString *)resolveURLName:(NSString *)name + extension:(nullable NSString *)extension + error:(FlutterError *_Nullable *_Nonnull)error; @end -extern void FLTPlatformImagesApiSetup(id binaryMessenger, NSObject *_Nullable api); +extern void FLTPlatformImagesApiSetup(id binaryMessenger, + NSObject *_Nullable api); NS_ASSUME_NONNULL_END diff --git a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m index 385c56e355e4..c056ae4e58e1 100644 --- a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m +++ b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m @@ -14,26 +14,25 @@ NSDictionary *errorDict = (NSDictionary *)[NSNull null]; if (error) { errorDict = @{ - @"code": (error.code ?: [NSNull null]), - @"message": (error.message ?: [NSNull null]), - @"details": (error.details ?: [NSNull null]), - }; + @"code" : (error.code ?: [NSNull null]), + @"message" : (error.message ?: [NSNull null]), + @"details" : (error.details ?: [NSNull null]), + }; } return @{ - @"result": (result ?: [NSNull null]), - @"error": errorDict, - }; + @"result" : (result ?: [NSNull null]), + @"error" : errorDict, + }; } -static id GetNullableObject(NSDictionary* dict, id key) { +static id GetNullableObject(NSDictionary *dict, id key) { id result = dict[key]; return (result == [NSNull null]) ? nil : result; } -static id GetNullableObjectAtIndex(NSArray* array, NSInteger key) { +static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) { id result = array[key]; return (result == [NSNull null]) ? nil : result; } - @interface FLTPlatformImage () + (FLTPlatformImage *)fromMap:(NSDictionary *)dict; + (nullable FLTPlatformImage *)nullableFromMap:(NSDictionary *)dict; @@ -42,8 +41,8 @@ - (NSDictionary *)toMap; @implementation FLTPlatformImage + (instancetype)makeWithScale:(nullable NSNumber *)scale - bytes:(nullable FlutterStandardTypedData *)bytes { - FLTPlatformImage* pigeonResult = [[FLTPlatformImage alloc] init]; + bytes:(nullable FlutterStandardTypedData *)bytes { + FLTPlatformImage *pigeonResult = [[FLTPlatformImage alloc] init]; pigeonResult.scale = scale; pigeonResult.bytes = bytes; return pigeonResult; @@ -54,7 +53,9 @@ + (FLTPlatformImage *)fromMap:(NSDictionary *)dict { pigeonResult.bytes = GetNullableObject(dict, @"bytes"); return pigeonResult; } -+ (nullable FLTPlatformImage *)nullableFromMap:(NSDictionary *)dict { return (dict) ? [FLTPlatformImage fromMap:dict] : nil; } ++ (nullable FLTPlatformImage *)nullableFromMap:(NSDictionary *)dict { + return (dict) ? [FLTPlatformImage fromMap:dict] : nil; +} - (NSDictionary *)toMap { return @{ @"scale" : (self.scale ?: [NSNull null]), @@ -66,15 +67,13 @@ - (NSDictionary *)toMap { @interface FLTPlatformImagesApiCodecReader : FlutterStandardReader @end @implementation FLTPlatformImagesApiCodecReader -- (nullable id)readValueOfType:(UInt8)type -{ +- (nullable id)readValueOfType:(UInt8)type { switch (type) { - case 128: + case 128: return [FLTPlatformImage fromMap:[self readValue]]; - - default: + + default: return [super readValueOfType:type]; - } } @end @@ -82,13 +81,11 @@ - (nullable id)readValueOfType:(UInt8)type @interface FLTPlatformImagesApiCodecWriter : FlutterStandardWriter @end @implementation FLTPlatformImagesApiCodecWriter -- (void)writeValue:(id)value -{ +- (void)writeValue:(id)value { if ([value isKindOfClass:[FLTPlatformImage class]]) { [self writeByte:128]; [self writeValue:[value toMap]]; - } else -{ + } else { [super writeValue:value]; } } @@ -109,22 +106,26 @@ - (FlutterStandardReader *)readerWithData:(NSData *)data { static dispatch_once_t sPred = 0; static FlutterStandardMessageCodec *sSharedObject = nil; dispatch_once(&sPred, ^{ - FLTPlatformImagesApiCodecReaderWriter *readerWriter = [[FLTPlatformImagesApiCodecReaderWriter alloc] init]; + FLTPlatformImagesApiCodecReaderWriter *readerWriter = + [[FLTPlatformImagesApiCodecReaderWriter alloc] init]; sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; }); return sSharedObject; } - -void FLTPlatformImagesApiSetup(id binaryMessenger, NSObject *api) { +void FLTPlatformImagesApiSetup(id binaryMessenger, + NSObject *api) { { - FlutterBasicMessageChannel *channel = - [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.PlatformImagesApi.getSystemImage" + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.PlatformImagesApi.getSystemImage" binaryMessenger:binaryMessenger - codec:FLTPlatformImagesApiGetCodec() ]; + codec:FLTPlatformImagesApiGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(getSystemImageName:size:weight:colorsRGBA:preferMulticolor:error:)], @"FLTPlatformImagesApi api (%@) doesn't respond to @selector(getSystemImageName:size:weight:colorsRGBA:preferMulticolor:error:)", api); + NSCAssert([api respondsToSelector:@selector + (getSystemImageName:size:weight:colorsRGBA:preferMulticolor:error:)], + @"FLTPlatformImagesApi api (%@) doesn't respond to " + @"@selector(getSystemImageName:size:weight:colorsRGBA:preferMulticolor:error:)", + api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; NSString *arg_name = GetNullableObjectAtIndex(args, 0); @@ -133,22 +134,28 @@ void FLTPlatformImagesApiSetup(id binaryMessenger, NSObj NSArray *arg_colorsRGBA = GetNullableObjectAtIndex(args, 3); NSNumber *arg_preferMulticolor = GetNullableObjectAtIndex(args, 4); FlutterError *error; - FLTPlatformImage *output = [api getSystemImageName:arg_name size:arg_size weight:arg_weight colorsRGBA:arg_colorsRGBA preferMulticolor:arg_preferMulticolor error:&error]; + FLTPlatformImage *output = [api getSystemImageName:arg_name + size:arg_size + weight:arg_weight + colorsRGBA:arg_colorsRGBA + preferMulticolor:arg_preferMulticolor + error:&error]; callback(wrapResult(output, error)); }]; - } - else { + } else { [channel setMessageHandler:nil]; } } { - FlutterBasicMessageChannel *channel = - [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.PlatformImagesApi.getPlatformImage" + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.PlatformImagesApi.getPlatformImage" binaryMessenger:binaryMessenger - codec:FLTPlatformImagesApiGetCodec() ]; + codec:FLTPlatformImagesApiGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(getPlatformImageName:error:)], @"FLTPlatformImagesApi api (%@) doesn't respond to @selector(getPlatformImageName:error:)", api); + NSCAssert([api respondsToSelector:@selector(getPlatformImageName:error:)], + @"FLTPlatformImagesApi api (%@) doesn't respond to " + @"@selector(getPlatformImageName:error:)", + api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; NSString *arg_name = GetNullableObjectAtIndex(args, 0); @@ -156,19 +163,20 @@ void FLTPlatformImagesApiSetup(id binaryMessenger, NSObj FLTPlatformImage *output = [api getPlatformImageName:arg_name error:&error]; callback(wrapResult(output, error)); }]; - } - else { + } else { [channel setMessageHandler:nil]; } } { - FlutterBasicMessageChannel *channel = - [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.PlatformImagesApi.resolveURL" + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.PlatformImagesApi.resolveURL" binaryMessenger:binaryMessenger - codec:FLTPlatformImagesApiGetCodec() ]; + codec:FLTPlatformImagesApiGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(resolveURLName:extension:error:)], @"FLTPlatformImagesApi api (%@) doesn't respond to @selector(resolveURLName:extension:error:)", api); + NSCAssert([api respondsToSelector:@selector(resolveURLName:extension:error:)], + @"FLTPlatformImagesApi api (%@) doesn't respond to " + @"@selector(resolveURLName:extension:error:)", + api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; NSString *arg_name = GetNullableObjectAtIndex(args, 0); @@ -177,8 +185,7 @@ void FLTPlatformImagesApiSetup(id binaryMessenger, NSObj NSString *output = [api resolveURLName:arg_name extension:arg_extension error:&error]; callback(wrapResult(output, error)); }]; - } - else { + } else { [channel setMessageHandler:nil]; } } diff --git a/packages/ios_platform_images/lib/platform_images_api.g.dart b/packages/ios_platform_images/lib/platform_images_api.g.dart index e121c2e3b180..10929d478624 100644 --- a/packages/ios_platform_images/lib/platform_images_api.g.dart +++ b/packages/ios_platform_images/lib/platform_images_api.g.dart @@ -54,20 +54,19 @@ class _PlatformImagesApiCodec extends StandardMessageCodec { if (value is PlatformImage) { buffer.putUint8(128); writeValue(buffer, value.encode()); - } else -{ + } else { super.writeValue(buffer, value); } } + @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: + case 128: return PlatformImage.decode(readValue(buffer)!); - - default: + + default: return super.readValueOfType(type, buffer); - } } } @@ -76,24 +75,37 @@ class PlatformImagesApi { /// Constructor for [PlatformImagesApi]. The [binaryMessenger] named argument is /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. - PlatformImagesApi({BinaryMessenger? binaryMessenger}) : _binaryMessenger = binaryMessenger; + PlatformImagesApi({BinaryMessenger? binaryMessenger}) + : _binaryMessenger = binaryMessenger; final BinaryMessenger? _binaryMessenger; static const MessageCodec codec = _PlatformImagesApiCodec(); - Future getSystemImage(String arg_name, double arg_size, FontWeight arg_weight, List arg_colorsRGBA, bool arg_preferMulticolor) async { + Future getSystemImage( + String arg_name, + double arg_size, + FontWeight arg_weight, + List arg_colorsRGBA, + bool arg_preferMulticolor) async { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.PlatformImagesApi.getSystemImage', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_name, arg_size, arg_weight.index, arg_colorsRGBA, arg_preferMulticolor]) as Map?; + 'dev.flutter.pigeon.PlatformImagesApi.getSystemImage', codec, + binaryMessenger: _binaryMessenger); + final Map? replyMap = await channel.send([ + arg_name, + arg_size, + arg_weight.index, + arg_colorsRGBA, + arg_preferMulticolor + ]) as Map?; if (replyMap == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); } else if (replyMap['error'] != null) { - final Map error = (replyMap['error'] as Map?)!; + final Map error = + (replyMap['error'] as Map?)!; throw PlatformException( code: (error['code'] as String?)!, message: error['message'] as String?, @@ -111,7 +123,8 @@ class PlatformImagesApi { Future getPlatformImage(String arg_name) async { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.PlatformImagesApi.getPlatformImage', codec, binaryMessenger: _binaryMessenger); + 'dev.flutter.pigeon.PlatformImagesApi.getPlatformImage', codec, + binaryMessenger: _binaryMessenger); final Map? replyMap = await channel.send([arg_name]) as Map?; if (replyMap == null) { @@ -120,7 +133,8 @@ class PlatformImagesApi { message: 'Unable to establish connection on channel.', ); } else if (replyMap['error'] != null) { - final Map error = (replyMap['error'] as Map?)!; + final Map error = + (replyMap['error'] as Map?)!; throw PlatformException( code: (error['code'] as String?)!, message: error['message'] as String?, @@ -138,16 +152,18 @@ class PlatformImagesApi { Future resolveURL(String arg_name, String? arg_extension) async { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.PlatformImagesApi.resolveURL', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_name, arg_extension]) as Map?; + 'dev.flutter.pigeon.PlatformImagesApi.resolveURL', codec, + binaryMessenger: _binaryMessenger); + final Map? replyMap = await channel + .send([arg_name, arg_extension]) as Map?; if (replyMap == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); } else if (replyMap['error'] != null) { - final Map error = (replyMap['error'] as Map?)!; + final Map error = + (replyMap['error'] as Map?)!; throw PlatformException( code: (error['code'] as String?)!, message: error['message'] as String?, From 1a650298b889c6277002f61147dfcf6eee4a40b4 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Sun, 11 Dec 2022 11:28:07 -0700 Subject: [PATCH 45/64] Fix Uint8List import --- packages/ios_platform_images/lib/ios_platform_images.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/ios_platform_images/lib/ios_platform_images.dart b/packages/ios_platform_images/lib/ios_platform_images.dart index 20ce9b67d317..a9dc508afb87 100644 --- a/packages/ios_platform_images/lib/ios_platform_images.dart +++ b/packages/ios_platform_images/lib/ios_platform_images.dart @@ -3,6 +3,7 @@ // found in the LICENSE file. import 'dart:async'; +import 'dart:typed_data'; import 'dart:ui' as ui; import 'package:flutter/foundation.dart' From a6dd9e8638a6f83910e22f13ebe54a0ce7f15ecc Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Sun, 11 Dec 2022 11:36:13 -0700 Subject: [PATCH 46/64] Regenerate Pigeon files --- .../ios/Classes/PlatformImagesApi.g.h | 25 ++-- .../ios/Classes/PlatformImagesApi.g.m | 107 ++++++++---------- .../lib/platform_images_api.g.dart | 57 ++++------ packages/ios_platform_images/pubspec.yaml | 2 +- 4 files changed, 79 insertions(+), 112 deletions(-) diff --git a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h index 90ed3dd45690..04aeceb7b65e 100644 --- a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h +++ b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v4.2.1), do not edit directly. +// Autogenerated from Pigeon (v4.2.10), do not edit directly. // See also: https://pub.dev/packages/pigeon #import @protocol FlutterBinaryMessenger; @@ -27,9 +27,9 @@ typedef NS_ENUM(NSUInteger, FLTFontWeight) { @interface FLTPlatformImage : NSObject + (instancetype)makeWithScale:(nullable NSNumber *)scale - bytes:(nullable FlutterStandardTypedData *)bytes; -@property(nonatomic, strong, nullable) NSNumber *scale; -@property(nonatomic, strong, nullable) FlutterStandardTypedData *bytes; + bytes:(nullable FlutterStandardTypedData *)bytes; +@property(nonatomic, strong, nullable) NSNumber * scale; +@property(nonatomic, strong, nullable) FlutterStandardTypedData * bytes; @end /// The codec used by FLTPlatformImagesApi. @@ -37,21 +37,12 @@ NSObject *FLTPlatformImagesApiGetCodec(void); @protocol FLTPlatformImagesApi /// @return `nil` only when `error != nil`. -- (nullable FLTPlatformImage *)getSystemImageName:(NSString *)name - size:(NSNumber *)size - weight:(FLTFontWeight)weight - colorsRGBA:(NSArray *)colorsRGBA - preferMulticolor:(NSNumber *)preferMulticolor - error:(FlutterError *_Nullable *_Nonnull)error; +- (nullable FLTPlatformImage *)getSystemImageName:(NSString *)name size:(NSNumber *)size weight:(FLTFontWeight)weight colorsRGBA:(NSArray *)colorsRGBA preferMulticolor:(NSNumber *)preferMulticolor error:(FlutterError *_Nullable *_Nonnull)error; /// @return `nil` only when `error != nil`. -- (nullable FLTPlatformImage *)getPlatformImageName:(NSString *)name - error:(FlutterError *_Nullable *_Nonnull)error; -- (nullable NSString *)resolveURLName:(NSString *)name - extension:(nullable NSString *)extension - error:(FlutterError *_Nullable *_Nonnull)error; +- (nullable FLTPlatformImage *)getPlatformImageName:(NSString *)name error:(FlutterError *_Nullable *_Nonnull)error; +- (nullable NSString *)resolveURLName:(NSString *)name extension:(nullable NSString *)extension error:(FlutterError *_Nullable *_Nonnull)error; @end -extern void FLTPlatformImagesApiSetup(id binaryMessenger, - NSObject *_Nullable api); +extern void FLTPlatformImagesApiSetup(id binaryMessenger, NSObject *_Nullable api); NS_ASSUME_NONNULL_END diff --git a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m index c056ae4e58e1..0720406fdc1d 100644 --- a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m +++ b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v4.2.1), do not edit directly. +// Autogenerated from Pigeon (v4.2.10), do not edit directly. // See also: https://pub.dev/packages/pigeon #import "PlatformImagesApi.g.h" #import @@ -14,25 +14,26 @@ NSDictionary *errorDict = (NSDictionary *)[NSNull null]; if (error) { errorDict = @{ - @"code" : (error.code ?: [NSNull null]), - @"message" : (error.message ?: [NSNull null]), - @"details" : (error.details ?: [NSNull null]), - }; + @"code": (error.code ?: [NSNull null]), + @"message": (error.message ?: [NSNull null]), + @"details": (error.details ?: [NSNull null]), + }; } return @{ - @"result" : (result ?: [NSNull null]), - @"error" : errorDict, - }; + @"result": (result ?: [NSNull null]), + @"error": errorDict, + }; } -static id GetNullableObject(NSDictionary *dict, id key) { +static id GetNullableObject(NSDictionary* dict, id key) { id result = dict[key]; return (result == [NSNull null]) ? nil : result; } -static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) { +static id GetNullableObjectAtIndex(NSArray* array, NSInteger key) { id result = array[key]; return (result == [NSNull null]) ? nil : result; } + @interface FLTPlatformImage () + (FLTPlatformImage *)fromMap:(NSDictionary *)dict; + (nullable FLTPlatformImage *)nullableFromMap:(NSDictionary *)dict; @@ -41,8 +42,8 @@ - (NSDictionary *)toMap; @implementation FLTPlatformImage + (instancetype)makeWithScale:(nullable NSNumber *)scale - bytes:(nullable FlutterStandardTypedData *)bytes { - FLTPlatformImage *pigeonResult = [[FLTPlatformImage alloc] init]; + bytes:(nullable FlutterStandardTypedData *)bytes { + FLTPlatformImage* pigeonResult = [[FLTPlatformImage alloc] init]; pigeonResult.scale = scale; pigeonResult.bytes = bytes; return pigeonResult; @@ -53,9 +54,7 @@ + (FLTPlatformImage *)fromMap:(NSDictionary *)dict { pigeonResult.bytes = GetNullableObject(dict, @"bytes"); return pigeonResult; } -+ (nullable FLTPlatformImage *)nullableFromMap:(NSDictionary *)dict { - return (dict) ? [FLTPlatformImage fromMap:dict] : nil; -} ++ (nullable FLTPlatformImage *)nullableFromMap:(NSDictionary *)dict { return (dict) ? [FLTPlatformImage fromMap:dict] : nil; } - (NSDictionary *)toMap { return @{ @"scale" : (self.scale ?: [NSNull null]), @@ -67,13 +66,15 @@ - (NSDictionary *)toMap { @interface FLTPlatformImagesApiCodecReader : FlutterStandardReader @end @implementation FLTPlatformImagesApiCodecReader -- (nullable id)readValueOfType:(UInt8)type { +- (nullable id)readValueOfType:(UInt8)type +{ switch (type) { - case 128: + case 128: return [FLTPlatformImage fromMap:[self readValue]]; - - default: + + default: return [super readValueOfType:type]; + } } @end @@ -81,11 +82,13 @@ - (nullable id)readValueOfType:(UInt8)type { @interface FLTPlatformImagesApiCodecWriter : FlutterStandardWriter @end @implementation FLTPlatformImagesApiCodecWriter -- (void)writeValue:(id)value { +- (void)writeValue:(id)value +{ if ([value isKindOfClass:[FLTPlatformImage class]]) { [self writeByte:128]; [self writeValue:[value toMap]]; - } else { + } else +{ [super writeValue:value]; } } @@ -102,30 +105,26 @@ - (FlutterStandardReader *)readerWithData:(NSData *)data { } @end + NSObject *FLTPlatformImagesApiGetCodec() { - static dispatch_once_t sPred = 0; static FlutterStandardMessageCodec *sSharedObject = nil; + static dispatch_once_t sPred = 0; dispatch_once(&sPred, ^{ - FLTPlatformImagesApiCodecReaderWriter *readerWriter = - [[FLTPlatformImagesApiCodecReaderWriter alloc] init]; + FLTPlatformImagesApiCodecReaderWriter *readerWriter = [[FLTPlatformImagesApiCodecReaderWriter alloc] init]; sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; }); return sSharedObject; } -void FLTPlatformImagesApiSetup(id binaryMessenger, - NSObject *api) { +void FLTPlatformImagesApiSetup(id binaryMessenger, NSObject *api) { { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.PlatformImagesApi.getSystemImage" + FlutterBasicMessageChannel *channel = + [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.PlatformImagesApi.getSystemImage" binaryMessenger:binaryMessenger - codec:FLTPlatformImagesApiGetCodec()]; + codec:FLTPlatformImagesApiGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector - (getSystemImageName:size:weight:colorsRGBA:preferMulticolor:error:)], - @"FLTPlatformImagesApi api (%@) doesn't respond to " - @"@selector(getSystemImageName:size:weight:colorsRGBA:preferMulticolor:error:)", - api); + NSCAssert([api respondsToSelector:@selector(getSystemImageName:size:weight:colorsRGBA:preferMulticolor:error:)], @"FLTPlatformImagesApi api (%@) doesn't respond to @selector(getSystemImageName:size:weight:colorsRGBA:preferMulticolor:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; NSString *arg_name = GetNullableObjectAtIndex(args, 0); @@ -134,28 +133,22 @@ void FLTPlatformImagesApiSetup(id binaryMessenger, NSArray *arg_colorsRGBA = GetNullableObjectAtIndex(args, 3); NSNumber *arg_preferMulticolor = GetNullableObjectAtIndex(args, 4); FlutterError *error; - FLTPlatformImage *output = [api getSystemImageName:arg_name - size:arg_size - weight:arg_weight - colorsRGBA:arg_colorsRGBA - preferMulticolor:arg_preferMulticolor - error:&error]; + FLTPlatformImage *output = [api getSystemImageName:arg_name size:arg_size weight:arg_weight colorsRGBA:arg_colorsRGBA preferMulticolor:arg_preferMulticolor error:&error]; callback(wrapResult(output, error)); }]; - } else { + } + else { [channel setMessageHandler:nil]; } } { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.PlatformImagesApi.getPlatformImage" + FlutterBasicMessageChannel *channel = + [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.PlatformImagesApi.getPlatformImage" binaryMessenger:binaryMessenger - codec:FLTPlatformImagesApiGetCodec()]; + codec:FLTPlatformImagesApiGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(getPlatformImageName:error:)], - @"FLTPlatformImagesApi api (%@) doesn't respond to " - @"@selector(getPlatformImageName:error:)", - api); + NSCAssert([api respondsToSelector:@selector(getPlatformImageName:error:)], @"FLTPlatformImagesApi api (%@) doesn't respond to @selector(getPlatformImageName:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; NSString *arg_name = GetNullableObjectAtIndex(args, 0); @@ -163,20 +156,19 @@ void FLTPlatformImagesApiSetup(id binaryMessenger, FLTPlatformImage *output = [api getPlatformImageName:arg_name error:&error]; callback(wrapResult(output, error)); }]; - } else { + } + else { [channel setMessageHandler:nil]; } } { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.PlatformImagesApi.resolveURL" + FlutterBasicMessageChannel *channel = + [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.PlatformImagesApi.resolveURL" binaryMessenger:binaryMessenger - codec:FLTPlatformImagesApiGetCodec()]; + codec:FLTPlatformImagesApiGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(resolveURLName:extension:error:)], - @"FLTPlatformImagesApi api (%@) doesn't respond to " - @"@selector(resolveURLName:extension:error:)", - api); + NSCAssert([api respondsToSelector:@selector(resolveURLName:extension:error:)], @"FLTPlatformImagesApi api (%@) doesn't respond to @selector(resolveURLName:extension:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; NSString *arg_name = GetNullableObjectAtIndex(args, 0); @@ -185,7 +177,8 @@ void FLTPlatformImagesApiSetup(id binaryMessenger, NSString *output = [api resolveURLName:arg_name extension:arg_extension error:&error]; callback(wrapResult(output, error)); }]; - } else { + } + else { [channel setMessageHandler:nil]; } } diff --git a/packages/ios_platform_images/lib/platform_images_api.g.dart b/packages/ios_platform_images/lib/platform_images_api.g.dart index 10929d478624..651e6cb8df4c 100644 --- a/packages/ios_platform_images/lib/platform_images_api.g.dart +++ b/packages/ios_platform_images/lib/platform_images_api.g.dart @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v4.2.1), do not edit directly. +// Autogenerated from Pigeon (v4.2.10), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import import 'dart:async'; @@ -47,26 +47,27 @@ class PlatformImage { } } -class _PlatformImagesApiCodec extends StandardMessageCodec { +class _PlatformImagesApiCodec extends StandardMessageCodec{ const _PlatformImagesApiCodec(); @override void writeValue(WriteBuffer buffer, Object? value) { if (value is PlatformImage) { buffer.putUint8(128); writeValue(buffer, value.encode()); - } else { + } else +{ super.writeValue(buffer, value); } } - @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: + case 128: return PlatformImage.decode(readValue(buffer)!); - - default: + + default: return super.readValueOfType(type, buffer); + } } } @@ -75,37 +76,23 @@ class PlatformImagesApi { /// Constructor for [PlatformImagesApi]. The [binaryMessenger] named argument is /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. - PlatformImagesApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - + PlatformImagesApi({BinaryMessenger? binaryMessenger}) : _binaryMessenger = binaryMessenger; final BinaryMessenger? _binaryMessenger; static const MessageCodec codec = _PlatformImagesApiCodec(); - Future getSystemImage( - String arg_name, - double arg_size, - FontWeight arg_weight, - List arg_colorsRGBA, - bool arg_preferMulticolor) async { + Future getSystemImage(String arg_name, double arg_size, FontWeight arg_weight, List arg_colorsRGBA, bool arg_preferMulticolor) async { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.PlatformImagesApi.getSystemImage', codec, - binaryMessenger: _binaryMessenger); - final Map? replyMap = await channel.send([ - arg_name, - arg_size, - arg_weight.index, - arg_colorsRGBA, - arg_preferMulticolor - ]) as Map?; + 'dev.flutter.pigeon.PlatformImagesApi.getSystemImage', codec, binaryMessenger: _binaryMessenger); + final Map? replyMap = + await channel.send([arg_name, arg_size, arg_weight.index, arg_colorsRGBA, arg_preferMulticolor]) as Map?; if (replyMap == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + final Map error = (replyMap['error'] as Map?)!; throw PlatformException( code: (error['code'] as String?)!, message: error['message'] as String?, @@ -123,8 +110,7 @@ class PlatformImagesApi { Future getPlatformImage(String arg_name) async { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.PlatformImagesApi.getPlatformImage', codec, - binaryMessenger: _binaryMessenger); + 'dev.flutter.pigeon.PlatformImagesApi.getPlatformImage', codec, binaryMessenger: _binaryMessenger); final Map? replyMap = await channel.send([arg_name]) as Map?; if (replyMap == null) { @@ -133,8 +119,7 @@ class PlatformImagesApi { message: 'Unable to establish connection on channel.', ); } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + final Map error = (replyMap['error'] as Map?)!; throw PlatformException( code: (error['code'] as String?)!, message: error['message'] as String?, @@ -152,18 +137,16 @@ class PlatformImagesApi { Future resolveURL(String arg_name, String? arg_extension) async { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.PlatformImagesApi.resolveURL', codec, - binaryMessenger: _binaryMessenger); - final Map? replyMap = await channel - .send([arg_name, arg_extension]) as Map?; + 'dev.flutter.pigeon.PlatformImagesApi.resolveURL', codec, binaryMessenger: _binaryMessenger); + final Map? replyMap = + await channel.send([arg_name, arg_extension]) as Map?; if (replyMap == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + final Map error = (replyMap['error'] as Map?)!; throw PlatformException( code: (error['code'] as String?)!, message: error['message'] as String?, diff --git a/packages/ios_platform_images/pubspec.yaml b/packages/ios_platform_images/pubspec.yaml index b8a45a3477f0..7a96d49d8356 100644 --- a/packages/ios_platform_images/pubspec.yaml +++ b/packages/ios_platform_images/pubspec.yaml @@ -27,4 +27,4 @@ dev_dependencies: sdk: flutter mockito: ^5.3.2 pedantic: ^1.10.0 - pigeon: ^4.2.1 + pigeon: ^4.2.10 From c36dcc03835a89243acc36ae796ca4682b3dfa2f Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Mon, 2 Jan 2023 02:48:05 -0700 Subject: [PATCH 47/64] Ignore avoid print in example app --- packages/ios_platform_images/example/lib/main.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/ios_platform_images/example/lib/main.dart b/packages/ios_platform_images/example/lib/main.dart index b0839f895836..0b433fb87c80 100644 --- a/packages/ios_platform_images/example/lib/main.dart +++ b/packages/ios_platform_images/example/lib/main.dart @@ -22,6 +22,7 @@ class _MyAppState extends State { super.initState(); IosPlatformImages.resolveURL('textfile') + // ignore: avoid_print .then((String? value) => print(value)); } From c763486c101d48a3cbf4ecf4e7d89852a460db8d Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Mon, 2 Jan 2023 02:58:39 -0700 Subject: [PATCH 48/64] Update pigeon --- .../ios/Classes/PlatformImagesApi.g.h | 2 +- .../ios/Classes/PlatformImagesApi.g.m | 44 ++++----- .../lib/platform_images_api.g.dart | 95 ++++++++++--------- packages/ios_platform_images/pubspec.yaml | 2 +- 4 files changed, 69 insertions(+), 74 deletions(-) diff --git a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h index 04aeceb7b65e..15d702cc4a1a 100644 --- a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h +++ b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v4.2.10), do not edit directly. +// Autogenerated from Pigeon (v4.2.14), do not edit directly. // See also: https://pub.dev/packages/pigeon #import @protocol FlutterBinaryMessenger; diff --git a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m index 0720406fdc1d..21b3091b059a 100644 --- a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m +++ b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v4.2.10), do not edit directly. +// Autogenerated from Pigeon (v4.2.14), do not edit directly. // See also: https://pub.dev/packages/pigeon #import "PlatformImagesApi.g.h" #import @@ -10,19 +10,11 @@ #error File requires ARC to be enabled. #endif -static NSDictionary *wrapResult(id result, FlutterError *error) { - NSDictionary *errorDict = (NSDictionary *)[NSNull null]; +static NSArray *wrapResult(id result, FlutterError *error) { if (error) { - errorDict = @{ - @"code": (error.code ?: [NSNull null]), - @"message": (error.message ?: [NSNull null]), - @"details": (error.details ?: [NSNull null]), - }; + return @[ error.code ?: [NSNull null], error.message ?: [NSNull null], error.details ?: [NSNull null] ]; } - return @{ - @"result": (result ?: [NSNull null]), - @"error": errorDict, - }; + return @[ result ?: [NSNull null] ]; } static id GetNullableObject(NSDictionary* dict, id key) { id result = dict[key]; @@ -35,9 +27,9 @@ static id GetNullableObjectAtIndex(NSArray* array, NSInteger key) { @interface FLTPlatformImage () -+ (FLTPlatformImage *)fromMap:(NSDictionary *)dict; -+ (nullable FLTPlatformImage *)nullableFromMap:(NSDictionary *)dict; -- (NSDictionary *)toMap; ++ (FLTPlatformImage *)fromList:(NSArray *)list; ++ (nullable FLTPlatformImage *)nullableFromList:(NSArray *)list; +- (NSArray *)toList; @end @implementation FLTPlatformImage @@ -48,18 +40,18 @@ + (instancetype)makeWithScale:(nullable NSNumber *)scale pigeonResult.bytes = bytes; return pigeonResult; } -+ (FLTPlatformImage *)fromMap:(NSDictionary *)dict { ++ (FLTPlatformImage *)fromList:(NSArray *)list { FLTPlatformImage *pigeonResult = [[FLTPlatformImage alloc] init]; - pigeonResult.scale = GetNullableObject(dict, @"scale"); - pigeonResult.bytes = GetNullableObject(dict, @"bytes"); + pigeonResult.scale = GetNullableObjectAtIndex(list, 0); + pigeonResult.bytes = GetNullableObjectAtIndex(list, 1); return pigeonResult; } -+ (nullable FLTPlatformImage *)nullableFromMap:(NSDictionary *)dict { return (dict) ? [FLTPlatformImage fromMap:dict] : nil; } -- (NSDictionary *)toMap { - return @{ - @"scale" : (self.scale ?: [NSNull null]), - @"bytes" : (self.bytes ?: [NSNull null]), - }; ++ (nullable FLTPlatformImage *)nullableFromList:(NSArray *)list { return (list) ? [FLTPlatformImage fromList:list] : nil; } +- (NSArray *)toList { + return @[ + (self.scale ?: [NSNull null]), + (self.bytes ?: [NSNull null]), + ]; } @end @@ -70,7 +62,7 @@ - (nullable id)readValueOfType:(UInt8)type { switch (type) { case 128: - return [FLTPlatformImage fromMap:[self readValue]]; + return [FLTPlatformImage fromList:[self readValue]]; default: return [super readValueOfType:type]; @@ -86,7 +78,7 @@ - (void)writeValue:(id)value { if ([value isKindOfClass:[FLTPlatformImage class]]) { [self writeByte:128]; - [self writeValue:[value toMap]]; + [self writeValue:[value toList]]; } else { [super writeValue:value]; diff --git a/packages/ios_platform_images/lib/platform_images_api.g.dart b/packages/ios_platform_images/lib/platform_images_api.g.dart index 651e6cb8df4c..6a540d2e7a91 100644 --- a/packages/ios_platform_images/lib/platform_images_api.g.dart +++ b/packages/ios_platform_images/lib/platform_images_api.g.dart @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v4.2.10), do not edit directly. +// Autogenerated from Pigeon (v4.2.14), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import import 'dart:async'; @@ -29,43 +29,45 @@ class PlatformImage { }); double? scale; + Uint8List? bytes; Object encode() { - final Map pigeonMap = {}; - pigeonMap['scale'] = scale; - pigeonMap['bytes'] = bytes; - return pigeonMap; + return [ + scale, + bytes, + ]; } - static PlatformImage decode(Object message) { - final Map pigeonMap = message as Map; + static PlatformImage decode(Object result) { + result as List; return PlatformImage( - scale: pigeonMap['scale'] as double?, - bytes: pigeonMap['bytes'] as Uint8List?, + scale: result[0] as double?, + bytes: result[1] as Uint8List?, ); } } -class _PlatformImagesApiCodec extends StandardMessageCodec{ +class _PlatformImagesApiCodec extends StandardMessageCodec { const _PlatformImagesApiCodec(); @override void writeValue(WriteBuffer buffer, Object? value) { if (value is PlatformImage) { buffer.putUint8(128); writeValue(buffer, value.encode()); - } else -{ + } else { super.writeValue(buffer, value); } } + @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { case 128: return PlatformImage.decode(readValue(buffer)!); - default: + default: + return super.readValueOfType(type, buffer); } @@ -76,84 +78,85 @@ class PlatformImagesApi { /// Constructor for [PlatformImagesApi]. The [binaryMessenger] named argument is /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. - PlatformImagesApi({BinaryMessenger? binaryMessenger}) : _binaryMessenger = binaryMessenger; + PlatformImagesApi({BinaryMessenger? binaryMessenger}) + : _binaryMessenger = binaryMessenger; final BinaryMessenger? _binaryMessenger; static const MessageCodec codec = _PlatformImagesApiCodec(); Future getSystemImage(String arg_name, double arg_size, FontWeight arg_weight, List arg_colorsRGBA, bool arg_preferMulticolor) async { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.PlatformImagesApi.getSystemImage', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_name, arg_size, arg_weight.index, arg_colorsRGBA, arg_preferMulticolor]) as Map?; - if (replyMap == null) { + 'dev.flutter.pigeon.PlatformImagesApi.getSystemImage', codec, + binaryMessenger: _binaryMessenger); + final List? replyList = + await channel.send([arg_name, arg_size, arg_weight.index, arg_colorsRGBA, arg_preferMulticolor]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as PlatformImage?)!; + return (replyList[0] as PlatformImage?)!; } } Future getPlatformImage(String arg_name) async { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.PlatformImagesApi.getPlatformImage', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_name]) as Map?; - if (replyMap == null) { + 'dev.flutter.pigeon.PlatformImagesApi.getPlatformImage', codec, + binaryMessenger: _binaryMessenger); + final List? replyList = + await channel.send([arg_name]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as PlatformImage?)!; + return (replyList[0] as PlatformImage?)!; } } Future resolveURL(String arg_name, String? arg_extension) async { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.PlatformImagesApi.resolveURL', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_name, arg_extension]) as Map?; - if (replyMap == null) { + 'dev.flutter.pigeon.PlatformImagesApi.resolveURL', codec, + binaryMessenger: _binaryMessenger); + final List? replyList = + await channel.send([arg_name, arg_extension]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { - return (replyMap['result'] as String?); + return (replyList[0] as String?); } } } diff --git a/packages/ios_platform_images/pubspec.yaml b/packages/ios_platform_images/pubspec.yaml index 7a96d49d8356..2abb7b130a9a 100644 --- a/packages/ios_platform_images/pubspec.yaml +++ b/packages/ios_platform_images/pubspec.yaml @@ -27,4 +27,4 @@ dev_dependencies: sdk: flutter mockito: ^5.3.2 pedantic: ^1.10.0 - pigeon: ^4.2.10 + pigeon: ^4.2.14 From 544259024c96562fee108220475474f35e05a3e0 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Mon, 2 Jan 2023 02:59:39 -0700 Subject: [PATCH 49/64] Bump version and fix changelog --- packages/ios_platform_images/CHANGELOG.md | 8 ++++---- packages/ios_platform_images/pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/ios_platform_images/CHANGELOG.md b/packages/ios_platform_images/CHANGELOG.md index 101a73de8120..f489a677d9a5 100644 --- a/packages/ios_platform_images/CHANGELOG.md +++ b/packages/ios_platform_images/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.2.2 + +* Adds `loadSystemImage` to load system images, also known as 'sfsymbols'. + ## 0.2.1+1 * Add lint ignore comments @@ -8,10 +12,6 @@ * Removes usage of deprecated [ImageProvider.load]. * Ignores unnecessary import warnings in preparation for [upcoming Flutter changes](https://github.com/flutter/flutter/pull/106316). -## 0.2.1 - -* Adds `loadSystemImage` to load system images, also known as 'sfsymbols'. - ## 0.2.0+9 * Ignores the warning for the upcoming deprecation of `DecoderCallback`. diff --git a/packages/ios_platform_images/pubspec.yaml b/packages/ios_platform_images/pubspec.yaml index 2abb7b130a9a..8f5637bd39f7 100644 --- a/packages/ios_platform_images/pubspec.yaml +++ b/packages/ios_platform_images/pubspec.yaml @@ -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.1+1 +version: 0.2.2 environment: sdk: ">=2.14.0 <3.0.0" From c2f46363ecbaaa977060d263b05bce5627a5ecfe Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Thu, 26 Jan 2023 03:16:31 -0700 Subject: [PATCH 50/64] Update to pigeon 7.0.5 --- .../ios/Classes/PlatformImagesApi.g.h | 4 +- .../ios/Classes/PlatformImagesApi.g.m | 43 ++++++++----------- .../lib/platform_images_api.g.dart | 8 ++-- packages/ios_platform_images/pubspec.yaml | 2 +- 4 files changed, 26 insertions(+), 31 deletions(-) diff --git a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h index 15d702cc4a1a..4de20e8e3db8 100644 --- a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h +++ b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h @@ -1,9 +1,11 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v4.2.14), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon + #import + @protocol FlutterBinaryMessenger; @protocol FlutterMessageCodec; @class FlutterError; diff --git a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m index 21b3091b059a..047f65af28c3 100644 --- a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m +++ b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m @@ -1,8 +1,9 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v4.2.14), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon + #import "PlatformImagesApi.g.h" #import @@ -12,20 +13,21 @@ static NSArray *wrapResult(id result, FlutterError *error) { if (error) { - return @[ error.code ?: [NSNull null], error.message ?: [NSNull null], error.details ?: [NSNull null] ]; + return @[ + error.code ?: [NSNull null], error.message ?: [NSNull null], error.details ?: [NSNull null] + ]; } - return @[ result ?: [NSNull null] ]; + return @[ result ?: [NSNull null] ]; } -static id GetNullableObject(NSDictionary* dict, id key) { +static id GetNullableObject(NSDictionary *dict, id key) { id result = dict[key]; return (result == [NSNull null]) ? nil : result; } -static id GetNullableObjectAtIndex(NSArray* array, NSInteger key) { +static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) { id result = array[key]; return (result == [NSNull null]) ? nil : result; } - @interface FLTPlatformImage () + (FLTPlatformImage *)fromList:(NSArray *)list; + (nullable FLTPlatformImage *)nullableFromList:(NSArray *)list; @@ -46,7 +48,9 @@ + (FLTPlatformImage *)fromList:(NSArray *)list { pigeonResult.bytes = GetNullableObjectAtIndex(list, 1); return pigeonResult; } -+ (nullable FLTPlatformImage *)nullableFromList:(NSArray *)list { return (list) ? [FLTPlatformImage fromList:list] : nil; } ++ (nullable FLTPlatformImage *)nullableFromList:(NSArray *)list { + return (list) ? [FLTPlatformImage fromList:list] : nil; +} - (NSArray *)toList { return @[ (self.scale ?: [NSNull null]), @@ -58,15 +62,12 @@ - (NSArray *)toList { @interface FLTPlatformImagesApiCodecReader : FlutterStandardReader @end @implementation FLTPlatformImagesApiCodecReader -- (nullable id)readValueOfType:(UInt8)type -{ +- (nullable id)readValueOfType:(UInt8)type { switch (type) { - case 128: + case 128: return [FLTPlatformImage fromList:[self readValue]]; - - default: + default: return [super readValueOfType:type]; - } } @end @@ -74,13 +75,11 @@ - (nullable id)readValueOfType:(UInt8)type @interface FLTPlatformImagesApiCodecWriter : FlutterStandardWriter @end @implementation FLTPlatformImagesApiCodecWriter -- (void)writeValue:(id)value -{ +- (void)writeValue:(id)value { if ([value isKindOfClass:[FLTPlatformImage class]]) { [self writeByte:128]; [self writeValue:[value toList]]; - } else -{ + } else { [super writeValue:value]; } } @@ -97,7 +96,6 @@ - (FlutterStandardReader *)readerWithData:(NSData *)data { } @end - NSObject *FLTPlatformImagesApiGetCodec() { static FlutterStandardMessageCodec *sSharedObject = nil; static dispatch_once_t sPred = 0; @@ -128,8 +126,7 @@ void FLTPlatformImagesApiSetup(id binaryMessenger, NSObj FLTPlatformImage *output = [api getSystemImageName:arg_name size:arg_size weight:arg_weight colorsRGBA:arg_colorsRGBA preferMulticolor:arg_preferMulticolor error:&error]; callback(wrapResult(output, error)); }]; - } - else { + } else { [channel setMessageHandler:nil]; } } @@ -148,8 +145,7 @@ void FLTPlatformImagesApiSetup(id binaryMessenger, NSObj FLTPlatformImage *output = [api getPlatformImageName:arg_name error:&error]; callback(wrapResult(output, error)); }]; - } - else { + } else { [channel setMessageHandler:nil]; } } @@ -169,8 +165,7 @@ void FLTPlatformImagesApiSetup(id binaryMessenger, NSObj NSString *output = [api resolveURLName:arg_name extension:arg_extension error:&error]; callback(wrapResult(output, error)); }]; - } - else { + } else { [channel setMessageHandler:nil]; } } diff --git a/packages/ios_platform_images/lib/platform_images_api.g.dart b/packages/ios_platform_images/lib/platform_images_api.g.dart index 6a540d2e7a91..ac6337cca3fe 100644 --- a/packages/ios_platform_images/lib/platform_images_api.g.dart +++ b/packages/ios_platform_images/lib/platform_images_api.g.dart @@ -1,9 +1,10 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v4.2.14), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import + import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; @@ -63,13 +64,10 @@ class _PlatformImagesApiCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: + case 128: return PlatformImage.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } } } diff --git a/packages/ios_platform_images/pubspec.yaml b/packages/ios_platform_images/pubspec.yaml index 8f5637bd39f7..66e362f7450d 100644 --- a/packages/ios_platform_images/pubspec.yaml +++ b/packages/ios_platform_images/pubspec.yaml @@ -27,4 +27,4 @@ dev_dependencies: sdk: flutter mockito: ^5.3.2 pedantic: ^1.10.0 - pigeon: ^4.2.14 + pigeon: ^7.0.5 From ed394eb8c9445eb820082f89ebb6a05f64a65267 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Thu, 26 Jan 2023 03:34:06 -0700 Subject: [PATCH 51/64] Correct formatting --- .../ios/Runner.xcodeproj/project.pbxproj | 4 +- .../example/ios/Runner/Info.plist | 2 + .../ios/Classes/PlatformImagesApi.g.h | 23 +++++--- .../ios/Classes/PlatformImagesApi.g.m | 56 ++++++++++++------- .../lib/platform_images_api.g.dart | 22 ++++++-- 5 files changed, 72 insertions(+), 35 deletions(-) diff --git a/packages/ios_platform_images/example/ios/Runner.xcodeproj/project.pbxproj b/packages/ios_platform_images/example/ios/Runner.xcodeproj/project.pbxproj index f217bcd92656..08d42f9edb6c 100644 --- a/packages/ios_platform_images/example/ios/Runner.xcodeproj/project.pbxproj +++ b/packages/ios_platform_images/example/ios/Runner.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 50; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -278,6 +278,7 @@ /* Begin PBXShellScriptBuildPhase section */ 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); @@ -334,6 +335,7 @@ }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); diff --git a/packages/ios_platform_images/example/ios/Runner/Info.plist b/packages/ios_platform_images/example/ios/Runner/Info.plist index a6a7ea568a77..bebb28ae7cf0 100644 --- a/packages/ios_platform_images/example/ios/Runner/Info.plist +++ b/packages/ios_platform_images/example/ios/Runner/Info.plist @@ -43,5 +43,7 @@ CADisableMinimumFrameDurationOnPhone + UIApplicationSupportsIndirectInputEvents + diff --git a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h index 4de20e8e3db8..e2a9a215eed3 100644 --- a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h +++ b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h @@ -29,9 +29,9 @@ typedef NS_ENUM(NSUInteger, FLTFontWeight) { @interface FLTPlatformImage : NSObject + (instancetype)makeWithScale:(nullable NSNumber *)scale - bytes:(nullable FlutterStandardTypedData *)bytes; -@property(nonatomic, strong, nullable) NSNumber * scale; -@property(nonatomic, strong, nullable) FlutterStandardTypedData * bytes; + bytes:(nullable FlutterStandardTypedData *)bytes; +@property(nonatomic, strong, nullable) NSNumber *scale; +@property(nonatomic, strong, nullable) FlutterStandardTypedData *bytes; @end /// The codec used by FLTPlatformImagesApi. @@ -39,12 +39,21 @@ NSObject *FLTPlatformImagesApiGetCodec(void); @protocol FLTPlatformImagesApi /// @return `nil` only when `error != nil`. -- (nullable FLTPlatformImage *)getSystemImageName:(NSString *)name size:(NSNumber *)size weight:(FLTFontWeight)weight colorsRGBA:(NSArray *)colorsRGBA preferMulticolor:(NSNumber *)preferMulticolor error:(FlutterError *_Nullable *_Nonnull)error; +- (nullable FLTPlatformImage *)getSystemImageName:(NSString *)name + size:(NSNumber *)size + weight:(FLTFontWeight)weight + colorsRGBA:(NSArray *)colorsRGBA + preferMulticolor:(NSNumber *)preferMulticolor + error:(FlutterError *_Nullable *_Nonnull)error; /// @return `nil` only when `error != nil`. -- (nullable FLTPlatformImage *)getPlatformImageName:(NSString *)name error:(FlutterError *_Nullable *_Nonnull)error; -- (nullable NSString *)resolveURLName:(NSString *)name extension:(nullable NSString *)extension error:(FlutterError *_Nullable *_Nonnull)error; +- (nullable FLTPlatformImage *)getPlatformImageName:(NSString *)name + error:(FlutterError *_Nullable *_Nonnull)error; +- (nullable NSString *)resolveURLName:(NSString *)name + extension:(nullable NSString *)extension + error:(FlutterError *_Nullable *_Nonnull)error; @end -extern void FLTPlatformImagesApiSetup(id binaryMessenger, NSObject *_Nullable api); +extern void FLTPlatformImagesApiSetup(id binaryMessenger, + NSObject *_Nullable api); NS_ASSUME_NONNULL_END diff --git a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m index 047f65af28c3..af620b2d0e44 100644 --- a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m +++ b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m @@ -36,8 +36,8 @@ - (NSArray *)toList; @implementation FLTPlatformImage + (instancetype)makeWithScale:(nullable NSNumber *)scale - bytes:(nullable FlutterStandardTypedData *)bytes { - FLTPlatformImage* pigeonResult = [[FLTPlatformImage alloc] init]; + bytes:(nullable FlutterStandardTypedData *)bytes { + FLTPlatformImage *pigeonResult = [[FLTPlatformImage alloc] init]; pigeonResult.scale = scale; pigeonResult.bytes = bytes; return pigeonResult; @@ -64,7 +64,7 @@ @interface FLTPlatformImagesApiCodecReader : FlutterStandardReader @implementation FLTPlatformImagesApiCodecReader - (nullable id)readValueOfType:(UInt8)type { switch (type) { - case 128: + case 128: return [FLTPlatformImage fromList:[self readValue]]; default: return [super readValueOfType:type]; @@ -100,21 +100,26 @@ - (FlutterStandardReader *)readerWithData:(NSData *)data { static FlutterStandardMessageCodec *sSharedObject = nil; static dispatch_once_t sPred = 0; dispatch_once(&sPred, ^{ - FLTPlatformImagesApiCodecReaderWriter *readerWriter = [[FLTPlatformImagesApiCodecReaderWriter alloc] init]; + FLTPlatformImagesApiCodecReaderWriter *readerWriter = + [[FLTPlatformImagesApiCodecReaderWriter alloc] init]; sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; }); return sSharedObject; } -void FLTPlatformImagesApiSetup(id binaryMessenger, NSObject *api) { +void FLTPlatformImagesApiSetup(id binaryMessenger, + NSObject *api) { { - FlutterBasicMessageChannel *channel = - [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.PlatformImagesApi.getSystemImage" + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.PlatformImagesApi.getSystemImage" binaryMessenger:binaryMessenger - codec:FLTPlatformImagesApiGetCodec()]; + codec:FLTPlatformImagesApiGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(getSystemImageName:size:weight:colorsRGBA:preferMulticolor:error:)], @"FLTPlatformImagesApi api (%@) doesn't respond to @selector(getSystemImageName:size:weight:colorsRGBA:preferMulticolor:error:)", api); + NSCAssert([api respondsToSelector:@selector + (getSystemImageName:size:weight:colorsRGBA:preferMulticolor:error:)], + @"FLTPlatformImagesApi api (%@) doesn't respond to " + @"@selector(getSystemImageName:size:weight:colorsRGBA:preferMulticolor:error:)", + api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; NSString *arg_name = GetNullableObjectAtIndex(args, 0); @@ -123,7 +128,12 @@ void FLTPlatformImagesApiSetup(id binaryMessenger, NSObj NSArray *arg_colorsRGBA = GetNullableObjectAtIndex(args, 3); NSNumber *arg_preferMulticolor = GetNullableObjectAtIndex(args, 4); FlutterError *error; - FLTPlatformImage *output = [api getSystemImageName:arg_name size:arg_size weight:arg_weight colorsRGBA:arg_colorsRGBA preferMulticolor:arg_preferMulticolor error:&error]; + FLTPlatformImage *output = [api getSystemImageName:arg_name + size:arg_size + weight:arg_weight + colorsRGBA:arg_colorsRGBA + preferMulticolor:arg_preferMulticolor + error:&error]; callback(wrapResult(output, error)); }]; } else { @@ -131,13 +141,15 @@ void FLTPlatformImagesApiSetup(id binaryMessenger, NSObj } } { - FlutterBasicMessageChannel *channel = - [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.PlatformImagesApi.getPlatformImage" + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.PlatformImagesApi.getPlatformImage" binaryMessenger:binaryMessenger - codec:FLTPlatformImagesApiGetCodec()]; + codec:FLTPlatformImagesApiGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(getPlatformImageName:error:)], @"FLTPlatformImagesApi api (%@) doesn't respond to @selector(getPlatformImageName:error:)", api); + NSCAssert([api respondsToSelector:@selector(getPlatformImageName:error:)], + @"FLTPlatformImagesApi api (%@) doesn't respond to " + @"@selector(getPlatformImageName:error:)", + api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; NSString *arg_name = GetNullableObjectAtIndex(args, 0); @@ -150,13 +162,15 @@ void FLTPlatformImagesApiSetup(id binaryMessenger, NSObj } } { - FlutterBasicMessageChannel *channel = - [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.PlatformImagesApi.resolveURL" + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.PlatformImagesApi.resolveURL" binaryMessenger:binaryMessenger - codec:FLTPlatformImagesApiGetCodec()]; + codec:FLTPlatformImagesApiGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(resolveURLName:extension:error:)], @"FLTPlatformImagesApi api (%@) doesn't respond to @selector(resolveURLName:extension:error:)", api); + NSCAssert([api respondsToSelector:@selector(resolveURLName:extension:error:)], + @"FLTPlatformImagesApi api (%@) doesn't respond to " + @"@selector(resolveURLName:extension:error:)", + api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; NSString *arg_name = GetNullableObjectAtIndex(args, 0); diff --git a/packages/ios_platform_images/lib/platform_images_api.g.dart b/packages/ios_platform_images/lib/platform_images_api.g.dart index ac6337cca3fe..bd2a43acf00c 100644 --- a/packages/ios_platform_images/lib/platform_images_api.g.dart +++ b/packages/ios_platform_images/lib/platform_images_api.g.dart @@ -64,7 +64,7 @@ class _PlatformImagesApiCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: + case 128: return PlatformImage.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); @@ -82,12 +82,22 @@ class PlatformImagesApi { static const MessageCodec codec = _PlatformImagesApiCodec(); - Future getSystemImage(String arg_name, double arg_size, FontWeight arg_weight, List arg_colorsRGBA, bool arg_preferMulticolor) async { + Future getSystemImage( + String arg_name, + double arg_size, + FontWeight arg_weight, + List arg_colorsRGBA, + bool arg_preferMulticolor) async { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.PlatformImagesApi.getSystemImage', codec, binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_name, arg_size, arg_weight.index, arg_colorsRGBA, arg_preferMulticolor]) as List?; + final List? replyList = await channel.send([ + arg_name, + arg_size, + arg_weight.index, + arg_colorsRGBA, + arg_preferMulticolor + ]) as List?; if (replyList == null) { throw PlatformException( code: 'channel-error', @@ -140,8 +150,8 @@ class PlatformImagesApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.PlatformImagesApi.resolveURL', codec, binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_name, arg_extension]) as List?; + final List? replyList = await channel + .send([arg_name, arg_extension]) as List?; if (replyList == null) { throw PlatformException( code: 'channel-error', From 5e20e1a486d1f8a40bb2fada492d248e0924b5ec Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Fri, 27 Jan 2023 13:49:51 -0700 Subject: [PATCH 52/64] Fix null issues in native code & pigeon --- .../ios/Classes/FLTPlatformImagesPlugin.m | 4 ++++ .../ios/Classes/PlatformImagesApi.g.h | 2 -- .../lib/ios_platform_images.dart | 8 ++++---- .../lib/platform_images_api.g.dart | 18 ++++-------------- .../pigeons/platform_images.dart | 4 ++-- 5 files changed, 14 insertions(+), 22 deletions(-) diff --git a/packages/ios_platform_images/ios/Classes/FLTPlatformImagesPlugin.m b/packages/ios_platform_images/ios/Classes/FLTPlatformImagesPlugin.m index bb25936d7db0..4d8b58067f3d 100644 --- a/packages/ios_platform_images/ios/Classes/FLTPlatformImagesPlugin.m +++ b/packages/ios_platform_images/ios/Classes/FLTPlatformImagesPlugin.m @@ -65,6 +65,10 @@ - (nullable FLTPlatformImage *)getSystemImageName:(NSString *)name [image imageWithTintColor:colorArray.count > 0 ? colorArray[0] : [UIColor blackColor]]; } + if (finalImage == nil) { + return nil; + } + FlutterStandardTypedData *data = [FlutterStandardTypedData typedDataWithBytes:UIImagePNGRepresentation(finalImage)]; return [FLTPlatformImage makeWithScale:@(finalImage.scale) bytes:data]; diff --git a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h index e2a9a215eed3..58d47b99e0df 100644 --- a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h +++ b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h @@ -38,14 +38,12 @@ typedef NS_ENUM(NSUInteger, FLTFontWeight) { NSObject *FLTPlatformImagesApiGetCodec(void); @protocol FLTPlatformImagesApi -/// @return `nil` only when `error != nil`. - (nullable FLTPlatformImage *)getSystemImageName:(NSString *)name size:(NSNumber *)size weight:(FLTFontWeight)weight colorsRGBA:(NSArray *)colorsRGBA preferMulticolor:(NSNumber *)preferMulticolor error:(FlutterError *_Nullable *_Nonnull)error; -/// @return `nil` only when `error != nil`. - (nullable FLTPlatformImage *)getPlatformImageName:(NSString *)name error:(FlutterError *_Nullable *_Nonnull)error; - (nullable NSString *)resolveURLName:(NSString *)name diff --git a/packages/ios_platform_images/lib/ios_platform_images.dart b/packages/ios_platform_images/lib/ios_platform_images.dart index a9dc508afb87..c1b57d5843b5 100644 --- a/packages/ios_platform_images/lib/ios_platform_images.dart +++ b/packages/ios_platform_images/lib/ios_platform_images.dart @@ -120,7 +120,7 @@ class IosPlatformImages { /// /// See [https://developer.apple.com/documentation/uikit/uiimage/1624146-imagenamed?language=objc] static ImageProvider load(String name) { - final Future image = _api.getPlatformImage(name); + final Future image = _api.getPlatformImage(name); return _platformImageToFutureMemoryImage(image, name); } @@ -178,17 +178,17 @@ class IosPlatformImages { ]) .toList(); - final Future image = + final Future image = _api.getSystemImage(name, size, weight, colorsRGBA, preferMulticolor); return _platformImageToFutureMemoryImage(image, name); } static _FutureMemoryImage _platformImageToFutureMemoryImage( - Future image, String name) { + Future image, String name) { final Completer bytesCompleter = Completer(); final Completer scaleCompleter = Completer(); - image.then((PlatformImage image) { + image.then((PlatformImage? image) { if (image == null || image.bytes == null || image.scale == null) { scaleCompleter.completeError( ArgumentError("Image couldn't be found: $name"), diff --git a/packages/ios_platform_images/lib/platform_images_api.g.dart b/packages/ios_platform_images/lib/platform_images_api.g.dart index bd2a43acf00c..3888df4d81ea 100644 --- a/packages/ios_platform_images/lib/platform_images_api.g.dart +++ b/packages/ios_platform_images/lib/platform_images_api.g.dart @@ -82,7 +82,7 @@ class PlatformImagesApi { static const MessageCodec codec = _PlatformImagesApiCodec(); - Future getSystemImage( + Future getSystemImage( String arg_name, double arg_size, FontWeight arg_weight, @@ -109,17 +109,12 @@ class PlatformImagesApi { message: replyList[1] as String?, details: replyList[2], ); - } else if (replyList[0] == null) { - throw PlatformException( - code: 'null-error', - message: 'Host platform returned null value for non-null return value.', - ); } else { - return (replyList[0] as PlatformImage?)!; + return (replyList[0] as PlatformImage?); } } - Future getPlatformImage(String arg_name) async { + Future getPlatformImage(String arg_name) async { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.PlatformImagesApi.getPlatformImage', codec, binaryMessenger: _binaryMessenger); @@ -136,13 +131,8 @@ class PlatformImagesApi { message: replyList[1] as String?, details: replyList[2], ); - } else if (replyList[0] == null) { - throw PlatformException( - code: 'null-error', - message: 'Host platform returned null value for non-null return value.', - ); } else { - return (replyList[0] as PlatformImage?)!; + return (replyList[0] as PlatformImage?); } } diff --git a/packages/ios_platform_images/pigeons/platform_images.dart b/packages/ios_platform_images/pigeons/platform_images.dart index 715737e998ad..2eea8e26bc57 100644 --- a/packages/ios_platform_images/pigeons/platform_images.dart +++ b/packages/ios_platform_images/pigeons/platform_images.dart @@ -32,8 +32,8 @@ enum FontWeight { @HostApi() abstract class PlatformImagesApi { - PlatformImage getSystemImage(String name, double size, FontWeight weight, + PlatformImage? getSystemImage(String name, double size, FontWeight weight, List colorsRGBA, bool preferMulticolor); - PlatformImage getPlatformImage(String name); + PlatformImage? getPlatformImage(String name); String? resolveURL(String name, String? extension); } From ece3b57f7a2b106dd11e499381fe7e1e8fe61058 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Fri, 27 Jan 2023 14:12:41 -0700 Subject: [PATCH 53/64] Make Pigeon PlatformImage fields non-nullable --- packages/ios_platform_images/pigeons/platform_images.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/ios_platform_images/pigeons/platform_images.dart b/packages/ios_platform_images/pigeons/platform_images.dart index 2eea8e26bc57..56c2d1b58763 100644 --- a/packages/ios_platform_images/pigeons/platform_images.dart +++ b/packages/ios_platform_images/pigeons/platform_images.dart @@ -14,8 +14,10 @@ import 'package:pigeon/pigeon.dart'; copyrightHeader: 'pigeons/copyright.txt', )) class PlatformImage { - double? scale; - Uint8List? bytes; + PlatformImage(this.scale, this.bytes); + + double scale; + Uint8List bytes; } enum FontWeight { From 9349e4f941e1b77245acf86ba6c8129767d6351b Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Fri, 27 Jan 2023 22:09:24 -0700 Subject: [PATCH 54/64] Update pigeon --- .../example/ios/Runner.xcodeproj/project.pbxproj | 12 ++++++++---- .../xcshareddata/xcschemes/Runner.xcscheme | 2 +- .../ios/Classes/PlatformImagesApi.g.h | 11 ++++++----- .../ios/Classes/PlatformImagesApi.g.m | 11 ++++------- .../lib/platform_images_api.g.dart | 14 +++++++------- packages/ios_platform_images/pubspec.yaml | 2 +- 6 files changed, 27 insertions(+), 25 deletions(-) diff --git a/packages/ios_platform_images/example/ios/Runner.xcodeproj/project.pbxproj b/packages/ios_platform_images/example/ios/Runner.xcodeproj/project.pbxproj index 08d42f9edb6c..f5154fd989de 100644 --- a/packages/ios_platform_images/example/ios/Runner.xcodeproj/project.pbxproj +++ b/packages/ios_platform_images/example/ios/Runner.xcodeproj/project.pbxproj @@ -219,7 +219,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1300; + LastUpgradeCheck = 1420; ORGANIZATIONNAME = "The Flutter Authors"; TargetAttributes = { 97C146ED1CF9000F007C117D = { @@ -443,6 +443,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -461,7 +462,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; @@ -522,6 +523,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -546,7 +548,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -577,6 +579,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -595,10 +598,11 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; diff --git a/packages/ios_platform_images/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/packages/ios_platform_images/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index 7ae2cb4d4e54..a37057fcf10c 100644 --- a/packages/ios_platform_images/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/packages/ios_platform_images/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ @@ -28,10 +28,11 @@ typedef NS_ENUM(NSUInteger, FLTFontWeight) { @class FLTPlatformImage; @interface FLTPlatformImage : NSObject -+ (instancetype)makeWithScale:(nullable NSNumber *)scale - bytes:(nullable FlutterStandardTypedData *)bytes; -@property(nonatomic, strong, nullable) NSNumber *scale; -@property(nonatomic, strong, nullable) FlutterStandardTypedData *bytes; +/// `init` unavailable to enforce nonnull fields, see the `make` class method. +- (instancetype)init NS_UNAVAILABLE; ++ (instancetype)makeWithScale:(NSNumber *)scale bytes:(FlutterStandardTypedData *)bytes; +@property(nonatomic, strong) NSNumber *scale; +@property(nonatomic, strong) FlutterStandardTypedData *bytes; @end /// The codec used by FLTPlatformImagesApi. diff --git a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m index af620b2d0e44..be4306a1387f 100644 --- a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m +++ b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v7.0.5), do not edit directly. +// Autogenerated from Pigeon (v7.1.4), do not edit directly. // See also: https://pub.dev/packages/pigeon #import "PlatformImagesApi.g.h" @@ -19,10 +19,6 @@ } return @[ result ?: [NSNull null] ]; } -static id GetNullableObject(NSDictionary *dict, id key) { - id result = dict[key]; - return (result == [NSNull null]) ? nil : result; -} static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) { id result = array[key]; return (result == [NSNull null]) ? nil : result; @@ -35,8 +31,7 @@ - (NSArray *)toList; @end @implementation FLTPlatformImage -+ (instancetype)makeWithScale:(nullable NSNumber *)scale - bytes:(nullable FlutterStandardTypedData *)bytes { ++ (instancetype)makeWithScale:(NSNumber *)scale bytes:(FlutterStandardTypedData *)bytes { FLTPlatformImage *pigeonResult = [[FLTPlatformImage alloc] init]; pigeonResult.scale = scale; pigeonResult.bytes = bytes; @@ -45,7 +40,9 @@ + (instancetype)makeWithScale:(nullable NSNumber *)scale + (FLTPlatformImage *)fromList:(NSArray *)list { FLTPlatformImage *pigeonResult = [[FLTPlatformImage alloc] init]; pigeonResult.scale = GetNullableObjectAtIndex(list, 0); + NSAssert(pigeonResult.scale != nil, @""); pigeonResult.bytes = GetNullableObjectAtIndex(list, 1); + NSAssert(pigeonResult.bytes != nil, @""); return pigeonResult; } + (nullable FLTPlatformImage *)nullableFromList:(NSArray *)list { diff --git a/packages/ios_platform_images/lib/platform_images_api.g.dart b/packages/ios_platform_images/lib/platform_images_api.g.dart index 3888df4d81ea..b6f78a6c875d 100644 --- a/packages/ios_platform_images/lib/platform_images_api.g.dart +++ b/packages/ios_platform_images/lib/platform_images_api.g.dart @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v7.0.5), do not edit directly. +// Autogenerated from Pigeon (v7.1.4), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import @@ -25,13 +25,13 @@ enum FontWeight { class PlatformImage { PlatformImage({ - this.scale, - this.bytes, + required this.scale, + required this.bytes, }); - double? scale; + double scale; - Uint8List? bytes; + Uint8List bytes; Object encode() { return [ @@ -43,8 +43,8 @@ class PlatformImage { static PlatformImage decode(Object result) { result as List; return PlatformImage( - scale: result[0] as double?, - bytes: result[1] as Uint8List?, + scale: result[0]! as double, + bytes: result[1]! as Uint8List, ); } } diff --git a/packages/ios_platform_images/pubspec.yaml b/packages/ios_platform_images/pubspec.yaml index 66e362f7450d..17a03a52804c 100644 --- a/packages/ios_platform_images/pubspec.yaml +++ b/packages/ios_platform_images/pubspec.yaml @@ -27,4 +27,4 @@ dev_dependencies: sdk: flutter mockito: ^5.3.2 pedantic: ^1.10.0 - pigeon: ^7.0.5 + pigeon: ^7.1.4 From 531fd695208b1fc5758d10167ffbf136e30b631e Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Fri, 27 Jan 2023 22:11:40 -0700 Subject: [PATCH 55/64] Fix dart test --- .../ios_platform_images/test/ios_platform_images_test.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 d0d69c3c75eb..52583ea30f15 100644 --- a/packages/ios_platform_images/test/ios_platform_images_test.dart +++ b/packages/ios_platform_images/test/ios_platform_images_test.dart @@ -15,8 +15,10 @@ void main() { TestWidgetsFlutterBinding.ensureInitialized(); - final PlatformImage fakePlatformImage = PlatformImage(bytes: Uint8List(1)); - final PlatformImage fakeSystemImage = PlatformImage(bytes: Uint8List(2)); + final PlatformImage fakePlatformImage = + PlatformImage(scale: 1, bytes: Uint8List(1)); + final PlatformImage fakeSystemImage = + PlatformImage(scale: 1, bytes: Uint8List(2)); setUp(() { when(api.resolveURL('foobar', null)).thenAnswer((_) async => '42'); From 41769489272a9c24086fdbe740c912a8df18eb86 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Sun, 12 Feb 2023 20:40:43 -0700 Subject: [PATCH 56/64] Update pigeon to 8.0.0 --- .../ios/Classes/PlatformImagesApi.g.h | 26 +++----- .../ios/Classes/PlatformImagesApi.g.m | 59 ++++++++----------- .../lib/platform_images_api.g.dart | 24 +++----- packages/ios_platform_images/pubspec.yaml | 2 +- 4 files changed, 40 insertions(+), 71 deletions(-) diff --git a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h index 2dca1cd4a945..8cb37374f677 100644 --- a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h +++ b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v7.1.4), do not edit directly. +// Autogenerated from Pigeon (v8.0.0), do not edit directly. // See also: https://pub.dev/packages/pigeon #import @@ -30,29 +30,21 @@ typedef NS_ENUM(NSUInteger, FLTFontWeight) { @interface FLTPlatformImage : NSObject /// `init` unavailable to enforce nonnull fields, see the `make` class method. - (instancetype)init NS_UNAVAILABLE; -+ (instancetype)makeWithScale:(NSNumber *)scale bytes:(FlutterStandardTypedData *)bytes; -@property(nonatomic, strong) NSNumber *scale; -@property(nonatomic, strong) FlutterStandardTypedData *bytes; ++ (instancetype)makeWithScale:(NSNumber *)scale + bytes:(FlutterStandardTypedData *)bytes; +@property(nonatomic, strong) NSNumber * scale; +@property(nonatomic, strong) FlutterStandardTypedData * bytes; @end /// The codec used by FLTPlatformImagesApi. NSObject *FLTPlatformImagesApiGetCodec(void); @protocol FLTPlatformImagesApi -- (nullable FLTPlatformImage *)getSystemImageName:(NSString *)name - size:(NSNumber *)size - weight:(FLTFontWeight)weight - colorsRGBA:(NSArray *)colorsRGBA - preferMulticolor:(NSNumber *)preferMulticolor - error:(FlutterError *_Nullable *_Nonnull)error; -- (nullable FLTPlatformImage *)getPlatformImageName:(NSString *)name - error:(FlutterError *_Nullable *_Nonnull)error; -- (nullable NSString *)resolveURLName:(NSString *)name - extension:(nullable NSString *)extension - error:(FlutterError *_Nullable *_Nonnull)error; +- (nullable FLTPlatformImage *)getSystemImageName:(NSString *)name size:(NSNumber *)size weight:(FLTFontWeight)weight colorsRGBA:(NSArray *)colorsRGBA preferMulticolor:(NSNumber *)preferMulticolor error:(FlutterError *_Nullable *_Nonnull)error; +- (nullable FLTPlatformImage *)getPlatformImageName:(NSString *)name error:(FlutterError *_Nullable *_Nonnull)error; +- (nullable NSString *)resolveURLName:(NSString *)name extension:(nullable NSString *)extension error:(FlutterError *_Nullable *_Nonnull)error; @end -extern void FLTPlatformImagesApiSetup(id binaryMessenger, - NSObject *_Nullable api); +extern void FLTPlatformImagesApiSetup(id binaryMessenger, NSObject *_Nullable api); NS_ASSUME_NONNULL_END diff --git a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m index be4306a1387f..62755a403428 100644 --- a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m +++ b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v7.1.4), do not edit directly. +// Autogenerated from Pigeon (v8.0.0), do not edit directly. // See also: https://pub.dev/packages/pigeon #import "PlatformImagesApi.g.h" @@ -31,8 +31,9 @@ - (NSArray *)toList; @end @implementation FLTPlatformImage -+ (instancetype)makeWithScale:(NSNumber *)scale bytes:(FlutterStandardTypedData *)bytes { - FLTPlatformImage *pigeonResult = [[FLTPlatformImage alloc] init]; ++ (instancetype)makeWithScale:(NSNumber *)scale + bytes:(FlutterStandardTypedData *)bytes { + FLTPlatformImage* pigeonResult = [[FLTPlatformImage alloc] init]; pigeonResult.scale = scale; pigeonResult.bytes = bytes; return pigeonResult; @@ -61,7 +62,7 @@ @interface FLTPlatformImagesApiCodecReader : FlutterStandardReader @implementation FLTPlatformImagesApiCodecReader - (nullable id)readValueOfType:(UInt8)type { switch (type) { - case 128: + case 128: return [FLTPlatformImage fromList:[self readValue]]; default: return [super readValueOfType:type]; @@ -97,26 +98,21 @@ - (FlutterStandardReader *)readerWithData:(NSData *)data { static FlutterStandardMessageCodec *sSharedObject = nil; static dispatch_once_t sPred = 0; dispatch_once(&sPred, ^{ - FLTPlatformImagesApiCodecReaderWriter *readerWriter = - [[FLTPlatformImagesApiCodecReaderWriter alloc] init]; + FLTPlatformImagesApiCodecReaderWriter *readerWriter = [[FLTPlatformImagesApiCodecReaderWriter alloc] init]; sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; }); return sSharedObject; } -void FLTPlatformImagesApiSetup(id binaryMessenger, - NSObject *api) { +void FLTPlatformImagesApiSetup(id binaryMessenger, NSObject *api) { { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.PlatformImagesApi.getSystemImage" + FlutterBasicMessageChannel *channel = + [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.PlatformImagesApi.getSystemImage" binaryMessenger:binaryMessenger - codec:FLTPlatformImagesApiGetCodec()]; + codec:FLTPlatformImagesApiGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector - (getSystemImageName:size:weight:colorsRGBA:preferMulticolor:error:)], - @"FLTPlatformImagesApi api (%@) doesn't respond to " - @"@selector(getSystemImageName:size:weight:colorsRGBA:preferMulticolor:error:)", - api); + NSCAssert([api respondsToSelector:@selector(getSystemImageName:size:weight:colorsRGBA:preferMulticolor:error:)], @"FLTPlatformImagesApi api (%@) doesn't respond to @selector(getSystemImageName:size:weight:colorsRGBA:preferMulticolor:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; NSString *arg_name = GetNullableObjectAtIndex(args, 0); @@ -125,12 +121,7 @@ void FLTPlatformImagesApiSetup(id binaryMessenger, NSArray *arg_colorsRGBA = GetNullableObjectAtIndex(args, 3); NSNumber *arg_preferMulticolor = GetNullableObjectAtIndex(args, 4); FlutterError *error; - FLTPlatformImage *output = [api getSystemImageName:arg_name - size:arg_size - weight:arg_weight - colorsRGBA:arg_colorsRGBA - preferMulticolor:arg_preferMulticolor - error:&error]; + FLTPlatformImage *output = [api getSystemImageName:arg_name size:arg_size weight:arg_weight colorsRGBA:arg_colorsRGBA preferMulticolor:arg_preferMulticolor error:&error]; callback(wrapResult(output, error)); }]; } else { @@ -138,15 +129,13 @@ void FLTPlatformImagesApiSetup(id binaryMessenger, } } { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.PlatformImagesApi.getPlatformImage" + FlutterBasicMessageChannel *channel = + [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.PlatformImagesApi.getPlatformImage" binaryMessenger:binaryMessenger - codec:FLTPlatformImagesApiGetCodec()]; + codec:FLTPlatformImagesApiGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(getPlatformImageName:error:)], - @"FLTPlatformImagesApi api (%@) doesn't respond to " - @"@selector(getPlatformImageName:error:)", - api); + NSCAssert([api respondsToSelector:@selector(getPlatformImageName:error:)], @"FLTPlatformImagesApi api (%@) doesn't respond to @selector(getPlatformImageName:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; NSString *arg_name = GetNullableObjectAtIndex(args, 0); @@ -159,15 +148,13 @@ void FLTPlatformImagesApiSetup(id binaryMessenger, } } { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.PlatformImagesApi.resolveURL" + FlutterBasicMessageChannel *channel = + [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.PlatformImagesApi.resolveURL" binaryMessenger:binaryMessenger - codec:FLTPlatformImagesApiGetCodec()]; + codec:FLTPlatformImagesApiGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(resolveURLName:extension:error:)], - @"FLTPlatformImagesApi api (%@) doesn't respond to " - @"@selector(resolveURLName:extension:error:)", - api); + NSCAssert([api respondsToSelector:@selector(resolveURLName:extension:error:)], @"FLTPlatformImagesApi api (%@) doesn't respond to @selector(resolveURLName:extension:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; NSString *arg_name = GetNullableObjectAtIndex(args, 0); diff --git a/packages/ios_platform_images/lib/platform_images_api.g.dart b/packages/ios_platform_images/lib/platform_images_api.g.dart index b6f78a6c875d..a53e7779f19e 100644 --- a/packages/ios_platform_images/lib/platform_images_api.g.dart +++ b/packages/ios_platform_images/lib/platform_images_api.g.dart @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v7.1.4), do not edit directly. +// Autogenerated from Pigeon (v8.0.0), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import @@ -64,7 +64,7 @@ class _PlatformImagesApiCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: + case 128: return PlatformImage.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); @@ -82,22 +82,12 @@ class PlatformImagesApi { static const MessageCodec codec = _PlatformImagesApiCodec(); - Future getSystemImage( - String arg_name, - double arg_size, - FontWeight arg_weight, - List arg_colorsRGBA, - bool arg_preferMulticolor) async { + Future getSystemImage(String arg_name, double arg_size, FontWeight arg_weight, List arg_colorsRGBA, bool arg_preferMulticolor) async { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.PlatformImagesApi.getSystemImage', codec, binaryMessenger: _binaryMessenger); - final List? replyList = await channel.send([ - arg_name, - arg_size, - arg_weight.index, - arg_colorsRGBA, - arg_preferMulticolor - ]) as List?; + final List? replyList = + await channel.send([arg_name, arg_size, arg_weight.index, arg_colorsRGBA, arg_preferMulticolor]) as List?; if (replyList == null) { throw PlatformException( code: 'channel-error', @@ -140,8 +130,8 @@ class PlatformImagesApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.PlatformImagesApi.resolveURL', codec, binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_name, arg_extension]) as List?; + final List? replyList = + await channel.send([arg_name, arg_extension]) as List?; if (replyList == null) { throw PlatformException( code: 'channel-error', diff --git a/packages/ios_platform_images/pubspec.yaml b/packages/ios_platform_images/pubspec.yaml index 17a03a52804c..9638a1f964e3 100644 --- a/packages/ios_platform_images/pubspec.yaml +++ b/packages/ios_platform_images/pubspec.yaml @@ -27,4 +27,4 @@ dev_dependencies: sdk: flutter mockito: ^5.3.2 pedantic: ^1.10.0 - pigeon: ^7.1.4 + pigeon: ^8.0.0 From 1507628b0ba652a76badd8b2304c1c6665f1858e Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Sun, 12 Feb 2023 20:43:13 -0700 Subject: [PATCH 57/64] Fix system image error case test --- .../ios_platform_images_integration_test.dart | 2 +- packages/ios_platform_images/lib/ios_platform_images.dart | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/ios_platform_images/example/integration_test/ios_platform_images_integration_test.dart b/packages/ios_platform_images/example/integration_test/ios_platform_images_integration_test.dart index 712aa9ad1b98..6b0174130246 100644 --- a/packages/ios_platform_images/example/integration_test/ios_platform_images_integration_test.dart +++ b/packages/ios_platform_images/example/integration_test/ios_platform_images_integration_test.dart @@ -47,7 +47,7 @@ void main() { imageProvider.resolve(ImageConfiguration.empty).completer?.addListener( ImageStreamListener( (ImageInfo info, bool _) => completer.complete(info), - onError: (Object exception, StackTrace? stack) => () { + onError: (Object exception, StackTrace? stack) { completer.completeError(exception); }, ), diff --git a/packages/ios_platform_images/lib/ios_platform_images.dart b/packages/ios_platform_images/lib/ios_platform_images.dart index c1b57d5843b5..6f69cfd7f7c4 100644 --- a/packages/ios_platform_images/lib/ios_platform_images.dart +++ b/packages/ios_platform_images/lib/ios_platform_images.dart @@ -22,7 +22,6 @@ class _FutureImageStreamCompleter extends ImageStreamCompleter { context: ErrorDescription('resolving a single-frame image stream'), exception: error, stack: stack, - silent: true, ); }); } @@ -39,7 +38,6 @@ class _FutureImageStreamCompleter extends ImageStreamCompleter { context: ErrorDescription('resolving an image frame'), exception: exception, stack: stack, - silent: true, ); } } @@ -190,9 +188,6 @@ class IosPlatformImages { final Completer scaleCompleter = Completer(); image.then((PlatformImage? image) { if (image == null || image.bytes == null || image.scale == null) { - scaleCompleter.completeError( - ArgumentError("Image couldn't be found: $name"), - ); bytesCompleter.completeError( ArgumentError("Image couldn't be found: $name"), ); From 35591e4febba070dfc1bde3a7e5093539ccee69a Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Sun, 12 Feb 2023 21:04:24 -0700 Subject: [PATCH 58/64] Fix xctest --- .../example/ios/RunnerTests/IosPlatformImagesTests.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ios_platform_images/example/ios/RunnerTests/IosPlatformImagesTests.m b/packages/ios_platform_images/example/ios/RunnerTests/IosPlatformImagesTests.m index c95c6ad5730d..66ce7e659047 100644 --- a/packages/ios_platform_images/example/ios/RunnerTests/IosPlatformImagesTests.m +++ b/packages/ios_platform_images/example/ios/RunnerTests/IosPlatformImagesTests.m @@ -11,7 +11,7 @@ @interface IosPlatformImagesTests : XCTestCase @implementation IosPlatformImagesTests - (void)testPlugin { - IosPlatformImagesPlugin *plugin = [[IosPlatformImagesPlugin alloc] init]; + FLTPlatformImagesPlugin *plugin = [[FLTPlatformImagesPlugin alloc] init]; XCTAssertNotNil(plugin); } From fa3a4b015864d32c5e423d94556904f30d5cab99 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Sun, 12 Feb 2023 21:13:18 -0700 Subject: [PATCH 59/64] Fix pigeon file formatting --- .../ios/Classes/PlatformImagesApi.g.h | 24 +++++--- .../ios/Classes/PlatformImagesApi.g.m | 57 ++++++++++++------- .../lib/platform_images_api.g.dart | 22 +++++-- 3 files changed, 67 insertions(+), 36 deletions(-) diff --git a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h index 8cb37374f677..2b5f87f4f5a6 100644 --- a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h +++ b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.h @@ -30,21 +30,29 @@ typedef NS_ENUM(NSUInteger, FLTFontWeight) { @interface FLTPlatformImage : NSObject /// `init` unavailable to enforce nonnull fields, see the `make` class method. - (instancetype)init NS_UNAVAILABLE; -+ (instancetype)makeWithScale:(NSNumber *)scale - bytes:(FlutterStandardTypedData *)bytes; -@property(nonatomic, strong) NSNumber * scale; -@property(nonatomic, strong) FlutterStandardTypedData * bytes; ++ (instancetype)makeWithScale:(NSNumber *)scale bytes:(FlutterStandardTypedData *)bytes; +@property(nonatomic, strong) NSNumber *scale; +@property(nonatomic, strong) FlutterStandardTypedData *bytes; @end /// The codec used by FLTPlatformImagesApi. NSObject *FLTPlatformImagesApiGetCodec(void); @protocol FLTPlatformImagesApi -- (nullable FLTPlatformImage *)getSystemImageName:(NSString *)name size:(NSNumber *)size weight:(FLTFontWeight)weight colorsRGBA:(NSArray *)colorsRGBA preferMulticolor:(NSNumber *)preferMulticolor error:(FlutterError *_Nullable *_Nonnull)error; -- (nullable FLTPlatformImage *)getPlatformImageName:(NSString *)name error:(FlutterError *_Nullable *_Nonnull)error; -- (nullable NSString *)resolveURLName:(NSString *)name extension:(nullable NSString *)extension error:(FlutterError *_Nullable *_Nonnull)error; +- (nullable FLTPlatformImage *)getSystemImageName:(NSString *)name + size:(NSNumber *)size + weight:(FLTFontWeight)weight + colorsRGBA:(NSArray *)colorsRGBA + preferMulticolor:(NSNumber *)preferMulticolor + error:(FlutterError *_Nullable *_Nonnull)error; +- (nullable FLTPlatformImage *)getPlatformImageName:(NSString *)name + error:(FlutterError *_Nullable *_Nonnull)error; +- (nullable NSString *)resolveURLName:(NSString *)name + extension:(nullable NSString *)extension + error:(FlutterError *_Nullable *_Nonnull)error; @end -extern void FLTPlatformImagesApiSetup(id binaryMessenger, NSObject *_Nullable api); +extern void FLTPlatformImagesApiSetup(id binaryMessenger, + NSObject *_Nullable api); NS_ASSUME_NONNULL_END diff --git a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m index 62755a403428..050ea7e80e38 100644 --- a/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m +++ b/packages/ios_platform_images/ios/Classes/PlatformImagesApi.g.m @@ -31,9 +31,8 @@ - (NSArray *)toList; @end @implementation FLTPlatformImage -+ (instancetype)makeWithScale:(NSNumber *)scale - bytes:(FlutterStandardTypedData *)bytes { - FLTPlatformImage* pigeonResult = [[FLTPlatformImage alloc] init]; ++ (instancetype)makeWithScale:(NSNumber *)scale bytes:(FlutterStandardTypedData *)bytes { + FLTPlatformImage *pigeonResult = [[FLTPlatformImage alloc] init]; pigeonResult.scale = scale; pigeonResult.bytes = bytes; return pigeonResult; @@ -62,7 +61,7 @@ @interface FLTPlatformImagesApiCodecReader : FlutterStandardReader @implementation FLTPlatformImagesApiCodecReader - (nullable id)readValueOfType:(UInt8)type { switch (type) { - case 128: + case 128: return [FLTPlatformImage fromList:[self readValue]]; default: return [super readValueOfType:type]; @@ -98,21 +97,26 @@ - (FlutterStandardReader *)readerWithData:(NSData *)data { static FlutterStandardMessageCodec *sSharedObject = nil; static dispatch_once_t sPred = 0; dispatch_once(&sPred, ^{ - FLTPlatformImagesApiCodecReaderWriter *readerWriter = [[FLTPlatformImagesApiCodecReaderWriter alloc] init]; + FLTPlatformImagesApiCodecReaderWriter *readerWriter = + [[FLTPlatformImagesApiCodecReaderWriter alloc] init]; sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; }); return sSharedObject; } -void FLTPlatformImagesApiSetup(id binaryMessenger, NSObject *api) { +void FLTPlatformImagesApiSetup(id binaryMessenger, + NSObject *api) { { - FlutterBasicMessageChannel *channel = - [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.PlatformImagesApi.getSystemImage" + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.PlatformImagesApi.getSystemImage" binaryMessenger:binaryMessenger - codec:FLTPlatformImagesApiGetCodec()]; + codec:FLTPlatformImagesApiGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(getSystemImageName:size:weight:colorsRGBA:preferMulticolor:error:)], @"FLTPlatformImagesApi api (%@) doesn't respond to @selector(getSystemImageName:size:weight:colorsRGBA:preferMulticolor:error:)", api); + NSCAssert([api respondsToSelector:@selector + (getSystemImageName:size:weight:colorsRGBA:preferMulticolor:error:)], + @"FLTPlatformImagesApi api (%@) doesn't respond to " + @"@selector(getSystemImageName:size:weight:colorsRGBA:preferMulticolor:error:)", + api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; NSString *arg_name = GetNullableObjectAtIndex(args, 0); @@ -121,7 +125,12 @@ void FLTPlatformImagesApiSetup(id binaryMessenger, NSObj NSArray *arg_colorsRGBA = GetNullableObjectAtIndex(args, 3); NSNumber *arg_preferMulticolor = GetNullableObjectAtIndex(args, 4); FlutterError *error; - FLTPlatformImage *output = [api getSystemImageName:arg_name size:arg_size weight:arg_weight colorsRGBA:arg_colorsRGBA preferMulticolor:arg_preferMulticolor error:&error]; + FLTPlatformImage *output = [api getSystemImageName:arg_name + size:arg_size + weight:arg_weight + colorsRGBA:arg_colorsRGBA + preferMulticolor:arg_preferMulticolor + error:&error]; callback(wrapResult(output, error)); }]; } else { @@ -129,13 +138,15 @@ void FLTPlatformImagesApiSetup(id binaryMessenger, NSObj } } { - FlutterBasicMessageChannel *channel = - [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.PlatformImagesApi.getPlatformImage" + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.PlatformImagesApi.getPlatformImage" binaryMessenger:binaryMessenger - codec:FLTPlatformImagesApiGetCodec()]; + codec:FLTPlatformImagesApiGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(getPlatformImageName:error:)], @"FLTPlatformImagesApi api (%@) doesn't respond to @selector(getPlatformImageName:error:)", api); + NSCAssert([api respondsToSelector:@selector(getPlatformImageName:error:)], + @"FLTPlatformImagesApi api (%@) doesn't respond to " + @"@selector(getPlatformImageName:error:)", + api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; NSString *arg_name = GetNullableObjectAtIndex(args, 0); @@ -148,13 +159,15 @@ void FLTPlatformImagesApiSetup(id binaryMessenger, NSObj } } { - FlutterBasicMessageChannel *channel = - [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.PlatformImagesApi.resolveURL" + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.PlatformImagesApi.resolveURL" binaryMessenger:binaryMessenger - codec:FLTPlatformImagesApiGetCodec()]; + codec:FLTPlatformImagesApiGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(resolveURLName:extension:error:)], @"FLTPlatformImagesApi api (%@) doesn't respond to @selector(resolveURLName:extension:error:)", api); + NSCAssert([api respondsToSelector:@selector(resolveURLName:extension:error:)], + @"FLTPlatformImagesApi api (%@) doesn't respond to " + @"@selector(resolveURLName:extension:error:)", + api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; NSString *arg_name = GetNullableObjectAtIndex(args, 0); diff --git a/packages/ios_platform_images/lib/platform_images_api.g.dart b/packages/ios_platform_images/lib/platform_images_api.g.dart index a53e7779f19e..ac867a465883 100644 --- a/packages/ios_platform_images/lib/platform_images_api.g.dart +++ b/packages/ios_platform_images/lib/platform_images_api.g.dart @@ -64,7 +64,7 @@ class _PlatformImagesApiCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: + case 128: return PlatformImage.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); @@ -82,12 +82,22 @@ class PlatformImagesApi { static const MessageCodec codec = _PlatformImagesApiCodec(); - Future getSystemImage(String arg_name, double arg_size, FontWeight arg_weight, List arg_colorsRGBA, bool arg_preferMulticolor) async { + Future getSystemImage( + String arg_name, + double arg_size, + FontWeight arg_weight, + List arg_colorsRGBA, + bool arg_preferMulticolor) async { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.PlatformImagesApi.getSystemImage', codec, binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_name, arg_size, arg_weight.index, arg_colorsRGBA, arg_preferMulticolor]) as List?; + final List? replyList = await channel.send([ + arg_name, + arg_size, + arg_weight.index, + arg_colorsRGBA, + arg_preferMulticolor + ]) as List?; if (replyList == null) { throw PlatformException( code: 'channel-error', @@ -130,8 +140,8 @@ class PlatformImagesApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.PlatformImagesApi.resolveURL', codec, binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_name, arg_extension]) as List?; + final List? replyList = await channel + .send([arg_name, arg_extension]) as List?; if (replyList == null) { throw PlatformException( code: 'channel-error', From e43c3b10e1f87114a964fc69f603cea9e982e793 Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Sun, 12 Feb 2023 22:52:09 -0700 Subject: [PATCH 60/64] Rearchitect integration test --- .../ios_platform_images_integration_test.dart | 31 ++++++++++++++++--- .../ios_platform_images/example/lib/main.dart | 6 +++- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/packages/ios_platform_images/example/integration_test/ios_platform_images_integration_test.dart b/packages/ios_platform_images/example/integration_test/ios_platform_images_integration_test.dart index 6b0174130246..ac09cabe6b50 100644 --- a/packages/ios_platform_images/example/integration_test/ios_platform_images_integration_test.dart +++ b/packages/ios_platform_images/example/integration_test/ios_platform_images_integration_test.dart @@ -20,7 +20,13 @@ void main() { app.main(); await tester.pumpAndSettle(); - expect(find.bySemanticsLabel('Flutter logo'), findsOneWidget); + final Finder flutterLogoFinder = find.byKey(const Key('Flutter logo')); + expect(flutterLogoFinder, findsOneWidget); + final Size flutterLogoSize = flutterLogoFinder.evaluate().single.size ?? + fail('Widget size is null'); + + expect(flutterLogoSize.width, equals(101)); + expect(flutterLogoSize.height, equals(125)); }, ); @@ -30,9 +36,26 @@ void main() { app.main(); await tester.pumpAndSettle(); - expect(find.bySemanticsLabel('Smiling face'), findsOneWidget); - expect(find.bySemanticsLabel('Sprinting hare'), findsOneWidget); - expect(find.bySemanticsLabel('Ladybug'), findsOneWidget); + final Finder smilingFaceFinder = find.byKey(const Key('Smiling face')); + expect(smilingFaceFinder, findsOneWidget); + final Size smilingFaceSize = smilingFaceFinder.evaluate().single.size ?? + fail('Smiling face widget size is null'); + expect(smilingFaceSize.width.round(), equals(100)); + expect(smilingFaceSize.height.round(), equals(96)); + + final Finder hammerCircleFinder = find.byKey(const Key('Hammer circle')); + expect(hammerCircleFinder, findsOneWidget); + final Size hammerCircleSize = hammerCircleFinder.evaluate().single.size ?? + fail('Hammer circle widget size is null'); + expect(hammerCircleSize.width.round(), equals(100)); + expect(hammerCircleSize.height.round(), equals(96)); + + final Finder ladybugFinder = find.byKey(const Key('Ladybug')); + expect(ladybugFinder, findsOneWidget); + final Size ladybugSize = ladybugFinder.evaluate().single.size ?? + fail('Ladybug widget size is null'); + expect(ladybugSize.width.round(), equals(116)); + expect(ladybugSize.height.round(), equals(111)); }, ); diff --git a/packages/ios_platform_images/example/lib/main.dart b/packages/ios_platform_images/example/lib/main.dart index 0b433fb87c80..f1f7012c0a34 100644 --- a/packages/ios_platform_images/example/lib/main.dart +++ b/packages/ios_platform_images/example/lib/main.dart @@ -43,16 +43,19 @@ class _MyAppState extends State { children: [ const Text('This is an icon from the iOS asset bundle'), Image( + key: const Key('Flutter logo'), image: IosPlatformImages.load('flutter'), semanticLabel: 'Flutter logo', ), const Text('These are icons from the iOS system'), Image( + key: const Key('Smiling face'), image: IosPlatformImages.loadSystemImage('face.smiling', 100, colors: [iconColor]), semanticLabel: 'Smiling face', ), Image( + key: const Key('Hammer circle'), image: IosPlatformImages.loadSystemImage( 'hammer.circle.fill', 100, @@ -61,9 +64,10 @@ class _MyAppState extends State { theme.colorScheme.primary.withAlpha(100), ], ), - semanticLabel: 'Sprinting hare', + semanticLabel: 'Hammer circle', ), Image( + key: const Key('Ladybug'), image: IosPlatformImages.loadSystemImage( 'ladybug.fill', 100, From b3ac4c1bbbfe02d2cdadfd2cdcd3bbfb305e62fb Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Wed, 15 Feb 2023 17:02:15 -0700 Subject: [PATCH 61/64] Remove pedantic --- packages/ios_platform_images/pubspec.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/ios_platform_images/pubspec.yaml b/packages/ios_platform_images/pubspec.yaml index 9638a1f964e3..8247921f1822 100644 --- a/packages/ios_platform_images/pubspec.yaml +++ b/packages/ios_platform_images/pubspec.yaml @@ -26,5 +26,4 @@ dev_dependencies: integration_test: sdk: flutter mockito: ^5.3.2 - pedantic: ^1.10.0 pigeon: ^8.0.0 From 6cdf8946211436641d40fe97b0687ffd2e43d64a Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Wed, 15 Feb 2023 17:02:59 -0700 Subject: [PATCH 62/64] Tweak Xcode build settings --- .../example/ios/Runner.xcodeproj/project.pbxproj | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/ios_platform_images/example/ios/Runner.xcodeproj/project.pbxproj b/packages/ios_platform_images/example/ios/Runner.xcodeproj/project.pbxproj index f5154fd989de..9a1d20cf03eb 100644 --- a/packages/ios_platform_images/example/ios/Runner.xcodeproj/project.pbxproj +++ b/packages/ios_platform_images/example/ios/Runner.xcodeproj/project.pbxproj @@ -219,7 +219,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1420; + LastUpgradeCheck = 1300; ORGANIZATIONNAME = "The Flutter Authors"; TargetAttributes = { 97C146ED1CF9000F007C117D = { @@ -462,7 +462,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 12.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; @@ -523,7 +523,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -548,7 +548,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 12.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -598,7 +598,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 12.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; From 35b832c0f2cfce2da922c65f38bccb0c8070543e Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Wed, 15 Feb 2023 17:34:19 -0700 Subject: [PATCH 63/64] Fully disable quoted include warnings --- .../example/ios/Runner.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ios_platform_images/example/ios/Runner.xcodeproj/project.pbxproj b/packages/ios_platform_images/example/ios/Runner.xcodeproj/project.pbxproj index 9a1d20cf03eb..05fadc5c003a 100644 --- a/packages/ios_platform_images/example/ios/Runner.xcodeproj/project.pbxproj +++ b/packages/ios_platform_images/example/ios/Runner.xcodeproj/project.pbxproj @@ -443,7 +443,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -579,7 +579,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; From 3bc88fcae48b58c1a66fff457d8b11f7c6c0f63b Mon Sep 17 00:00:00 2001 From: Caden Kriese Date: Thu, 16 Feb 2023 13:53:45 -0700 Subject: [PATCH 64/64] Make integration test accept a range of sizes --- .../ios_platform_images_integration_test.dart | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/ios_platform_images/example/integration_test/ios_platform_images_integration_test.dart b/packages/ios_platform_images/example/integration_test/ios_platform_images_integration_test.dart index ac09cabe6b50..f1a93b4facc0 100644 --- a/packages/ios_platform_images/example/integration_test/ios_platform_images_integration_test.dart +++ b/packages/ios_platform_images/example/integration_test/ios_platform_images_integration_test.dart @@ -25,8 +25,8 @@ void main() { final Size flutterLogoSize = flutterLogoFinder.evaluate().single.size ?? fail('Widget size is null'); - expect(flutterLogoSize.width, equals(101)); - expect(flutterLogoSize.height, equals(125)); + expect(flutterLogoSize.width, closeTo(101, 3)); + expect(flutterLogoSize.height, closeTo(125, 3)); }, ); @@ -40,22 +40,22 @@ void main() { expect(smilingFaceFinder, findsOneWidget); final Size smilingFaceSize = smilingFaceFinder.evaluate().single.size ?? fail('Smiling face widget size is null'); - expect(smilingFaceSize.width.round(), equals(100)); - expect(smilingFaceSize.height.round(), equals(96)); + expect(smilingFaceSize.width.round(), closeTo(100, 3)); + expect(smilingFaceSize.height.round(), closeTo(96, 3)); final Finder hammerCircleFinder = find.byKey(const Key('Hammer circle')); expect(hammerCircleFinder, findsOneWidget); final Size hammerCircleSize = hammerCircleFinder.evaluate().single.size ?? fail('Hammer circle widget size is null'); - expect(hammerCircleSize.width.round(), equals(100)); - expect(hammerCircleSize.height.round(), equals(96)); + expect(hammerCircleSize.width.round(), closeTo(100, 3)); + expect(hammerCircleSize.height.round(), closeTo(96, 3)); final Finder ladybugFinder = find.byKey(const Key('Ladybug')); expect(ladybugFinder, findsOneWidget); final Size ladybugSize = ladybugFinder.evaluate().single.size ?? fail('Ladybug widget size is null'); - expect(ladybugSize.width.round(), equals(116)); - expect(ladybugSize.height.round(), equals(111)); + expect(ladybugSize.width.round(), closeTo(116, 3)); + expect(ladybugSize.height.round(), closeTo(111, 3)); }, );