From 4a6b001b89cbb646125a7bf6b11720b069d65d76 Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Fri, 27 Oct 2023 10:46:26 -0700 Subject: [PATCH 1/9] space --- .../example/app/ios/Runner/Messages.g.swift | 4 +- packages/pigeon/lib/swift_generator.dart | 4 +- .../ios/Classes/CoreTests.gen.swift | 104 +++++++++--------- .../macos/Classes/CoreTests.gen.swift | 104 +++++++++--------- 4 files changed, 108 insertions(+), 108 deletions(-) diff --git a/packages/pigeon/example/app/ios/Runner/Messages.g.swift b/packages/pigeon/example/app/ios/Runner/Messages.g.swift index ef38ee5849c..ae45905a758 100644 --- a/packages/pigeon/example/app/ios/Runner/Messages.g.swift +++ b/packages/pigeon/example/app/ios/Runner/Messages.g.swift @@ -175,14 +175,14 @@ class ExampleHostApiSetup { } /// Generated protocol from Pigeon that represents Flutter messages that can be called from Swift. protocol MessageFlutterApiProtocol { - func flutterMethod(aString aStringArg: String?, completion: @escaping (Result) -> Void) + func flutterMethod(aString aStringArg: String?, completion: @escaping (Result) -> Void) } class MessageFlutterApi: MessageFlutterApiProtocol { private let binaryMessenger: FlutterBinaryMessenger init(binaryMessenger: FlutterBinaryMessenger){ self.binaryMessenger = binaryMessenger } - func flutterMethod(aString aStringArg: String?, completion: @escaping (Result) -> Void) { + func flutterMethod(aString aStringArg: String?, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_example_package.MessageFlutterApi.flutterMethod", binaryMessenger: binaryMessenger) channel.sendMessage([aStringArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { diff --git a/packages/pigeon/lib/swift_generator.dart b/packages/pigeon/lib/swift_generator.dart index af96efd0205..762b318c067 100644 --- a/packages/pigeon/lib/swift_generator.dart +++ b/packages/pigeon/lib/swift_generator.dart @@ -882,7 +882,7 @@ String _getMethodSignature(Method func) { : _nullsafeSwiftTypeForDartType(func.returnType); if (func.arguments.isEmpty) { - return 'func ${func.name}(completion: @escaping (Result<$returnType, FlutterError>) -> Void) '; + return 'func ${func.name}(completion: @escaping (Result<$returnType, FlutterError>) -> Void)'; } else { final Iterable argTypes = func.arguments .map((NamedType e) => _nullsafeSwiftTypeForDartType(e.type)); @@ -895,7 +895,7 @@ String _getMethodSignature(Method func) { final String argsSignature = map3(argTypes, argLabels, argNames, (String type, String label, String name) => '$label $name: $type') .join(', '); - return 'func ${components.name}($argsSignature, completion: @escaping (Result<$returnType, FlutterError>) -> Void) '; + return 'func ${components.name}($argsSignature, completion: @escaping (Result<$returnType, FlutterError>) -> Void)'; } } diff --git a/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift index 8b83e3d1771..3beab718895 100644 --- a/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift +++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift @@ -1743,56 +1743,56 @@ class FlutterIntegrationCoreApiCodec: FlutterStandardMessageCodec { protocol FlutterIntegrationCoreApiProtocol { /// A no-op function taking no arguments and returning no value, to sanity /// test basic calling. - func noop(completion: @escaping (Result) -> Void) + func noop(completion: @escaping (Result) -> Void) /// Responds with an error from an async function returning a value. - func throwError(completion: @escaping (Result) -> Void) + func throwError(completion: @escaping (Result) -> Void) /// Responds with an error from an async void function. - func throwErrorFromVoid(completion: @escaping (Result) -> Void) + func throwErrorFromVoid(completion: @escaping (Result) -> Void) /// Returns the passed object, to test serialization and deserialization. - func echo(_ everythingArg: AllTypes, completion: @escaping (Result) -> Void) + func echo(_ everythingArg: AllTypes, completion: @escaping (Result) -> Void) /// Returns the passed object, to test serialization and deserialization. - func echoNullable(_ everythingArg: AllNullableTypes?, completion: @escaping (Result) -> Void) + func echoNullable(_ everythingArg: AllNullableTypes?, completion: @escaping (Result) -> Void) /// Returns passed in arguments of multiple types. /// /// Tests multiple-arity FlutterApi handling. - func sendMultipleNullableTypes(aBool aNullableBoolArg: Bool?, anInt aNullableIntArg: Int64?, aString aNullableStringArg: String?, completion: @escaping (Result) -> Void) + func sendMultipleNullableTypes(aBool aNullableBoolArg: Bool?, anInt aNullableIntArg: Int64?, aString aNullableStringArg: String?, completion: @escaping (Result) -> Void) /// Returns the passed boolean, to test serialization and deserialization. - func echo(_ aBoolArg: Bool, completion: @escaping (Result) -> Void) + func echo(_ aBoolArg: Bool, completion: @escaping (Result) -> Void) /// Returns the passed int, to test serialization and deserialization. - func echo(_ anIntArg: Int64, completion: @escaping (Result) -> Void) + func echo(_ anIntArg: Int64, completion: @escaping (Result) -> Void) /// Returns the passed double, to test serialization and deserialization. - func echo(_ aDoubleArg: Double, completion: @escaping (Result) -> Void) + func echo(_ aDoubleArg: Double, completion: @escaping (Result) -> Void) /// Returns the passed string, to test serialization and deserialization. - func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) + func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) /// Returns the passed byte list, to test serialization and deserialization. - func echo(_ aListArg: FlutterStandardTypedData, completion: @escaping (Result) -> Void) + func echo(_ aListArg: FlutterStandardTypedData, completion: @escaping (Result) -> Void) /// Returns the passed list, to test serialization and deserialization. - func echo(_ aListArg: [Any?], completion: @escaping (Result<[Any?], FlutterError>) -> Void) + func echo(_ aListArg: [Any?], completion: @escaping (Result<[Any?], FlutterError>) -> Void) /// Returns the passed map, to test serialization and deserialization. - func echo(_ aMapArg: [String?: Any?], completion: @escaping (Result<[String?: Any?], FlutterError>) -> Void) + func echo(_ aMapArg: [String?: Any?], completion: @escaping (Result<[String?: Any?], FlutterError>) -> Void) /// Returns the passed enum to test serialization and deserialization. - func echo(_ anEnumArg: AnEnum, completion: @escaping (Result) -> Void) + func echo(_ anEnumArg: AnEnum, completion: @escaping (Result) -> Void) /// Returns the passed boolean, to test serialization and deserialization. - func echoNullable(_ aBoolArg: Bool?, completion: @escaping (Result) -> Void) + func echoNullable(_ aBoolArg: Bool?, completion: @escaping (Result) -> Void) /// Returns the passed int, to test serialization and deserialization. - func echoNullable(_ anIntArg: Int64?, completion: @escaping (Result) -> Void) + func echoNullable(_ anIntArg: Int64?, completion: @escaping (Result) -> Void) /// Returns the passed double, to test serialization and deserialization. - func echoNullable(_ aDoubleArg: Double?, completion: @escaping (Result) -> Void) + func echoNullable(_ aDoubleArg: Double?, completion: @escaping (Result) -> Void) /// Returns the passed string, to test serialization and deserialization. - func echoNullable(_ aStringArg: String?, completion: @escaping (Result) -> Void) + func echoNullable(_ aStringArg: String?, completion: @escaping (Result) -> Void) /// Returns the passed byte list, to test serialization and deserialization. - func echoNullable(_ aListArg: FlutterStandardTypedData?, completion: @escaping (Result) -> Void) + func echoNullable(_ aListArg: FlutterStandardTypedData?, completion: @escaping (Result) -> Void) /// Returns the passed list, to test serialization and deserialization. - func echoNullable(_ aListArg: [Any?]?, completion: @escaping (Result<[Any?]?, FlutterError>) -> Void) + func echoNullable(_ aListArg: [Any?]?, completion: @escaping (Result<[Any?]?, FlutterError>) -> Void) /// Returns the passed map, to test serialization and deserialization. - func echoNullable(_ aMapArg: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, FlutterError>) -> Void) + func echoNullable(_ aMapArg: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, FlutterError>) -> Void) /// Returns the passed enum to test serialization and deserialization. - func echoNullable(_ anEnumArg: AnEnum?, completion: @escaping (Result) -> Void) + func echoNullable(_ anEnumArg: AnEnum?, completion: @escaping (Result) -> Void) /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. - func noopAsync(completion: @escaping (Result) -> Void) + func noopAsync(completion: @escaping (Result) -> Void) /// Returns the passed in generic Object asynchronously. - func echoAsync(_ aStringArg: String, completion: @escaping (Result) -> Void) + func echoAsync(_ aStringArg: String, completion: @escaping (Result) -> Void) } class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { private let binaryMessenger: FlutterBinaryMessenger @@ -1804,14 +1804,14 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } /// A no-op function taking no arguments and returning no value, to sanity /// test basic calling. - func noop(completion: @escaping (Result) -> Void) { + func noop(completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.noop", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage(nil) { _ in completion(.success(Void())) } } /// Responds with an error from an async function returning a value. - func throwError(completion: @escaping (Result) -> Void) { + func throwError(completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.throwError", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage(nil) { response in guard let listResponse = response as? [Any?] else { @@ -1830,14 +1830,14 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Responds with an error from an async void function. - func throwErrorFromVoid(completion: @escaping (Result) -> Void) { + func throwErrorFromVoid(completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.throwErrorFromVoid", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage(nil) { _ in completion(.success(Void())) } } /// Returns the passed object, to test serialization and deserialization. - func echo(_ everythingArg: AllTypes, completion: @escaping (Result) -> Void) { + func echo(_ everythingArg: AllTypes, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAllTypes", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([everythingArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -1858,7 +1858,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed object, to test serialization and deserialization. - func echoNullable(_ everythingArg: AllNullableTypes?, completion: @escaping (Result) -> Void) { + func echoNullable(_ everythingArg: AllNullableTypes?, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAllNullableTypes", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([everythingArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -1879,7 +1879,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { /// Returns passed in arguments of multiple types. /// /// Tests multiple-arity FlutterApi handling. - func sendMultipleNullableTypes(aBool aNullableBoolArg: Bool?, anInt aNullableIntArg: Int64?, aString aNullableStringArg: String?, completion: @escaping (Result) -> Void) { + func sendMultipleNullableTypes(aBool aNullableBoolArg: Bool?, anInt aNullableIntArg: Int64?, aString aNullableStringArg: String?, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.sendMultipleNullableTypes", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aNullableBoolArg, aNullableIntArg, aNullableStringArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -1900,7 +1900,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed boolean, to test serialization and deserialization. - func echo(_ aBoolArg: Bool, completion: @escaping (Result) -> Void) { + func echo(_ aBoolArg: Bool, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoBool", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aBoolArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -1921,7 +1921,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed int, to test serialization and deserialization. - func echo(_ anIntArg: Int64, completion: @escaping (Result) -> Void) { + func echo(_ anIntArg: Int64, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoInt", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([anIntArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -1942,7 +1942,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed double, to test serialization and deserialization. - func echo(_ aDoubleArg: Double, completion: @escaping (Result) -> Void) { + func echo(_ aDoubleArg: Double, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoDouble", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aDoubleArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -1963,7 +1963,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed string, to test serialization and deserialization. - func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) { + func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoString", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aStringArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -1984,7 +1984,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed byte list, to test serialization and deserialization. - func echo(_ aListArg: FlutterStandardTypedData, completion: @escaping (Result) -> Void) { + func echo(_ aListArg: FlutterStandardTypedData, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoUint8List", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aListArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -2005,7 +2005,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed list, to test serialization and deserialization. - func echo(_ aListArg: [Any?], completion: @escaping (Result<[Any?], FlutterError>) -> Void) { + func echo(_ aListArg: [Any?], completion: @escaping (Result<[Any?], FlutterError>) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoList", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aListArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -2026,7 +2026,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed map, to test serialization and deserialization. - func echo(_ aMapArg: [String?: Any?], completion: @escaping (Result<[String?: Any?], FlutterError>) -> Void) { + func echo(_ aMapArg: [String?: Any?], completion: @escaping (Result<[String?: Any?], FlutterError>) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoMap", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aMapArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -2047,7 +2047,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed enum to test serialization and deserialization. - func echo(_ anEnumArg: AnEnum, completion: @escaping (Result) -> Void) { + func echo(_ anEnumArg: AnEnum, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoEnum", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([anEnumArg.rawValue] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -2068,7 +2068,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed boolean, to test serialization and deserialization. - func echoNullable(_ aBoolArg: Bool?, completion: @escaping (Result) -> Void) { + func echoNullable(_ aBoolArg: Bool?, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableBool", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aBoolArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -2087,7 +2087,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed int, to test serialization and deserialization. - func echoNullable(_ anIntArg: Int64?, completion: @escaping (Result) -> Void) { + func echoNullable(_ anIntArg: Int64?, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableInt", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([anIntArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -2106,7 +2106,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed double, to test serialization and deserialization. - func echoNullable(_ aDoubleArg: Double?, completion: @escaping (Result) -> Void) { + func echoNullable(_ aDoubleArg: Double?, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableDouble", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aDoubleArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -2125,7 +2125,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed string, to test serialization and deserialization. - func echoNullable(_ aStringArg: String?, completion: @escaping (Result) -> Void) { + func echoNullable(_ aStringArg: String?, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableString", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aStringArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -2144,7 +2144,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed byte list, to test serialization and deserialization. - func echoNullable(_ aListArg: FlutterStandardTypedData?, completion: @escaping (Result) -> Void) { + func echoNullable(_ aListArg: FlutterStandardTypedData?, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableUint8List", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aListArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -2163,7 +2163,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed list, to test serialization and deserialization. - func echoNullable(_ aListArg: [Any?]?, completion: @escaping (Result<[Any?]?, FlutterError>) -> Void) { + func echoNullable(_ aListArg: [Any?]?, completion: @escaping (Result<[Any?]?, FlutterError>) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableList", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aListArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -2182,7 +2182,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed map, to test serialization and deserialization. - func echoNullable(_ aMapArg: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, FlutterError>) -> Void) { + func echoNullable(_ aMapArg: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, FlutterError>) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableMap", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aMapArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -2201,7 +2201,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed enum to test serialization and deserialization. - func echoNullable(_ anEnumArg: AnEnum?, completion: @escaping (Result) -> Void) { + func echoNullable(_ anEnumArg: AnEnum?, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableEnum", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([anEnumArg?.rawValue] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -2221,14 +2221,14 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. - func noopAsync(completion: @escaping (Result) -> Void) { + func noopAsync(completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.noopAsync", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage(nil) { _ in completion(.success(Void())) } } /// Returns the passed in generic Object asynchronously. - func echoAsync(_ aStringArg: String, completion: @escaping (Result) -> Void) { + func echoAsync(_ aStringArg: String, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAsyncString", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aStringArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -2363,8 +2363,8 @@ class FlutterSmallApiCodec: FlutterStandardMessageCodec { /// /// Generated protocol from Pigeon that represents Flutter messages that can be called from Swift. protocol FlutterSmallApiProtocol { - func echo(_ msgArg: TestMessage, completion: @escaping (Result) -> Void) - func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) + func echo(_ msgArg: TestMessage, completion: @escaping (Result) -> Void) + func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) } class FlutterSmallApi: FlutterSmallApiProtocol { private let binaryMessenger: FlutterBinaryMessenger @@ -2374,7 +2374,7 @@ class FlutterSmallApi: FlutterSmallApiProtocol { var codec: FlutterStandardMessageCodec { return FlutterSmallApiCodec.shared } - func echo(_ msgArg: TestMessage, completion: @escaping (Result) -> Void) { + func echo(_ msgArg: TestMessage, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi.echoWrappedList", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([msgArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -2394,7 +2394,7 @@ class FlutterSmallApi: FlutterSmallApiProtocol { } } } - func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) { + func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi.echoString", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aStringArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { diff --git a/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift index 8b83e3d1771..3beab718895 100644 --- a/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift +++ b/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift @@ -1743,56 +1743,56 @@ class FlutterIntegrationCoreApiCodec: FlutterStandardMessageCodec { protocol FlutterIntegrationCoreApiProtocol { /// A no-op function taking no arguments and returning no value, to sanity /// test basic calling. - func noop(completion: @escaping (Result) -> Void) + func noop(completion: @escaping (Result) -> Void) /// Responds with an error from an async function returning a value. - func throwError(completion: @escaping (Result) -> Void) + func throwError(completion: @escaping (Result) -> Void) /// Responds with an error from an async void function. - func throwErrorFromVoid(completion: @escaping (Result) -> Void) + func throwErrorFromVoid(completion: @escaping (Result) -> Void) /// Returns the passed object, to test serialization and deserialization. - func echo(_ everythingArg: AllTypes, completion: @escaping (Result) -> Void) + func echo(_ everythingArg: AllTypes, completion: @escaping (Result) -> Void) /// Returns the passed object, to test serialization and deserialization. - func echoNullable(_ everythingArg: AllNullableTypes?, completion: @escaping (Result) -> Void) + func echoNullable(_ everythingArg: AllNullableTypes?, completion: @escaping (Result) -> Void) /// Returns passed in arguments of multiple types. /// /// Tests multiple-arity FlutterApi handling. - func sendMultipleNullableTypes(aBool aNullableBoolArg: Bool?, anInt aNullableIntArg: Int64?, aString aNullableStringArg: String?, completion: @escaping (Result) -> Void) + func sendMultipleNullableTypes(aBool aNullableBoolArg: Bool?, anInt aNullableIntArg: Int64?, aString aNullableStringArg: String?, completion: @escaping (Result) -> Void) /// Returns the passed boolean, to test serialization and deserialization. - func echo(_ aBoolArg: Bool, completion: @escaping (Result) -> Void) + func echo(_ aBoolArg: Bool, completion: @escaping (Result) -> Void) /// Returns the passed int, to test serialization and deserialization. - func echo(_ anIntArg: Int64, completion: @escaping (Result) -> Void) + func echo(_ anIntArg: Int64, completion: @escaping (Result) -> Void) /// Returns the passed double, to test serialization and deserialization. - func echo(_ aDoubleArg: Double, completion: @escaping (Result) -> Void) + func echo(_ aDoubleArg: Double, completion: @escaping (Result) -> Void) /// Returns the passed string, to test serialization and deserialization. - func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) + func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) /// Returns the passed byte list, to test serialization and deserialization. - func echo(_ aListArg: FlutterStandardTypedData, completion: @escaping (Result) -> Void) + func echo(_ aListArg: FlutterStandardTypedData, completion: @escaping (Result) -> Void) /// Returns the passed list, to test serialization and deserialization. - func echo(_ aListArg: [Any?], completion: @escaping (Result<[Any?], FlutterError>) -> Void) + func echo(_ aListArg: [Any?], completion: @escaping (Result<[Any?], FlutterError>) -> Void) /// Returns the passed map, to test serialization and deserialization. - func echo(_ aMapArg: [String?: Any?], completion: @escaping (Result<[String?: Any?], FlutterError>) -> Void) + func echo(_ aMapArg: [String?: Any?], completion: @escaping (Result<[String?: Any?], FlutterError>) -> Void) /// Returns the passed enum to test serialization and deserialization. - func echo(_ anEnumArg: AnEnum, completion: @escaping (Result) -> Void) + func echo(_ anEnumArg: AnEnum, completion: @escaping (Result) -> Void) /// Returns the passed boolean, to test serialization and deserialization. - func echoNullable(_ aBoolArg: Bool?, completion: @escaping (Result) -> Void) + func echoNullable(_ aBoolArg: Bool?, completion: @escaping (Result) -> Void) /// Returns the passed int, to test serialization and deserialization. - func echoNullable(_ anIntArg: Int64?, completion: @escaping (Result) -> Void) + func echoNullable(_ anIntArg: Int64?, completion: @escaping (Result) -> Void) /// Returns the passed double, to test serialization and deserialization. - func echoNullable(_ aDoubleArg: Double?, completion: @escaping (Result) -> Void) + func echoNullable(_ aDoubleArg: Double?, completion: @escaping (Result) -> Void) /// Returns the passed string, to test serialization and deserialization. - func echoNullable(_ aStringArg: String?, completion: @escaping (Result) -> Void) + func echoNullable(_ aStringArg: String?, completion: @escaping (Result) -> Void) /// Returns the passed byte list, to test serialization and deserialization. - func echoNullable(_ aListArg: FlutterStandardTypedData?, completion: @escaping (Result) -> Void) + func echoNullable(_ aListArg: FlutterStandardTypedData?, completion: @escaping (Result) -> Void) /// Returns the passed list, to test serialization and deserialization. - func echoNullable(_ aListArg: [Any?]?, completion: @escaping (Result<[Any?]?, FlutterError>) -> Void) + func echoNullable(_ aListArg: [Any?]?, completion: @escaping (Result<[Any?]?, FlutterError>) -> Void) /// Returns the passed map, to test serialization and deserialization. - func echoNullable(_ aMapArg: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, FlutterError>) -> Void) + func echoNullable(_ aMapArg: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, FlutterError>) -> Void) /// Returns the passed enum to test serialization and deserialization. - func echoNullable(_ anEnumArg: AnEnum?, completion: @escaping (Result) -> Void) + func echoNullable(_ anEnumArg: AnEnum?, completion: @escaping (Result) -> Void) /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. - func noopAsync(completion: @escaping (Result) -> Void) + func noopAsync(completion: @escaping (Result) -> Void) /// Returns the passed in generic Object asynchronously. - func echoAsync(_ aStringArg: String, completion: @escaping (Result) -> Void) + func echoAsync(_ aStringArg: String, completion: @escaping (Result) -> Void) } class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { private let binaryMessenger: FlutterBinaryMessenger @@ -1804,14 +1804,14 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } /// A no-op function taking no arguments and returning no value, to sanity /// test basic calling. - func noop(completion: @escaping (Result) -> Void) { + func noop(completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.noop", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage(nil) { _ in completion(.success(Void())) } } /// Responds with an error from an async function returning a value. - func throwError(completion: @escaping (Result) -> Void) { + func throwError(completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.throwError", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage(nil) { response in guard let listResponse = response as? [Any?] else { @@ -1830,14 +1830,14 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Responds with an error from an async void function. - func throwErrorFromVoid(completion: @escaping (Result) -> Void) { + func throwErrorFromVoid(completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.throwErrorFromVoid", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage(nil) { _ in completion(.success(Void())) } } /// Returns the passed object, to test serialization and deserialization. - func echo(_ everythingArg: AllTypes, completion: @escaping (Result) -> Void) { + func echo(_ everythingArg: AllTypes, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAllTypes", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([everythingArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -1858,7 +1858,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed object, to test serialization and deserialization. - func echoNullable(_ everythingArg: AllNullableTypes?, completion: @escaping (Result) -> Void) { + func echoNullable(_ everythingArg: AllNullableTypes?, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAllNullableTypes", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([everythingArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -1879,7 +1879,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { /// Returns passed in arguments of multiple types. /// /// Tests multiple-arity FlutterApi handling. - func sendMultipleNullableTypes(aBool aNullableBoolArg: Bool?, anInt aNullableIntArg: Int64?, aString aNullableStringArg: String?, completion: @escaping (Result) -> Void) { + func sendMultipleNullableTypes(aBool aNullableBoolArg: Bool?, anInt aNullableIntArg: Int64?, aString aNullableStringArg: String?, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.sendMultipleNullableTypes", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aNullableBoolArg, aNullableIntArg, aNullableStringArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -1900,7 +1900,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed boolean, to test serialization and deserialization. - func echo(_ aBoolArg: Bool, completion: @escaping (Result) -> Void) { + func echo(_ aBoolArg: Bool, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoBool", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aBoolArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -1921,7 +1921,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed int, to test serialization and deserialization. - func echo(_ anIntArg: Int64, completion: @escaping (Result) -> Void) { + func echo(_ anIntArg: Int64, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoInt", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([anIntArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -1942,7 +1942,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed double, to test serialization and deserialization. - func echo(_ aDoubleArg: Double, completion: @escaping (Result) -> Void) { + func echo(_ aDoubleArg: Double, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoDouble", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aDoubleArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -1963,7 +1963,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed string, to test serialization and deserialization. - func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) { + func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoString", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aStringArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -1984,7 +1984,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed byte list, to test serialization and deserialization. - func echo(_ aListArg: FlutterStandardTypedData, completion: @escaping (Result) -> Void) { + func echo(_ aListArg: FlutterStandardTypedData, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoUint8List", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aListArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -2005,7 +2005,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed list, to test serialization and deserialization. - func echo(_ aListArg: [Any?], completion: @escaping (Result<[Any?], FlutterError>) -> Void) { + func echo(_ aListArg: [Any?], completion: @escaping (Result<[Any?], FlutterError>) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoList", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aListArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -2026,7 +2026,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed map, to test serialization and deserialization. - func echo(_ aMapArg: [String?: Any?], completion: @escaping (Result<[String?: Any?], FlutterError>) -> Void) { + func echo(_ aMapArg: [String?: Any?], completion: @escaping (Result<[String?: Any?], FlutterError>) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoMap", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aMapArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -2047,7 +2047,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed enum to test serialization and deserialization. - func echo(_ anEnumArg: AnEnum, completion: @escaping (Result) -> Void) { + func echo(_ anEnumArg: AnEnum, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoEnum", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([anEnumArg.rawValue] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -2068,7 +2068,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed boolean, to test serialization and deserialization. - func echoNullable(_ aBoolArg: Bool?, completion: @escaping (Result) -> Void) { + func echoNullable(_ aBoolArg: Bool?, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableBool", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aBoolArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -2087,7 +2087,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed int, to test serialization and deserialization. - func echoNullable(_ anIntArg: Int64?, completion: @escaping (Result) -> Void) { + func echoNullable(_ anIntArg: Int64?, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableInt", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([anIntArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -2106,7 +2106,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed double, to test serialization and deserialization. - func echoNullable(_ aDoubleArg: Double?, completion: @escaping (Result) -> Void) { + func echoNullable(_ aDoubleArg: Double?, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableDouble", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aDoubleArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -2125,7 +2125,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed string, to test serialization and deserialization. - func echoNullable(_ aStringArg: String?, completion: @escaping (Result) -> Void) { + func echoNullable(_ aStringArg: String?, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableString", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aStringArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -2144,7 +2144,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed byte list, to test serialization and deserialization. - func echoNullable(_ aListArg: FlutterStandardTypedData?, completion: @escaping (Result) -> Void) { + func echoNullable(_ aListArg: FlutterStandardTypedData?, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableUint8List", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aListArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -2163,7 +2163,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed list, to test serialization and deserialization. - func echoNullable(_ aListArg: [Any?]?, completion: @escaping (Result<[Any?]?, FlutterError>) -> Void) { + func echoNullable(_ aListArg: [Any?]?, completion: @escaping (Result<[Any?]?, FlutterError>) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableList", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aListArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -2182,7 +2182,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed map, to test serialization and deserialization. - func echoNullable(_ aMapArg: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, FlutterError>) -> Void) { + func echoNullable(_ aMapArg: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, FlutterError>) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableMap", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aMapArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -2201,7 +2201,7 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed enum to test serialization and deserialization. - func echoNullable(_ anEnumArg: AnEnum?, completion: @escaping (Result) -> Void) { + func echoNullable(_ anEnumArg: AnEnum?, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableEnum", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([anEnumArg?.rawValue] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -2221,14 +2221,14 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. - func noopAsync(completion: @escaping (Result) -> Void) { + func noopAsync(completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.noopAsync", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage(nil) { _ in completion(.success(Void())) } } /// Returns the passed in generic Object asynchronously. - func echoAsync(_ aStringArg: String, completion: @escaping (Result) -> Void) { + func echoAsync(_ aStringArg: String, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAsyncString", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aStringArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -2363,8 +2363,8 @@ class FlutterSmallApiCodec: FlutterStandardMessageCodec { /// /// Generated protocol from Pigeon that represents Flutter messages that can be called from Swift. protocol FlutterSmallApiProtocol { - func echo(_ msgArg: TestMessage, completion: @escaping (Result) -> Void) - func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) + func echo(_ msgArg: TestMessage, completion: @escaping (Result) -> Void) + func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) } class FlutterSmallApi: FlutterSmallApiProtocol { private let binaryMessenger: FlutterBinaryMessenger @@ -2374,7 +2374,7 @@ class FlutterSmallApi: FlutterSmallApiProtocol { var codec: FlutterStandardMessageCodec { return FlutterSmallApiCodec.shared } - func echo(_ msgArg: TestMessage, completion: @escaping (Result) -> Void) { + func echo(_ msgArg: TestMessage, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi.echoWrappedList", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([msgArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { @@ -2394,7 +2394,7 @@ class FlutterSmallApi: FlutterSmallApiProtocol { } } } - func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) { + func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) { let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi.echoString", binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aStringArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { From a8e29a61a29e5f8fba83d670232e874327f58dd5 Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Thu, 30 Nov 2023 08:02:12 -0800 Subject: [PATCH 2/9] tests --- .../plugins/imagepicker/ImageResizer.java | 18 +++++++++--------- .../plugins/imagepicker/ImageResizerTest.java | 18 ++++++++++++++++++ .../src/test/resources/jpgImageTall.jpg | Bin 0 -> 3390 bytes .../src/test/resources/jpgImageWide.jpg | Bin 0 -> 3290 bytes .../ios/RunnerTests/ImagePickerTestImages.h | 1 + .../ios/RunnerTests/ImagePickerTestImages.m | 15 +++++++++++++++ .../example/ios/RunnerTests/ImageUtilTests.m | 13 +++++++++++++ .../example/ios/TestImages/jpgImageTall.jpg | Bin 0 -> 3390 bytes .../ios/Classes/FLTImagePickerImageUtil.m | 16 ++++++++-------- 9 files changed, 64 insertions(+), 17 deletions(-) create mode 100644 packages/image_picker/image_picker_android/android/src/test/resources/jpgImageTall.jpg create mode 100644 packages/image_picker/image_picker_android/android/src/test/resources/jpgImageWide.jpg create mode 100644 packages/image_picker/image_picker_ios/example/ios/TestImages/jpgImageTall.jpg diff --git a/packages/image_picker/image_picker_android/android/src/main/java/io/flutter/plugins/imagepicker/ImageResizer.java b/packages/image_picker/image_picker_android/android/src/main/java/io/flutter/plugins/imagepicker/ImageResizer.java index b5024d6780c..e90be74f718 100644 --- a/packages/image_picker/image_picker_android/android/src/main/java/io/flutter/plugins/imagepicker/ImageResizer.java +++ b/packages/image_picker/image_picker_android/android/src/main/java/io/flutter/plugins/imagepicker/ImageResizer.java @@ -98,26 +98,26 @@ private SizeFCompat calculateTargetSize( boolean shouldDownscale = shouldDownscaleWidth || shouldDownscaleHeight; if (shouldDownscale) { - double downscaledWidth = (height / originalHeight) * originalWidth; - double downscaledHeight = (width / originalWidth) * originalHeight; + double downScaledWidth = (height / originalHeight) * originalWidth; + double downScaledHeight = (width / originalWidth) * originalHeight; if (width < height) { if (!hasMaxWidth) { - width = downscaledWidth; + width = downScaledWidth; } else { - height = downscaledHeight; + height = downScaledHeight; } } else if (height < width) { if (!hasMaxHeight) { - height = downscaledHeight; + height = downScaledHeight; } else { - width = downscaledWidth; + width = downScaledWidth; } } else { if (originalWidth < originalHeight) { - width = downscaledWidth; + width = downScaledWidth; } else if (originalHeight < originalWidth) { - height = downscaledHeight; + height = downScaledHeight; } } } @@ -145,7 +145,7 @@ private void copyExif(String filePathOri, String filePathDest) { } } - private SizeFCompat readFileDimensions(String path) { + SizeFCompat readFileDimensions(String path) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; decodeFile(path, options); diff --git a/packages/image_picker/image_picker_android/android/src/test/java/io/flutter/plugins/imagepicker/ImageResizerTest.java b/packages/image_picker/image_picker_android/android/src/test/java/io/flutter/plugins/imagepicker/ImageResizerTest.java index d54471786ca..b2f012879f6 100644 --- a/packages/image_picker/image_picker_android/android/src/test/java/io/flutter/plugins/imagepicker/ImageResizerTest.java +++ b/packages/image_picker/image_picker_android/android/src/test/java/io/flutter/plugins/imagepicker/ImageResizerTest.java @@ -18,6 +18,9 @@ import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; + +import androidx.core.util.SizeFCompat; + import java.io.File; import java.io.IOException; import java.util.List; @@ -40,6 +43,8 @@ public class ImageResizerTest { Context mockContext; File imageFile; File svgImageFile; + File tallJPG; + File wideJPG; File externalDirectory; Bitmap originalImageBitmap; @@ -50,6 +55,8 @@ public void setUp() throws IOException { mockCloseable = MockitoAnnotations.openMocks(this); imageFile = new File(getClass().getClassLoader().getResource("pngImage.png").getFile()); svgImageFile = new File(getClass().getClassLoader().getResource("flutter_image.svg").getFile()); + tallJPG = new File(getClass().getClassLoader().getResource("jpgImageTall.jpg").getFile()); + wideJPG = new File(getClass().getClassLoader().getResource("jpgImageWide.jpg").getFile()); originalImageBitmap = BitmapFactory.decodeFile(imageFile.getPath()); TemporaryFolder temporaryFolder = new TemporaryFolder(); temporaryFolder.create(); @@ -134,4 +141,15 @@ public void onResizeImageIfNeeded_whenResizeIsNecessary_shouldDecodeBitmapPixels assertFalse(capturedOptions.get(1).inJustDecodeBounds); } } + + @Test + public void onResizeImageIfNeeded_whenHeightAndWidthAreNotNull_shouldResizeCorrectly() { + String outputFile = resizer.resizeImageIfNeeded(tallJPG.getPath(), 6.0, 6.0, 100); + SizeFCompat originalSize = resizer.readFileDimensions(externalDirectory.getPath() + "/scaled_jpgImageTall.jpg"); + + float width = originalSize.getWidth(); + float height = originalSize.getHeight(); + assertThat(width, equalTo(4)); + assertThat(height, equalTo(6)); + } } diff --git a/packages/image_picker/image_picker_android/android/src/test/resources/jpgImageTall.jpg b/packages/image_picker/image_picker_android/android/src/test/resources/jpgImageTall.jpg new file mode 100644 index 0000000000000000000000000000000000000000..d7c137eb5ae1bbbc51e73f2d34c43f73a3a8d0e0 GIT binary patch literal 3390 zcmeHKNpRa_6n?)pFNqT?Zi2H7s?tCy6U%nm5_{@q8mCDU#!Q>8WQKz+E4G?gawVm9 zGs6rmOQFN1l(na{Wofw;DC+@QTDA+*Lg_Zl5O$bhXenzi;+NtmloN2pPczb!{_j1# z@B4N5WS%!a1OM>A&;TF=5W)wTGw|^0vOETmO2HBUa087RfW#TX2cQ<9?HphjwL19- zT3o>p0J~+NDwt7xwE}mxsw-D=8qIf{CLA<1O**;DDl=z1=kkV8j0=LIhtgR!BZWk@ zAe7TZArcA;u%fqIOpD`^!DXbJtR(m!-*}Vf!54Xm3NK zK(=-cwqY|#0MSM$;BhR)BDzj|PB&Cu}r4I4LY z-g4)tn3cwId3mdDOl~igcTC-T-~A8le(<3^kL-K&vB#fy@~Qm?4?X?Nv(Ftq^85=g zzI5#6S6+SX^%HNOJoV1I@4f%QnU6j``^mZU7cS0x{>7JHef`b1-+h1Or>j5z^6PKE z|8dRYg>CdKEqtD3_BUQE=0#8xNx3Xuh$vaaS&Cj5VH#GgbEUTh_~=geg1)^6jvn`P zbdOwa%xI^*O^cS!bY8Kj+06bKv0eX(nL})z*Cj~e{lkH`gCr>m?~|8dXqu^YdtBbS z+WNY>TA#0;Z3@);8(E((&=P3Gvo<%^H?+352HTs0%|R14LAaEmnHq+v3Hp8h;J*&@ eQ~WoA%!^PG= literal 0 HcmV?d00001 diff --git a/packages/image_picker/image_picker_android/android/src/test/resources/jpgImageWide.jpg b/packages/image_picker/image_picker_android/android/src/test/resources/jpgImageWide.jpg new file mode 100644 index 0000000000000000000000000000000000000000..12b2dc17624c028f8627b0aa72b82763cbab81e4 GIT binary patch literal 3290 zcmex=kR1VRQz zDF#+Bn}NZLQ5wz;V$^`DVPart&tzbMs)+*9AOJKOq#H^zFJMHNxPS?+nr8tsoXrl> z_WvPgaYji=ft9{~Ua?+cN`6wRUUGh}ennz|zM-ChK7);YML}Y6c4~=2Qfhi;o~_dR z-TRdkGE;1o!cBb*d<&dYGcrA@ic*8C{6dnevXd=SljF4@-9<|J>PIC z)FAWfZHvW%{|_(-axkzn@GvtfF)#@-G7B>PKf)jnY#6dKf&o|?kYHqDW?^Mx=iubx z1}fMpz`(@F%*@2X%*qOK1Y<2wo`FS>RY=j$kxe)-kzJ`!#HexNLJno8jR!@8E`Crk zPAY2R|V^&07y2J$~}^+4C1KUw!=a`ODXD-+%o41@afLi3{--kc9XQ&0m5*e=)JJ zFtf0O{Kd#r4)VAl3#+0bn~-B5dt#xml2Idvh||P{8xL|S8wY(5O)9#`C8lEXQ1v6o zYha%d=dmWTdeO? z6Xq8X73Ad=mJ${Px>Zt=Ur1V3T0&M#LQ>*C&=5wTRyI~PZZ8WQKz+E4G?gawVm9 zGs6rmOQFN1l(na{Wofw;DC+@QTDA+*Lg_Zl5O$bhXenzi;+NtmloN2pPczb!{_j1# z@B4N5WS%!a1OM>A&;TF=5W)wTGw|^0vOETmO2HBUa087RfW#TX2cQ<9?HphjwL19- zT3o>p0J~+NDwt7xwE}mxsw-D=8qIf{CLA<1O**;DDl=z1=kkV8j0=LIhtgR!BZWk@ zAe7TZArcA;u%fqIOpD`^!DXbJtR(m!-*}Vf!54Xm3NK zK(=-cwqY|#0MSM$;BhR)BDzj|PB&Cu}r4I4LY z-g4)tn3cwId3mdDOl~igcTC-T-~A8le(<3^kL-K&vB#fy@~Qm?4?X?Nv(Ftq^85=g zzI5#6S6+SX^%HNOJoV1I@4f%QnU6j``^mZU7cS0x{>7JHef`b1-+h1Or>j5z^6PKE z|8dRYg>CdKEqtD3_BUQE=0#8xNx3Xuh$vaaS&Cj5VH#GgbEUTh_~=geg1)^6jvn`P zbdOwa%xI^*O^cS!bY8Kj+06bKv0eX(nL})z*Cj~e{lkH`gCr>m?~|8dXqu^YdtBbS z+WNY>TA#0;Z3@);8(E((&=P3Gvo<%^H?+352HTs0%|R14LAaEmnHq+v3Hp8h;J*&@ eQ~WoA%!^PG= literal 0 HcmV?d00001 diff --git a/packages/image_picker/image_picker_ios/ios/Classes/FLTImagePickerImageUtil.m b/packages/image_picker/image_picker_ios/ios/Classes/FLTImagePickerImageUtil.m index 6adfd50402a..448430c0c4a 100644 --- a/packages/image_picker/image_picker_ios/ios/Classes/FLTImagePickerImageUtil.m +++ b/packages/image_picker/image_picker_ios/ios/Classes/FLTImagePickerImageUtil.m @@ -46,26 +46,26 @@ + (UIImage *)scaledImage:(UIImage *)image bool shouldDownscale = shouldDownscaleWidth || shouldDownscaleHeight; if (shouldDownscale) { - double downscaledWidth = floor((height / originalHeight) * originalWidth); - double downscaledHeight = floor((width / originalWidth) * originalHeight); + double downScaledWidth = floor((height / originalHeight) * originalWidth); + double downScaledHeight = floor((width / originalWidth) * originalHeight); if (width < height) { if (!hasMaxWidth) { - width = downscaledWidth; + width = downScaledWidth; } else { - height = downscaledHeight; + height = downScaledHeight; } } else if (height < width) { if (!hasMaxHeight) { - height = downscaledHeight; + height = downScaledHeight; } else { - width = downscaledWidth; + width = downScaledWidth; } } else { if (originalWidth < originalHeight) { - width = downscaledWidth; + width = downScaledWidth; } else if (originalHeight < originalWidth) { - height = downscaledHeight; + height = downScaledHeight; } } } From 4d9bfa39b65bcdbc657936c67846ec598d5fa2be Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Thu, 30 Nov 2023 09:12:13 -0800 Subject: [PATCH 3/9] correct number --- .../java/io/flutter/plugins/imagepicker/ImageResizerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/image_picker/image_picker_android/android/src/test/java/io/flutter/plugins/imagepicker/ImageResizerTest.java b/packages/image_picker/image_picker_android/android/src/test/java/io/flutter/plugins/imagepicker/ImageResizerTest.java index b2f012879f6..9d7433241a6 100644 --- a/packages/image_picker/image_picker_android/android/src/test/java/io/flutter/plugins/imagepicker/ImageResizerTest.java +++ b/packages/image_picker/image_picker_android/android/src/test/java/io/flutter/plugins/imagepicker/ImageResizerTest.java @@ -149,7 +149,7 @@ public void onResizeImageIfNeeded_whenHeightAndWidthAreNotNull_shouldResizeCorre float width = originalSize.getWidth(); float height = originalSize.getHeight(); - assertThat(width, equalTo(4)); + assertThat(width, equalTo(3)); assertThat(height, equalTo(6)); } } From 239a3b7937d4e5165f2f301e0f20a1898d026ac8 Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Wed, 6 Dec 2023 06:16:39 -0800 Subject: [PATCH 4/9] simple logic --- .../plugins/imagepicker/ImageResizer.java | 28 ++++++------------- .../plugins/imagepicker/ImageResizerTest.java | 4 +-- .../example/ios/RunnerTests/ImageUtilTests.m | 6 ++-- .../ios/Classes/FLTImagePickerImageUtil.m | 23 ++++----------- 4 files changed, 18 insertions(+), 43 deletions(-) diff --git a/packages/image_picker/image_picker_android/android/src/main/java/io/flutter/plugins/imagepicker/ImageResizer.java b/packages/image_picker/image_picker_android/android/src/main/java/io/flutter/plugins/imagepicker/ImageResizer.java index e90be74f718..e532b64dd05 100644 --- a/packages/image_picker/image_picker_android/android/src/main/java/io/flutter/plugins/imagepicker/ImageResizer.java +++ b/packages/image_picker/image_picker_android/android/src/main/java/io/flutter/plugins/imagepicker/ImageResizer.java @@ -87,6 +87,8 @@ private SizeFCompat calculateTargetSize( @Nullable Double maxWidth, @Nullable Double maxHeight) { + Double aspectRatio = originalWidth / originalHeight; + boolean hasMaxWidth = maxWidth != null; boolean hasMaxHeight = maxHeight != null; @@ -98,27 +100,13 @@ private SizeFCompat calculateTargetSize( boolean shouldDownscale = shouldDownscaleWidth || shouldDownscaleHeight; if (shouldDownscale) { - double downScaledWidth = (height / originalHeight) * originalWidth; - double downScaledHeight = (width / originalWidth) * originalHeight; - - if (width < height) { - if (!hasMaxWidth) { - width = downScaledWidth; - } else { - height = downScaledHeight; - } - } else if (height < width) { - if (!hasMaxHeight) { - height = downScaledHeight; - } else { - width = downScaledWidth; - } + double downScaledWidth = height * aspectRatio; + double downScaledHeight = width / aspectRatio; + + if (downScaledHeight > height) { + width = downScaledWidth; } else { - if (originalWidth < originalHeight) { - width = downScaledWidth; - } else if (originalHeight < originalWidth) { - height = downScaledHeight; - } + height = downScaledHeight; } } diff --git a/packages/image_picker/image_picker_android/android/src/test/java/io/flutter/plugins/imagepicker/ImageResizerTest.java b/packages/image_picker/image_picker_android/android/src/test/java/io/flutter/plugins/imagepicker/ImageResizerTest.java index 9d7433241a6..62d2bdc719d 100644 --- a/packages/image_picker/image_picker_android/android/src/test/java/io/flutter/plugins/imagepicker/ImageResizerTest.java +++ b/packages/image_picker/image_picker_android/android/src/test/java/io/flutter/plugins/imagepicker/ImageResizerTest.java @@ -144,12 +144,12 @@ public void onResizeImageIfNeeded_whenResizeIsNecessary_shouldDecodeBitmapPixels @Test public void onResizeImageIfNeeded_whenHeightAndWidthAreNotNull_shouldResizeCorrectly() { - String outputFile = resizer.resizeImageIfNeeded(tallJPG.getPath(), 6.0, 6.0, 100); + String outputFile = resizer.resizeImageIfNeeded(tallJPG.getPath(), 5.0, 5.0, 100); SizeFCompat originalSize = resizer.readFileDimensions(externalDirectory.getPath() + "/scaled_jpgImageTall.jpg"); float width = originalSize.getWidth(); float height = originalSize.getHeight(); assertThat(width, equalTo(3)); - assertThat(height, equalTo(6)); + assertThat(height, equalTo(5)); } } diff --git a/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImageUtilTests.m b/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImageUtilTests.m index b30cc76a358..012ce8b4e67 100644 --- a/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImageUtilTests.m +++ b/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImageUtilTests.m @@ -77,12 +77,12 @@ - (void)testScaledImage_ShouldBeScaledWithinMaxHeight { XCTAssertEqual(image.size.width, 4); XCTAssertEqual(image.size.height, 7); UIImage *newImage = [FLTImagePickerImageUtil scaledImage:image - maxWidth:@6 - maxHeight:@6 + maxWidth:@5 + maxHeight:@5 isMetadataAvailable:YES]; XCTAssertEqual(newImage.size.width, 3); - XCTAssertEqual(newImage.size.height, 6); + XCTAssertEqual(newImage.size.height, 5); } @end diff --git a/packages/image_picker/image_picker_ios/ios/Classes/FLTImagePickerImageUtil.m b/packages/image_picker/image_picker_ios/ios/Classes/FLTImagePickerImageUtil.m index 448430c0c4a..b6c593923f8 100644 --- a/packages/image_picker/image_picker_ios/ios/Classes/FLTImagePickerImageUtil.m +++ b/packages/image_picker/image_picker_ios/ios/Classes/FLTImagePickerImageUtil.m @@ -34,6 +34,7 @@ + (UIImage *)scaledImage:(UIImage *)image isMetadataAvailable:(BOOL)isMetadataAvailable { double originalWidth = image.size.width; double originalHeight = image.size.height; + double aspectRatio = originalWidth / originalHeight; bool hasMaxWidth = maxWidth != nil; bool hasMaxHeight = maxHeight != nil; @@ -45,30 +46,16 @@ + (UIImage *)scaledImage:(UIImage *)image bool shouldDownscaleHeight = hasMaxHeight && [maxHeight doubleValue] < originalHeight; bool shouldDownscale = shouldDownscaleWidth || shouldDownscaleHeight; - if (shouldDownscale) { - double downScaledWidth = floor((height / originalHeight) * originalWidth); - double downScaledHeight = floor((width / originalWidth) * originalHeight); + if (shouldDownscale) { + double downScaledWidth = height * aspectRatio; + double downScaledHeight = width / aspectRatio; - if (width < height) { - if (!hasMaxWidth) { + if (downScaledHeight > height) { width = downScaledWidth; } else { height = downScaledHeight; } - } else if (height < width) { - if (!hasMaxHeight) { - height = downScaledHeight; - } else { - width = downScaledWidth; - } - } else { - if (originalWidth < originalHeight) { - width = downScaledWidth; - } else if (originalHeight < originalWidth) { - height = downScaledHeight; - } } - } if (!isMetadataAvailable) { UIImage *imageToScale = [UIImage imageWithCGImage:image.CGImage From 1afcb8b27e688370b7e1cadff1d9c18a14ba6621 Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Wed, 6 Dec 2023 10:05:06 -0800 Subject: [PATCH 5/9] better rounding --- .../flutter/plugins/imagepicker/ImageResizer.java | 14 +++++++------- .../plugins/imagepicker/ImageResizerTest.java | 4 ++-- .../ios/Classes/FLTImagePickerImageUtil.m | 8 ++++---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/image_picker/image_picker_android/android/src/main/java/io/flutter/plugins/imagepicker/ImageResizer.java b/packages/image_picker/image_picker_android/android/src/main/java/io/flutter/plugins/imagepicker/ImageResizer.java index e532b64dd05..3af9c0b667d 100644 --- a/packages/image_picker/image_picker_android/android/src/main/java/io/flutter/plugins/imagepicker/ImageResizer.java +++ b/packages/image_picker/image_picker_android/android/src/main/java/io/flutter/plugins/imagepicker/ImageResizer.java @@ -82,18 +82,18 @@ private File resizedImage( } private SizeFCompat calculateTargetSize( - @NonNull Double originalWidth, - @NonNull Double originalHeight, + @NonNull double originalWidth, + @NonNull double originalHeight, @Nullable Double maxWidth, @Nullable Double maxHeight) { - Double aspectRatio = originalWidth / originalHeight; + double aspectRatio = originalWidth / originalHeight; boolean hasMaxWidth = maxWidth != null; boolean hasMaxHeight = maxHeight != null; - Double width = hasMaxWidth ? Math.min(originalWidth, maxWidth) : originalWidth; - Double height = hasMaxHeight ? Math.min(originalHeight, maxHeight) : originalHeight; + Double width = hasMaxWidth ? Math.min(originalWidth, Math.round(maxWidth)) : originalWidth; + Double height = hasMaxHeight ? Math.min(originalHeight, Math.round(maxHeight)) : originalHeight; boolean shouldDownscaleWidth = hasMaxWidth && maxWidth < originalWidth; boolean shouldDownscaleHeight = hasMaxHeight && maxHeight < originalHeight; @@ -104,9 +104,9 @@ private SizeFCompat calculateTargetSize( double downScaledHeight = width / aspectRatio; if (downScaledHeight > height) { - width = downScaledWidth; + width = (double)Math.round(downScaledWidth); } else { - height = downScaledHeight; + height = (double)Math.round(downScaledHeight); } } diff --git a/packages/image_picker/image_picker_android/android/src/test/java/io/flutter/plugins/imagepicker/ImageResizerTest.java b/packages/image_picker/image_picker_android/android/src/test/java/io/flutter/plugins/imagepicker/ImageResizerTest.java index 62d2bdc719d..08bff8b57ef 100644 --- a/packages/image_picker/image_picker_android/android/src/test/java/io/flutter/plugins/imagepicker/ImageResizerTest.java +++ b/packages/image_picker/image_picker_android/android/src/test/java/io/flutter/plugins/imagepicker/ImageResizerTest.java @@ -149,7 +149,7 @@ public void onResizeImageIfNeeded_whenHeightAndWidthAreNotNull_shouldResizeCorre float width = originalSize.getWidth(); float height = originalSize.getHeight(); - assertThat(width, equalTo(3)); - assertThat(height, equalTo(5)); + assertThat(width, equalTo(3.0F)); + assertThat(height, equalTo(5.0F)); } } diff --git a/packages/image_picker/image_picker_ios/ios/Classes/FLTImagePickerImageUtil.m b/packages/image_picker/image_picker_ios/ios/Classes/FLTImagePickerImageUtil.m index b6c593923f8..1e87a1ecfc0 100644 --- a/packages/image_picker/image_picker_ios/ios/Classes/FLTImagePickerImageUtil.m +++ b/packages/image_picker/image_picker_ios/ios/Classes/FLTImagePickerImageUtil.m @@ -39,8 +39,8 @@ + (UIImage *)scaledImage:(UIImage *)image bool hasMaxWidth = maxWidth != nil; bool hasMaxHeight = maxHeight != nil; - double width = hasMaxWidth ? MIN([maxWidth doubleValue], originalWidth) : originalWidth; - double height = hasMaxHeight ? MIN([maxHeight doubleValue], originalHeight) : originalHeight; + double width = hasMaxWidth ? MIN(round([maxWidth doubleValue]), originalWidth) : originalWidth; + double height = hasMaxHeight ? MIN(round([maxHeight doubleValue]), originalHeight) : originalHeight; bool shouldDownscaleWidth = hasMaxWidth && [maxWidth doubleValue] < originalWidth; bool shouldDownscaleHeight = hasMaxHeight && [maxHeight doubleValue] < originalHeight; @@ -51,9 +51,9 @@ + (UIImage *)scaledImage:(UIImage *)image double downScaledHeight = width / aspectRatio; if (downScaledHeight > height) { - width = downScaledWidth; + width = round(downScaledWidth); } else { - height = downScaledHeight; + height = round(downScaledHeight); } } From 70efb74678d853f9cf65c81a5a220147dabd8af9 Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Wed, 6 Dec 2023 10:47:49 -0800 Subject: [PATCH 6/9] More extensive tests --- .../plugins/imagepicker/ImageResizerTest.java | 59 ++++++++++++++++++- .../example/ios/RunnerTests/ImageUtilTests.m | 59 ++++++++++++++++++- 2 files changed, 115 insertions(+), 3 deletions(-) diff --git a/packages/image_picker/image_picker_android/android/src/test/java/io/flutter/plugins/imagepicker/ImageResizerTest.java b/packages/image_picker/image_picker_android/android/src/test/java/io/flutter/plugins/imagepicker/ImageResizerTest.java index 08bff8b57ef..b1cafd3bdd8 100644 --- a/packages/image_picker/image_picker_android/android/src/test/java/io/flutter/plugins/imagepicker/ImageResizerTest.java +++ b/packages/image_picker/image_picker_android/android/src/test/java/io/flutter/plugins/imagepicker/ImageResizerTest.java @@ -143,13 +143,68 @@ public void onResizeImageIfNeeded_whenResizeIsNecessary_shouldDecodeBitmapPixels } @Test - public void onResizeImageIfNeeded_whenHeightAndWidthAreNotNull_shouldResizeCorrectly() { + public void onResizeImageIfNeeded_whenImageIsVertical_WidthIsGreaterThanOriginal_shouldResizeCorrectly() { String outputFile = resizer.resizeImageIfNeeded(tallJPG.getPath(), 5.0, 5.0, 100); SizeFCompat originalSize = resizer.readFileDimensions(externalDirectory.getPath() + "/scaled_jpgImageTall.jpg"); - + + float width = originalSize.getWidth(); + float height = originalSize.getHeight(); + assertThat(width, equalTo(3.0F)); + assertThat(height, equalTo(5.0F)); + } + + @Test + public void onResizeImageIfNeeded_whenImageIsVertical_HeightIsGreaterThanOriginal_shouldResizeCorrectly() { + String outputFile = resizer.resizeImageIfNeeded(tallJPG.getPath(), 3.0, 10.0, 100); + SizeFCompat originalSize = resizer.readFileDimensions(externalDirectory.getPath() + "/scaled_jpgImageTall.jpg"); + float width = originalSize.getWidth(); float height = originalSize.getHeight(); assertThat(width, equalTo(3.0F)); assertThat(height, equalTo(5.0F)); } + + @Test + public void onResizeImageIfNeeded_whenImageIsVertical_HeightAndWidthIsGreaterThanOriginal_shouldNotResize() { + String outputFile = resizer.resizeImageIfNeeded(tallJPG.getPath(), 10.0, 10.0, 100); + SizeFCompat originalSize = resizer.readFileDimensions(externalDirectory.getPath() + "/scaled_jpgImageTall.jpg"); + + float width = originalSize.getWidth(); + float height = originalSize.getHeight(); + assertThat(width, equalTo(4.0F)); + assertThat(height, equalTo(7.0F)); + } + + @Test + public void onResizeImageIfNeeded_whenImageIsHorizontal_WidthIsGreaterThanOriginal_shouldResizeCorrectly() { + String outputFile = resizer.resizeImageIfNeeded(wideJPG.getPath(), 10.0, 20.0, 100); + SizeFCompat originalSize = resizer.readFileDimensions(externalDirectory.getPath() + "/scaled_jpgImageWide.jpg"); + + float width = originalSize.getWidth(); + float height = originalSize.getHeight(); + assertThat(width, equalTo(10.0F)); + assertThat(height, equalTo(6.0F)); + } + + @Test + public void onResizeImageIfNeeded_whenImageIsHorizontal_HeightIsGreaterThanOriginal_shouldResizeCorrectly() { + String outputFile = resizer.resizeImageIfNeeded(wideJPG.getPath(), 10.0, 10.0, 100); + SizeFCompat originalSize = resizer.readFileDimensions(externalDirectory.getPath() + "/scaled_jpgImageWide.jpg"); + + float width = originalSize.getWidth(); + float height = originalSize.getHeight(); + assertThat(width, equalTo(10.0F)); + assertThat(height, equalTo(6.0F)); + } + + @Test + public void onResizeImageIfNeeded_whenImageIsHorizontal_HeightAndWidthIsGreaterThanOriginal_shouldNotResize() { + String outputFile = resizer.resizeImageIfNeeded(wideJPG.getPath(), 100.0, 100.0, 100); + SizeFCompat originalSize = resizer.readFileDimensions(externalDirectory.getPath() + "/scaled_jpgImageWide.jpg"); + + float width = originalSize.getWidth(); + float height = originalSize.getHeight(); + assertThat(width, equalTo(12.0F)); + assertThat(height, equalTo(7.0F)); + } } diff --git a/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImageUtilTests.m b/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImageUtilTests.m index 012ce8b4e67..c7959253f3a 100644 --- a/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImageUtilTests.m +++ b/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImageUtilTests.m @@ -72,7 +72,7 @@ - (void)testScaledGIFImage_ShouldBeScaled { } } -- (void)testScaledImage_ShouldBeScaledWithinMaxHeight { +- (void)testScaledImage_TallImage_ShouldBeScaledBelowMaxHeight { UIImage *image = [UIImage imageWithData:ImagePickerTestImages.TallJPGTestData]; XCTAssertEqual(image.size.width, 4); XCTAssertEqual(image.size.height, 7); @@ -85,4 +85,61 @@ - (void)testScaledImage_ShouldBeScaledWithinMaxHeight { XCTAssertEqual(newImage.size.height, 5); } +- (void)testScaledImage_TallImage_ShouldBeScaledBelowMaxWidth { + UIImage *image = [UIImage imageWithData:ImagePickerTestImages.TallJPGTestData]; + UIImage *newImage = [FLTImagePickerImageUtil scaledImage:image + maxWidth:@3 + maxHeight:@10 + isMetadataAvailable:YES]; + + XCTAssertEqual(newImage.size.width, 3); + XCTAssertEqual(newImage.size.height, 5); +} + +- (void)testScaledImage_TallImage_ShouldNotBeScaledAboveOriginaWidthOrHeight { + UIImage *image = [UIImage imageWithData:ImagePickerTestImages.TallJPGTestData]; + UIImage *newImage = [FLTImagePickerImageUtil scaledImage:image + maxWidth:@10 + maxHeight:@10 + isMetadataAvailable:YES]; + + XCTAssertEqual(newImage.size.width, 4); + XCTAssertEqual(newImage.size.height, 7); +} + +- (void)testScaledImage_WideImage_ShouldBeScaledBelowMaxHeight { + UIImage *image = [UIImage imageWithData:ImagePickerTestImages.JPGTestData]; + XCTAssertEqual(image.size.width, 12); + XCTAssertEqual(image.size.height, 7); + UIImage *newImage = [FLTImagePickerImageUtil scaledImage:image + maxWidth:@20 + maxHeight:@6 + isMetadataAvailable:YES]; + + XCTAssertEqual(newImage.size.width, 10); + XCTAssertEqual(newImage.size.height, 6); +} + +- (void)testScaledImage_WideImage_ShouldBeScaledBelowMaxWidth { + UIImage *image = [UIImage imageWithData:ImagePickerTestImages.JPGTestData]; + UIImage *newImage = [FLTImagePickerImageUtil scaledImage:image + maxWidth:@10 + maxHeight:@10 + isMetadataAvailable:YES]; + + XCTAssertEqual(newImage.size.width, 10); + XCTAssertEqual(newImage.size.height, 6); +} + +- (void)testScaledImage_WideImage_ShouldNotBeScaledAboveOriginaWidthOrHeight { + UIImage *image = [UIImage imageWithData:ImagePickerTestImages.JPGTestData]; + UIImage *newImage = [FLTImagePickerImageUtil scaledImage:image + maxWidth:@100 + maxHeight:@100 + isMetadataAvailable:YES]; + + XCTAssertEqual(newImage.size.width, 12); + XCTAssertEqual(newImage.size.height, 7); +} + @end From 4617f439c34362db522c2350a061f3aa6d9b7e8e Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Wed, 6 Dec 2023 10:51:03 -0800 Subject: [PATCH 7/9] pubspec+changelog --- packages/image_picker/image_picker_android/CHANGELOG.md | 3 ++- packages/image_picker/image_picker_android/pubspec.yaml | 2 +- packages/image_picker/image_picker_ios/CHANGELOG.md | 3 ++- packages/image_picker/image_picker_ios/pubspec.yaml | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/image_picker/image_picker_android/CHANGELOG.md b/packages/image_picker/image_picker_android/CHANGELOG.md index 6fe44377395..68763b4d99c 100644 --- a/packages/image_picker/image_picker_android/CHANGELOG.md +++ b/packages/image_picker/image_picker_android/CHANGELOG.md @@ -1,5 +1,6 @@ -## NEXT +## 0.8.9 +* Fixes resizing bug and updates rounding to be more accurate. * Updates minimum supported SDK version to Flutter 3.10/Dart 3.0. ## 0.8.8+2 diff --git a/packages/image_picker/image_picker_android/pubspec.yaml b/packages/image_picker/image_picker_android/pubspec.yaml index 3581f558c49..93e9235eedb 100755 --- a/packages/image_picker/image_picker_android/pubspec.yaml +++ b/packages/image_picker/image_picker_android/pubspec.yaml @@ -3,7 +3,7 @@ description: Android implementation of the image_picker plugin. repository: https://github.com/flutter/packages/tree/main/packages/image_picker/image_picker_android issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22 -version: 0.8.8+2 +version: 0.8.9 environment: sdk: ">=3.0.0 <4.0.0" diff --git a/packages/image_picker/image_picker_ios/CHANGELOG.md b/packages/image_picker/image_picker_ios/CHANGELOG.md index fe29ad80ad0..d3855a4d2b7 100644 --- a/packages/image_picker/image_picker_ios/CHANGELOG.md +++ b/packages/image_picker/image_picker_ios/CHANGELOG.md @@ -1,5 +1,6 @@ -## NEXT +## 0.8.9 +* Fixes resizing bug and updates rounding to be more accurate. * Updates minimum supported SDK version to Flutter 3.10/Dart 3.0. ## 0.8.8+4 diff --git a/packages/image_picker/image_picker_ios/pubspec.yaml b/packages/image_picker/image_picker_ios/pubspec.yaml index cec65a9719e..f606cd1a56e 100755 --- a/packages/image_picker/image_picker_ios/pubspec.yaml +++ b/packages/image_picker/image_picker_ios/pubspec.yaml @@ -2,7 +2,7 @@ name: image_picker_ios description: iOS implementation of the image_picker plugin. repository: https://github.com/flutter/packages/tree/main/packages/image_picker/image_picker_ios issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22 -version: 0.8.8+4 +version: 0.8.9 environment: sdk: ">=3.0.0 <4.0.0" From a23a6013cb3f24d97ca83e932c3cb136735037b4 Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Wed, 6 Dec 2023 10:56:46 -0800 Subject: [PATCH 8/9] format --- .../plugins/imagepicker/ImageResizer.java | 4 +- .../plugins/imagepicker/ImageResizerTest.java | 38 +++++++----- .../ios/RunnerTests/ImagePickerTestImages.m | 59 ++++++++++++++++++- .../example/ios/RunnerTests/ImageUtilTests.m | 8 +-- .../ios/Classes/FLTImagePickerImageUtil.m | 19 +++--- 5 files changed, 98 insertions(+), 30 deletions(-) diff --git a/packages/image_picker/image_picker_android/android/src/main/java/io/flutter/plugins/imagepicker/ImageResizer.java b/packages/image_picker/image_picker_android/android/src/main/java/io/flutter/plugins/imagepicker/ImageResizer.java index 3af9c0b667d..4f3eea9cbe9 100644 --- a/packages/image_picker/image_picker_android/android/src/main/java/io/flutter/plugins/imagepicker/ImageResizer.java +++ b/packages/image_picker/image_picker_android/android/src/main/java/io/flutter/plugins/imagepicker/ImageResizer.java @@ -104,9 +104,9 @@ private SizeFCompat calculateTargetSize( double downScaledHeight = width / aspectRatio; if (downScaledHeight > height) { - width = (double)Math.round(downScaledWidth); + width = (double) Math.round(downScaledWidth); } else { - height = (double)Math.round(downScaledHeight); + height = (double) Math.round(downScaledHeight); } } diff --git a/packages/image_picker/image_picker_android/android/src/test/java/io/flutter/plugins/imagepicker/ImageResizerTest.java b/packages/image_picker/image_picker_android/android/src/test/java/io/flutter/plugins/imagepicker/ImageResizerTest.java index b1cafd3bdd8..5567f0fbfd4 100644 --- a/packages/image_picker/image_picker_android/android/src/test/java/io/flutter/plugins/imagepicker/ImageResizerTest.java +++ b/packages/image_picker/image_picker_android/android/src/test/java/io/flutter/plugins/imagepicker/ImageResizerTest.java @@ -18,9 +18,7 @@ import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; - import androidx.core.util.SizeFCompat; - import java.io.File; import java.io.IOException; import java.util.List; @@ -143,9 +141,11 @@ public void onResizeImageIfNeeded_whenResizeIsNecessary_shouldDecodeBitmapPixels } @Test - public void onResizeImageIfNeeded_whenImageIsVertical_WidthIsGreaterThanOriginal_shouldResizeCorrectly() { + public void + onResizeImageIfNeeded_whenImageIsVertical_WidthIsGreaterThanOriginal_shouldResizeCorrectly() { String outputFile = resizer.resizeImageIfNeeded(tallJPG.getPath(), 5.0, 5.0, 100); - SizeFCompat originalSize = resizer.readFileDimensions(externalDirectory.getPath() + "/scaled_jpgImageTall.jpg"); + SizeFCompat originalSize = + resizer.readFileDimensions(externalDirectory.getPath() + "/scaled_jpgImageTall.jpg"); float width = originalSize.getWidth(); float height = originalSize.getHeight(); @@ -154,9 +154,11 @@ public void onResizeImageIfNeeded_whenImageIsVertical_WidthIsGreaterThanOriginal } @Test - public void onResizeImageIfNeeded_whenImageIsVertical_HeightIsGreaterThanOriginal_shouldResizeCorrectly() { + public void + onResizeImageIfNeeded_whenImageIsVertical_HeightIsGreaterThanOriginal_shouldResizeCorrectly() { String outputFile = resizer.resizeImageIfNeeded(tallJPG.getPath(), 3.0, 10.0, 100); - SizeFCompat originalSize = resizer.readFileDimensions(externalDirectory.getPath() + "/scaled_jpgImageTall.jpg"); + SizeFCompat originalSize = + resizer.readFileDimensions(externalDirectory.getPath() + "/scaled_jpgImageTall.jpg"); float width = originalSize.getWidth(); float height = originalSize.getHeight(); @@ -165,9 +167,11 @@ public void onResizeImageIfNeeded_whenImageIsVertical_HeightIsGreaterThanOrigina } @Test - public void onResizeImageIfNeeded_whenImageIsVertical_HeightAndWidthIsGreaterThanOriginal_shouldNotResize() { + public void + onResizeImageIfNeeded_whenImageIsVertical_HeightAndWidthIsGreaterThanOriginal_shouldNotResize() { String outputFile = resizer.resizeImageIfNeeded(tallJPG.getPath(), 10.0, 10.0, 100); - SizeFCompat originalSize = resizer.readFileDimensions(externalDirectory.getPath() + "/scaled_jpgImageTall.jpg"); + SizeFCompat originalSize = + resizer.readFileDimensions(externalDirectory.getPath() + "/scaled_jpgImageTall.jpg"); float width = originalSize.getWidth(); float height = originalSize.getHeight(); @@ -176,9 +180,11 @@ public void onResizeImageIfNeeded_whenImageIsVertical_HeightAndWidthIsGreaterTha } @Test - public void onResizeImageIfNeeded_whenImageIsHorizontal_WidthIsGreaterThanOriginal_shouldResizeCorrectly() { + public void + onResizeImageIfNeeded_whenImageIsHorizontal_WidthIsGreaterThanOriginal_shouldResizeCorrectly() { String outputFile = resizer.resizeImageIfNeeded(wideJPG.getPath(), 10.0, 20.0, 100); - SizeFCompat originalSize = resizer.readFileDimensions(externalDirectory.getPath() + "/scaled_jpgImageWide.jpg"); + SizeFCompat originalSize = + resizer.readFileDimensions(externalDirectory.getPath() + "/scaled_jpgImageWide.jpg"); float width = originalSize.getWidth(); float height = originalSize.getHeight(); @@ -187,9 +193,11 @@ public void onResizeImageIfNeeded_whenImageIsHorizontal_WidthIsGreaterThanOrigin } @Test - public void onResizeImageIfNeeded_whenImageIsHorizontal_HeightIsGreaterThanOriginal_shouldResizeCorrectly() { + public void + onResizeImageIfNeeded_whenImageIsHorizontal_HeightIsGreaterThanOriginal_shouldResizeCorrectly() { String outputFile = resizer.resizeImageIfNeeded(wideJPG.getPath(), 10.0, 10.0, 100); - SizeFCompat originalSize = resizer.readFileDimensions(externalDirectory.getPath() + "/scaled_jpgImageWide.jpg"); + SizeFCompat originalSize = + resizer.readFileDimensions(externalDirectory.getPath() + "/scaled_jpgImageWide.jpg"); float width = originalSize.getWidth(); float height = originalSize.getHeight(); @@ -198,9 +206,11 @@ public void onResizeImageIfNeeded_whenImageIsHorizontal_HeightIsGreaterThanOrigi } @Test - public void onResizeImageIfNeeded_whenImageIsHorizontal_HeightAndWidthIsGreaterThanOriginal_shouldNotResize() { + public void + onResizeImageIfNeeded_whenImageIsHorizontal_HeightAndWidthIsGreaterThanOriginal_shouldNotResize() { String outputFile = resizer.resizeImageIfNeeded(wideJPG.getPath(), 100.0, 100.0, 100); - SizeFCompat originalSize = resizer.readFileDimensions(externalDirectory.getPath() + "/scaled_jpgImageWide.jpg"); + SizeFCompat originalSize = + resizer.readFileDimensions(externalDirectory.getPath() + "/scaled_jpgImageWide.jpg"); float width = originalSize.getWidth(); float height = originalSize.getHeight(); diff --git a/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImagePickerTestImages.m b/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImagePickerTestImages.m index f504a722801..bc160d3474d 100644 --- a/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImagePickerTestImages.m +++ b/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImagePickerTestImages.m @@ -82,7 +82,64 @@ + (NSData *)TallJPGTestData { // embedded in the test bundle. Fall back to the base64 string representation of the jpg. data = [[NSData alloc] initWithBase64EncodedString: - @"/9j/4AAQSkZJRgABAQAALgAuAAD/4QCMRXhpZgAATU0AKgAAAAgABQESAAMAAAABAAEAAAEaAAUAAAABAAAASgEbAAUAAAABAAAAUgEoAAMAAAABAAIAAIdpAAQAAAABAAAAWgAAAAAAAAAuAAAAAQAAAC4AAAABAAOgAQADAAAAAQABAACgAgAEAAAAAQAAAASgAwAEAAAAAQAAAAcAAAAA/+EJ12h0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8APD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczpwaG90b3Nob3A9Imh0dHA6Ly9ucy5hZG9iZS5jb20vcGhvdG9zaG9wLzEuMC8iIHhtbG5zOmRjPSJodHRwOi8vcHVybC5vcmcvZGMvZWxlbWVudHMvMS4xLyIgcGhvdG9zaG9wOkNyZWRpdD0iwqkgR29vZ2xlIj4gPGRjOnN1YmplY3Q+IDxyZGY6QmFnLz4gPC9kYzpzdWJqZWN0PiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICA8P3hwYWNrZXQgZW5kPSJ3Ij8+AP/tAFZQaG90b3Nob3AgMy4wADhCSU0EBAAAAAAAHRwBWgADGyVHHAIAAAIAAhwCbgAJwqkgR29vZ2xlADhCSU0EJQAAAAAAEJpLdiBdz4DSVTBp1ds4oxH/wAARCAAHAAQDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9sAQwAEAwMDAwIEAwMDBAQEBQYKBgYFBQYMCAkHCg4MDw4ODA0NDxEWEw8QFRENDRMaExUXGBkZGQ8SGx0bGB0WGBkY/9sAQwEEBAQGBQYLBgYLGBANEBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgY/90ABAAB/9oADAMBAAIRAxEAPwDFooor85P6qP/Z" + @"/9j/4AAQSkZJRgABAQAALgAuAAD/" + @"4QCMRXhpZgAATU0AKgAAAAgABQESAAMAAAABAAEAAAEaAAUAAAABAAAASgEbAAUAAAABAAAAUgEoAAMAAAABA" + @"AIAAIdpAAQAAAABAAAAWgAAAAAAAAAuAAAAAQAAAC4AAAABAAOgAQADAAAAAQABAACgAgAEAAAAAQAAAASgAw" + @"AEAAAAAQAAAAcAAAAA/" + @"+EJ12h0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8APD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTX" + @"BDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB" + @"0az0iWE1QIENvcmUgNi4wLjAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkv" + @"MDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczpwaG90b" + @"3Nob3A9Imh0dHA6Ly9ucy5hZG9iZS5jb20vcGhvdG9zaG9wLzEuMC8iIHhtbG5zOmRjPSJodHRwOi8vcHVybC" + @"5vcmcvZGMvZWxlbWVudHMvMS4xLyIgcGhvdG9zaG9wOkNyZWRpdD0iwqkgR29vZ2xlIj4gPGRjOnN1YmplY3Q" + @"+IDxyZGY6QmFnLz4gPC9kYzpzdWJqZWN0PiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1w" + @"bWV0YT4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI" + @"CAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC" + @"AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICA" + @"gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg" + @"ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI" + @"CAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC" + @"AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICA" + @"gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg" + @"ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI" + @"CAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC" + @"AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICA" + @"gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg" + @"ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI" + @"CAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC" + @"AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICA" + @"gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg" + @"ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI" + @"CAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC" + @"AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICA" + @"gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg" + @"ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI" + @"CAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC" + @"AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICA" + @"gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg" + @"ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI" + @"CAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC" + @"AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICA" + @"gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg" + @"ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI" + @"CAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC" + @"AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICA" + @"gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg" + @"ICAgICAgICAgICAgICA8P3hwYWNrZXQgZW5kPSJ3Ij8+AP/" + @"tAFZQaG90b3Nob3AgMy4wADhCSU0EBAAAAAAAHRwBWgADGyVHHAIAAAIAAhwCbgAJwqkgR29vZ2xlADhCSU0E" + @"JQAAAAAAEJpLdiBdz4DSVTBp1ds4oxH/wAARCAAHAAQDASIAAhEBAxEB/" + @"8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/" + @"8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGR" + @"olJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqK" + @"jpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/" + @"8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/" + @"8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8R" + @"cYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJm" + @"aoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/" + @"9sAQwAEAwMDAwIEAwMDBAQEBQYKBgYFBQYMCAkHCg4MDw4ODA0NDxEWEw8QFRENDRMaExUXGBkZGQ8SGx0bGB" + @"0WGBkY/" + @"9sAQwEEBAQGBQYLBgYLGBANEBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGB" + @"gYGBgY/90ABAAB/9oADAMBAAIRAxEAPwDFooor85P6qP/Z" options:0]; } return data; diff --git a/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImageUtilTests.m b/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImageUtilTests.m index c7959253f3a..86ec00502ae 100644 --- a/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImageUtilTests.m +++ b/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImageUtilTests.m @@ -74,8 +74,8 @@ - (void)testScaledGIFImage_ShouldBeScaled { - (void)testScaledImage_TallImage_ShouldBeScaledBelowMaxHeight { UIImage *image = [UIImage imageWithData:ImagePickerTestImages.TallJPGTestData]; - XCTAssertEqual(image.size.width, 4); - XCTAssertEqual(image.size.height, 7); + XCTAssertEqual(image.size.width, 4); + XCTAssertEqual(image.size.height, 7); UIImage *newImage = [FLTImagePickerImageUtil scaledImage:image maxWidth:@5 maxHeight:@5 @@ -109,8 +109,8 @@ - (void)testScaledImage_TallImage_ShouldNotBeScaledAboveOriginaWidthOrHeight { - (void)testScaledImage_WideImage_ShouldBeScaledBelowMaxHeight { UIImage *image = [UIImage imageWithData:ImagePickerTestImages.JPGTestData]; - XCTAssertEqual(image.size.width, 12); - XCTAssertEqual(image.size.height, 7); + XCTAssertEqual(image.size.width, 12); + XCTAssertEqual(image.size.height, 7); UIImage *newImage = [FLTImagePickerImageUtil scaledImage:image maxWidth:@20 maxHeight:@6 diff --git a/packages/image_picker/image_picker_ios/ios/Classes/FLTImagePickerImageUtil.m b/packages/image_picker/image_picker_ios/ios/Classes/FLTImagePickerImageUtil.m index 1e87a1ecfc0..b515f35e0c2 100644 --- a/packages/image_picker/image_picker_ios/ios/Classes/FLTImagePickerImageUtil.m +++ b/packages/image_picker/image_picker_ios/ios/Classes/FLTImagePickerImageUtil.m @@ -40,22 +40,23 @@ + (UIImage *)scaledImage:(UIImage *)image bool hasMaxHeight = maxHeight != nil; double width = hasMaxWidth ? MIN(round([maxWidth doubleValue]), originalWidth) : originalWidth; - double height = hasMaxHeight ? MIN(round([maxHeight doubleValue]), originalHeight) : originalHeight; + double height = + hasMaxHeight ? MIN(round([maxHeight doubleValue]), originalHeight) : originalHeight; bool shouldDownscaleWidth = hasMaxWidth && [maxWidth doubleValue] < originalWidth; bool shouldDownscaleHeight = hasMaxHeight && [maxHeight doubleValue] < originalHeight; bool shouldDownscale = shouldDownscaleWidth || shouldDownscaleHeight; - if (shouldDownscale) { - double downScaledWidth = height * aspectRatio; - double downScaledHeight = width / aspectRatio; + if (shouldDownscale) { + double downScaledWidth = height * aspectRatio; + double downScaledHeight = width / aspectRatio; - if (downScaledHeight > height) { - width = round(downScaledWidth); - } else { - height = round(downScaledHeight); - } + if (downScaledHeight > height) { + width = round(downScaledWidth); + } else { + height = round(downScaledHeight); } + } if (!isMetadataAvailable) { UIImage *imageToScale = [UIImage imageWithCGImage:image.CGImage From a9eec9b9c738311371ecfb039240cbd6e64cf9ac Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Tue, 12 Dec 2023 11:06:43 -0800 Subject: [PATCH 9/9] nits --- .../plugins/imagepicker/ImageResizer.java | 23 ++++++++++--------- .../plugins/imagepicker/ImageResizerTest.java | 2 ++ .../ios/RunnerTests/ImagePickerTestImages.h | 2 +- .../ios/RunnerTests/ImagePickerTestImages.m | 2 +- .../example/ios/RunnerTests/ImageUtilTests.m | 6 ++--- .../ios/Classes/FLTImagePickerImageUtil.m | 10 ++++---- 6 files changed, 24 insertions(+), 21 deletions(-) diff --git a/packages/image_picker/image_picker_android/android/src/main/java/io/flutter/plugins/imagepicker/ImageResizer.java b/packages/image_picker/image_picker_android/android/src/main/java/io/flutter/plugins/imagepicker/ImageResizer.java index 4f3eea9cbe9..3d4422ac320 100644 --- a/packages/image_picker/image_picker_android/android/src/main/java/io/flutter/plugins/imagepicker/ImageResizer.java +++ b/packages/image_picker/image_picker_android/android/src/main/java/io/flutter/plugins/imagepicker/ImageResizer.java @@ -10,6 +10,7 @@ import android.util.Log; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.annotation.VisibleForTesting; import androidx.core.util.SizeFCompat; import androidx.exifinterface.media.ExifInterface; import java.io.ByteArrayOutputStream; @@ -82,35 +83,34 @@ private File resizedImage( } private SizeFCompat calculateTargetSize( - @NonNull double originalWidth, - @NonNull double originalHeight, + double originalWidth, + double originalHeight, @Nullable Double maxWidth, @Nullable Double maxHeight) { - double aspectRatio = originalWidth / originalHeight; boolean hasMaxWidth = maxWidth != null; boolean hasMaxHeight = maxHeight != null; - Double width = hasMaxWidth ? Math.min(originalWidth, Math.round(maxWidth)) : originalWidth; - Double height = hasMaxHeight ? Math.min(originalHeight, Math.round(maxHeight)) : originalHeight; + double width = hasMaxWidth ? Math.min(originalWidth, Math.round(maxWidth)) : originalWidth; + double height = hasMaxHeight ? Math.min(originalHeight, Math.round(maxHeight)) : originalHeight; boolean shouldDownscaleWidth = hasMaxWidth && maxWidth < originalWidth; boolean shouldDownscaleHeight = hasMaxHeight && maxHeight < originalHeight; boolean shouldDownscale = shouldDownscaleWidth || shouldDownscaleHeight; if (shouldDownscale) { - double downScaledWidth = height * aspectRatio; - double downScaledHeight = width / aspectRatio; + double WidthForMaxHeight = height * aspectRatio; + double heightForMaxWidth = width / aspectRatio; - if (downScaledHeight > height) { - width = (double) Math.round(downScaledWidth); + if (heightForMaxWidth > height) { + width = (double) Math.round(WidthForMaxHeight); } else { - height = (double) Math.round(downScaledHeight); + height = (double) Math.round(heightForMaxWidth); } } - return new SizeFCompat(width.floatValue(), height.floatValue()); + return new SizeFCompat((float) width, (float) height); } private File createFile(File externalFilesDirectory, String child) { @@ -133,6 +133,7 @@ private void copyExif(String filePathOri, String filePathDest) { } } + @VisibleForTesting SizeFCompat readFileDimensions(String path) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; diff --git a/packages/image_picker/image_picker_android/android/src/test/java/io/flutter/plugins/imagepicker/ImageResizerTest.java b/packages/image_picker/image_picker_android/android/src/test/java/io/flutter/plugins/imagepicker/ImageResizerTest.java index 5567f0fbfd4..7320e324c4c 100644 --- a/packages/image_picker/image_picker_android/android/src/test/java/io/flutter/plugins/imagepicker/ImageResizerTest.java +++ b/packages/image_picker/image_picker_android/android/src/test/java/io/flutter/plugins/imagepicker/ImageResizerTest.java @@ -53,7 +53,9 @@ public void setUp() throws IOException { mockCloseable = MockitoAnnotations.openMocks(this); imageFile = new File(getClass().getClassLoader().getResource("pngImage.png").getFile()); svgImageFile = new File(getClass().getClassLoader().getResource("flutter_image.svg").getFile()); + // tallJPG has height 7px and width 4px. tallJPG = new File(getClass().getClassLoader().getResource("jpgImageTall.jpg").getFile()); + // wideJPG has height 7px and width 12px. wideJPG = new File(getClass().getClassLoader().getResource("jpgImageWide.jpg").getFile()); originalImageBitmap = BitmapFactory.decodeFile(imageFile.getPath()); TemporaryFolder temporaryFolder = new TemporaryFolder(); diff --git a/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImagePickerTestImages.h b/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImagePickerTestImages.h index b732853469a..c6cfa6c788d 100644 --- a/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImagePickerTestImages.h +++ b/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImagePickerTestImages.h @@ -9,7 +9,7 @@ NS_ASSUME_NONNULL_BEGIN @interface ImagePickerTestImages : NSObject @property(class, copy, readonly) NSData *JPGTestData; -@property(class, copy, readonly) NSData *TallJPGTestData; +@property(class, copy, readonly) NSData *JPGTallTestData; @property(class, copy, readonly) NSData *PNGTestData; @property(class, copy, readonly) NSData *GIFTestData; diff --git a/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImagePickerTestImages.m b/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImagePickerTestImages.m index bc160d3474d..b91eec29302 100644 --- a/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImagePickerTestImages.m +++ b/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImagePickerTestImages.m @@ -73,7 +73,7 @@ + (NSData *)JPGTestData { return data; } -+ (NSData *)TallJPGTestData { ++ (NSData *)JPGTallTestData { NSBundle *bundle = [NSBundle bundleForClass:self]; NSURL *url = [bundle URLForResource:@"jpgImageTall" withExtension:@"jpg"]; NSData *data = [NSData dataWithContentsOfURL:url]; diff --git a/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImageUtilTests.m b/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImageUtilTests.m index 86ec00502ae..ddd4087a9f4 100644 --- a/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImageUtilTests.m +++ b/packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImageUtilTests.m @@ -73,7 +73,7 @@ - (void)testScaledGIFImage_ShouldBeScaled { } - (void)testScaledImage_TallImage_ShouldBeScaledBelowMaxHeight { - UIImage *image = [UIImage imageWithData:ImagePickerTestImages.TallJPGTestData]; + UIImage *image = [UIImage imageWithData:ImagePickerTestImages.JPGTallTestData]; XCTAssertEqual(image.size.width, 4); XCTAssertEqual(image.size.height, 7); UIImage *newImage = [FLTImagePickerImageUtil scaledImage:image @@ -86,7 +86,7 @@ - (void)testScaledImage_TallImage_ShouldBeScaledBelowMaxHeight { } - (void)testScaledImage_TallImage_ShouldBeScaledBelowMaxWidth { - UIImage *image = [UIImage imageWithData:ImagePickerTestImages.TallJPGTestData]; + UIImage *image = [UIImage imageWithData:ImagePickerTestImages.JPGTallTestData]; UIImage *newImage = [FLTImagePickerImageUtil scaledImage:image maxWidth:@3 maxHeight:@10 @@ -97,7 +97,7 @@ - (void)testScaledImage_TallImage_ShouldBeScaledBelowMaxWidth { } - (void)testScaledImage_TallImage_ShouldNotBeScaledAboveOriginaWidthOrHeight { - UIImage *image = [UIImage imageWithData:ImagePickerTestImages.TallJPGTestData]; + UIImage *image = [UIImage imageWithData:ImagePickerTestImages.JPGTallTestData]; UIImage *newImage = [FLTImagePickerImageUtil scaledImage:image maxWidth:@10 maxHeight:@10 diff --git a/packages/image_picker/image_picker_ios/ios/Classes/FLTImagePickerImageUtil.m b/packages/image_picker/image_picker_ios/ios/Classes/FLTImagePickerImageUtil.m index b515f35e0c2..245a6617793 100644 --- a/packages/image_picker/image_picker_ios/ios/Classes/FLTImagePickerImageUtil.m +++ b/packages/image_picker/image_picker_ios/ios/Classes/FLTImagePickerImageUtil.m @@ -48,13 +48,13 @@ + (UIImage *)scaledImage:(UIImage *)image bool shouldDownscale = shouldDownscaleWidth || shouldDownscaleHeight; if (shouldDownscale) { - double downScaledWidth = height * aspectRatio; - double downScaledHeight = width / aspectRatio; + double widthForMaxHeight = height * aspectRatio; + double heightForMaxWidth = width / aspectRatio; - if (downScaledHeight > height) { - width = round(downScaledWidth); + if (heightForMaxWidth > height) { + width = round(widthForMaxHeight); } else { - height = round(downScaledHeight); + height = round(heightForMaxWidth); } }