diff --git a/.ci/flutter_master.version b/.ci/flutter_master.version index d04c9ccdbf6..20a81c08421 100644 --- a/.ci/flutter_master.version +++ b/.ci/flutter_master.version @@ -1 +1 @@ -bf7191fd388442428fc1ec20cb39514768cc20d4 +f1037a01b796bbd5e7c2bd6320525fbd47702473 diff --git a/packages/camera/camera/CHANGELOG.md b/packages/camera/camera/CHANGELOG.md index 8ad0b49fe98..901548e9b6d 100644 --- a/packages/camera/camera/CHANGELOG.md +++ b/packages/camera/camera/CHANGELOG.md @@ -1,5 +1,6 @@ -## NEXT +## 0.10.6 +* Adds support to control video fps and bitrate. See `CameraController` constructor. * Updates minimum supported SDK version to Flutter 3.13/Dart 3.1. * Updates support matrix in README to indicate that iOS 11 is no longer supported. * Clients on versions of Flutter that still support iOS 11 can continue to use this diff --git a/packages/camera/camera/lib/src/camera_controller.dart b/packages/camera/camera/lib/src/camera_controller.dart index 1d402afcc2e..5f90a0a740a 100644 --- a/packages/camera/camera/lib/src/camera_controller.dart +++ b/packages/camera/camera/lib/src/camera_controller.dart @@ -232,12 +232,30 @@ class CameraValue { /// To show the camera preview on the screen use a [CameraPreview] widget. class CameraController extends ValueNotifier { /// Creates a new camera controller in an uninitialized state. + /// + /// - [resolutionPreset] affect the quality of video recording and image capture. + /// - [enableAudio] controls audio presence in recorded video. + /// + /// Following parameters (if present) will overwrite [resolutionPreset] settings: + /// - [fps] controls rate at which frames should be captured by the camera in frames per second. + /// - [videoBitrate] controls the video encoding bit rate for recording. + /// - [audioBitrate] controls the audio encoding bit rate for recording. + CameraController( CameraDescription description, - this.resolutionPreset, { - this.enableAudio = true, + ResolutionPreset resolutionPreset, { + bool enableAudio = true, + int? fps, + int? videoBitrate, + int? audioBitrate, this.imageFormatGroup, - }) : super(CameraValue.uninitialized(description)); + }) : mediaSettings = MediaSettings( + resolutionPreset: resolutionPreset, + enableAudio: enableAudio, + fps: fps, + videoBitrate: videoBitrate, + audioBitrate: audioBitrate), + super(CameraValue.uninitialized(description)); /// The properties of the camera device controlled by this controller. CameraDescription get description => value.description; @@ -248,10 +266,19 @@ class CameraController extends ValueNotifier { /// if unavailable a lower resolution will be used. /// /// See also: [ResolutionPreset]. - final ResolutionPreset resolutionPreset; + ResolutionPreset get resolutionPreset => + mediaSettings.resolutionPreset ?? ResolutionPreset.max; /// Whether to include audio when recording a video. - final bool enableAudio; + bool get enableAudio => mediaSettings.enableAudio; + + /// The media settings this controller is targeting. + /// + /// This media settings are not guaranteed to be available on the device, + /// if unavailable a [resolutionPreset] default values will be used. + /// + /// See also: [MediaSettings]. + final MediaSettings mediaSettings; /// The [ImageFormatGroup] describes the output of the raw image format. /// @@ -265,6 +292,7 @@ class CameraController extends ValueNotifier { bool _isDisposed = false; StreamSubscription? _imageStreamSubscription; + // A Future awaiting an attempt to initialize (e.g. after `initialize` was // just called). If the controller has not been initialized at least once, // this value is null. @@ -313,10 +341,9 @@ class CameraController extends ValueNotifier { ); }); - _cameraId = await CameraPlatform.instance.createCamera( + _cameraId = await CameraPlatform.instance.createCameraWithSettings( description, - resolutionPreset, - enableAudio: enableAudio, + mediaSettings, ); _unawaited(CameraPlatform.instance @@ -372,7 +399,7 @@ class CameraController extends ValueNotifier { /// Pauses the current camera preview Future pausePreview() async { - if (value.isPreviewPaused) { + if (value.isPreviewPaused || !value.isInitialized || _isDisposed) { return; } try { @@ -923,7 +950,7 @@ class Optional extends IterableBase { if (_value == null) { throw StateError('value called on absent Optional.'); } - return _value!; + return _value; } /// Executes a function if the Optional value is present. @@ -960,7 +987,7 @@ class Optional extends IterableBase { Optional transform(S Function(T value) transformer) { return _value == null ? Optional.absent() - : Optional.of(transformer(_value as T)); + : Optional.of(transformer(_value)); } /// Transforms the Optional value. @@ -971,7 +998,7 @@ class Optional extends IterableBase { Optional transformNullable(S? Function(T value) transformer) { return _value == null ? Optional.absent() - : Optional.fromNullable(transformer(_value as T)); + : Optional.fromNullable(transformer(_value)); } @override diff --git a/packages/camera/camera/pubspec.yaml b/packages/camera/camera/pubspec.yaml index dc5755bb882..10533970c7e 100644 --- a/packages/camera/camera/pubspec.yaml +++ b/packages/camera/camera/pubspec.yaml @@ -4,11 +4,11 @@ description: A Flutter plugin for controlling the camera. Supports previewing Dart. repository: https://github.com/flutter/packages/tree/main/packages/camera/camera issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22 -version: 0.10.5+9 +version: 0.10.6 environment: - sdk: ^3.1.0 - flutter: ">=3.13.0" + sdk: ^3.2.3 + flutter: ">=3.16.6" flutter: plugin: @@ -21,10 +21,10 @@ flutter: default_package: camera_web dependencies: - camera_android: ^0.10.7 - camera_avfoundation: ^0.9.13 - camera_platform_interface: ^2.5.0 - camera_web: ^0.3.1 + camera_android: ^0.10.9 + camera_avfoundation: ^0.9.15 + camera_platform_interface: ^2.6.0 + camera_web: ^0.3.3 flutter: sdk: flutter flutter_plugin_android_lifecycle: ^2.0.2 diff --git a/packages/camera/camera/test/camera_preview_test.dart b/packages/camera/camera/test/camera_preview_test.dart index c73e1816445..4b5a2a5b516 100644 --- a/packages/camera/camera/test/camera_preview_test.dart +++ b/packages/camera/camera/test/camera_preview_test.dart @@ -3,6 +3,7 @@ // found in the LICENSE file. import 'package:camera/camera.dart'; +import 'package:camera_platform_interface/camera_platform_interface.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -68,6 +69,15 @@ class FakeController extends ValueNotifier @override ResolutionPreset get resolutionPreset => ResolutionPreset.low; + @override + MediaSettings get mediaSettings => const MediaSettings( + resolutionPreset: ResolutionPreset.low, + fps: 15, + videoBitrate: 200000, + audioBitrate: 32000, + enableAudio: true, + ); + @override Future resumeVideoRecording() async {} diff --git a/packages/camera/camera/test/camera_test.dart b/packages/camera/camera/test/camera_test.dart index ec111ed8594..f10015334d5 100644 --- a/packages/camera/camera/test/camera_test.dart +++ b/packages/camera/camera/test/camera_test.dart @@ -111,6 +111,46 @@ void main() { expect(cameraController.value.isInitialized, isTrue); }); + test('can be initialized with media settings', () async { + final CameraController cameraController = CameraController( + const CameraDescription( + name: 'cam', + lensDirection: CameraLensDirection.back, + sensorOrientation: 90), + ResolutionPreset.low, + fps: 15, + videoBitrate: 200000, + audioBitrate: 32000, + enableAudio: false, + ); + await cameraController.initialize(); + + expect(cameraController.value.aspectRatio, 1); + expect(cameraController.value.previewSize, const Size(75, 75)); + expect(cameraController.value.isInitialized, isTrue); + expect(cameraController.resolutionPreset, ResolutionPreset.low); + expect(cameraController.enableAudio, false); + expect(cameraController.mediaSettings.fps, 15); + expect(cameraController.mediaSettings.videoBitrate, 200000); + expect(cameraController.mediaSettings.audioBitrate, 32000); + }); + + test('default constructor initializes media settings', () async { + final CameraController cameraController = CameraController( + const CameraDescription( + name: 'cam', + lensDirection: CameraLensDirection.back, + sensorOrientation: 90), + ResolutionPreset.max); + await cameraController.initialize(); + + expect(cameraController.resolutionPreset, ResolutionPreset.max); + expect(cameraController.enableAudio, true); + expect(cameraController.mediaSettings.fps, isNull); + expect(cameraController.mediaSettings.videoBitrate, isNull); + expect(cameraController.mediaSettings.audioBitrate, isNull); + }); + test('can be disposed', () async { final CameraController cameraController = CameraController( const CameraDescription( @@ -1429,15 +1469,20 @@ class MockCameraPlatform extends Mock Future> availableCameras() => Future>.value(mockAvailableCameras); + @override + Future createCameraWithSettings( + CameraDescription cameraDescription, MediaSettings? mediaSettings) => + mockPlatformException + ? throw PlatformException(code: 'foo', message: 'bar') + : Future.value(mockInitializeCamera); + @override Future createCamera( CameraDescription description, ResolutionPreset? resolutionPreset, { bool enableAudio = false, }) => - mockPlatformException - ? throw PlatformException(code: 'foo', message: 'bar') - : Future.value(mockInitializeCamera); + createCameraWithSettings(description, null); @override Stream onCameraInitialized(int cameraId) => diff --git a/packages/camera/camera_android_camerax/CHANGELOG.md b/packages/camera/camera_android_camerax/CHANGELOG.md index f719078b681..863f99b8aa8 100644 --- a/packages/camera/camera_android_camerax/CHANGELOG.md +++ b/packages/camera/camera_android_camerax/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.6.4 + +* Prevents usage of unsupported concurrent `UseCase`s based on the capabiliites of the camera device. + ## 0.6.3 * Shortens default interval that internal Java `InstanceManager` uses to release garbage collected weak references to diff --git a/packages/camera/camera_android_camerax/README.md b/packages/camera/camera_android_camerax/README.md index 64a56f1a3b5..d7e31e92e03 100644 --- a/packages/camera/camera_android_camerax/README.md +++ b/packages/camera/camera_android_camerax/README.md @@ -21,6 +21,22 @@ from your project's root directory. ## Limitations +### Concurrent preview display, video recording, image capture, and image streaming + +The CameraX plugin only supports the concurrent camera use cases supported by Camerax; see +[their documentation][6] for more information. To avoid the usage of unsupported concurrent +use cases, the plugin behaves according to the following: + +* If the preview is paused (via `pausePreview`), concurrent video recording and image capture + and/or image streaming (via `startVideoCapturing(cameraId, VideoCaptureOptions(streamCallback:...))`) + is supported. +* If the preview is not paused + * **and** the camera device is at least supported hardware [`LIMITED`][8], then concurrent + image capture and video recording is supported. + * **and** the camera device is at least supported hardware [`LEVEL_3`][7], then concurrent + video recording and image streaming is supported, but concurrent video recording, image + streaming, and image capture is not supported. + ### 240p resolution configuration for video recording 240p resolution configuration for video recording is unsupported by CameraX, @@ -45,6 +61,9 @@ For more information on contributing to this plugin, see [`CONTRIBUTING.md`](CON [3]: https://docs.flutter.dev/packages-and-plugins/developing-packages#non-endorsed-federated-plugin [4]: https://pub.dev/packages/camera_android [5]: https://github.com/flutter/flutter/issues/new/choose +[6]: https://developer.android.com/media/camera/camerax/architecture#combine-use-cases +[7]: https://developer.android.com/reference/android/hardware/camera2/CameraMetadata#INFO_SUPPORTED_HARDWARE_LEVEL_3 +[8]: https://developer.android.com/reference/android/hardware/camera2/CameraMetadata#INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED [120462]: https://github.com/flutter/flutter/issues/120462 [125915]: https://github.com/flutter/flutter/issues/125915 [120715]: https://github.com/flutter/flutter/issues/120715 diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/Camera2CameraInfoFlutterApiImpl.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/Camera2CameraInfoFlutterApiImpl.java new file mode 100644 index 00000000000..398fc38049a --- /dev/null +++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/Camera2CameraInfoFlutterApiImpl.java @@ -0,0 +1,27 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.camerax; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.camera.camera2.interop.Camera2CameraInfo; +import io.flutter.plugin.common.BinaryMessenger; +import io.flutter.plugins.camerax.GeneratedCameraXLibrary.Camera2CameraInfoFlutterApi; + +public class Camera2CameraInfoFlutterApiImpl extends Camera2CameraInfoFlutterApi { + private final InstanceManager instanceManager; + + public Camera2CameraInfoFlutterApiImpl( + @Nullable BinaryMessenger binaryMessenger, @Nullable InstanceManager instanceManager) { + super(binaryMessenger); + this.instanceManager = instanceManager; + } + + void create(@NonNull Camera2CameraInfo camera2CameraInfo, @Nullable Reply reply) { + if (!instanceManager.containsInstance(camera2CameraInfo)) { + create(instanceManager.addHostCreatedInstance(camera2CameraInfo), reply); + } + } +} diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/Camera2CameraInfoHostApiImpl.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/Camera2CameraInfoHostApiImpl.java new file mode 100644 index 00000000000..43fd0a383b0 --- /dev/null +++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/Camera2CameraInfoHostApiImpl.java @@ -0,0 +1,111 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.camerax; + +import android.content.Context; +import android.hardware.camera2.CameraCharacteristics; +import androidx.annotation.NonNull; +import androidx.annotation.OptIn; +import androidx.annotation.VisibleForTesting; +import androidx.camera.camera2.interop.Camera2CameraInfo; +import androidx.camera.camera2.interop.ExperimentalCamera2Interop; +import androidx.camera.core.CameraInfo; +import io.flutter.plugin.common.BinaryMessenger; +import io.flutter.plugins.camerax.GeneratedCameraXLibrary.Camera2CameraInfoHostApi; +import java.util.Objects; + +/** + * Host API implementation for {@link Camera2CameraInfo}. + * + *

This class handles instantiating and adding native object instances that are attached to a + * Dart instance or handle method calls on the associated native class or an instance of the class. + */ +public class Camera2CameraInfoHostApiImpl implements Camera2CameraInfoHostApi { + private final BinaryMessenger binaryMessenger; + private final InstanceManager instanceManager; + private final Camera2CameraInfoProxy proxy; + + /** Proxy for methods of {@link Camera2CameraInfo}. */ + @VisibleForTesting + public static class Camera2CameraInfoProxy { + + @NonNull + @OptIn(markerClass = ExperimentalCamera2Interop.class) + public Camera2CameraInfo createFrom(@NonNull CameraInfo cameraInfo) { + return Camera2CameraInfo.from(cameraInfo); + } + + @NonNull + @OptIn(markerClass = ExperimentalCamera2Interop.class) + public Integer getSupportedHardwareLevel(@NonNull Camera2CameraInfo camera2CameraInfo) { + return camera2CameraInfo.getCameraCharacteristic( + CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL); + } + + @NonNull + @OptIn(markerClass = ExperimentalCamera2Interop.class) + public String getCameraId(@NonNull Camera2CameraInfo camera2CameraInfo) { + return camera2CameraInfo.getCameraId(); + } + } + + /** + * Constructs an {@link Camera2CameraInfoHostApiImpl}. + * + * @param binaryMessenger used to communicate with Dart over asynchronous messages + * @param instanceManager maintains instances stored to communicate with attached Dart objects + * @param context {@link Context} used to retrieve {@code Executor} + */ + public Camera2CameraInfoHostApiImpl( + @NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) { + this(binaryMessenger, instanceManager, new Camera2CameraInfoProxy()); + } + + /** + * Constructs an {@link Camera2CameraInfoHostApiImpl}. + * + * @param binaryMessenger used to communicate with Dart over asynchronous messages + * @param instanceManager maintains instances stored to communicate with attached Dart objects + * @param proxy proxy for methods of {@link Camera2CameraInfo} + */ + @VisibleForTesting + Camera2CameraInfoHostApiImpl( + @NonNull BinaryMessenger binaryMessenger, + @NonNull InstanceManager instanceManager, + @NonNull Camera2CameraInfoProxy proxy) { + this.instanceManager = instanceManager; + this.binaryMessenger = binaryMessenger; + this.proxy = proxy; + } + + @Override + @NonNull + public Long createFrom(@NonNull Long cameraInfoIdentifier) { + final CameraInfo cameraInfo = + Objects.requireNonNull(instanceManager.getInstance(cameraInfoIdentifier)); + final Camera2CameraInfo camera2CameraInfo = proxy.createFrom(cameraInfo); + final Camera2CameraInfoFlutterApiImpl flutterApi = + new Camera2CameraInfoFlutterApiImpl(binaryMessenger, instanceManager); + + flutterApi.create(camera2CameraInfo, reply -> {}); + return instanceManager.getIdentifierForStrongReference(camera2CameraInfo); + } + + @Override + @NonNull + public Long getSupportedHardwareLevel(@NonNull Long identifier) { + return Long.valueOf(proxy.getSupportedHardwareLevel(getCamera2CameraInfoInstance(identifier))); + } + + @Override + @NonNull + public String getCameraId(@NonNull Long identifier) { + return proxy.getCameraId(getCamera2CameraInfoInstance(identifier)); + } + + private Camera2CameraInfo getCamera2CameraInfoInstance(@NonNull Long identifier) { + return Objects.requireNonNull(instanceManager.getInstance(identifier)); + } +} diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraAndroidCameraxPlugin.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraAndroidCameraxPlugin.java index d281bbe65a8..42e5df0f32c 100644 --- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraAndroidCameraxPlugin.java +++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraAndroidCameraxPlugin.java @@ -136,6 +136,8 @@ public void setUp( GeneratedCameraXLibrary.MeteringPointHostApi.setup(binaryMessenger, meteringPointHostApiImpl); GeneratedCameraXLibrary.ResolutionFilterHostApi.setup( binaryMessenger, new ResolutionFilterHostApiImpl(instanceManager)); + GeneratedCameraXLibrary.Camera2CameraInfoHostApi.setup( + binaryMessenger, new Camera2CameraInfoHostApiImpl(binaryMessenger, instanceManager)); } @Override diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/GeneratedCameraXLibrary.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/GeneratedCameraXLibrary.java index fa6be792096..41094fd858a 100644 --- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/GeneratedCameraXLibrary.java +++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/GeneratedCameraXLibrary.java @@ -4267,4 +4267,137 @@ static void setup( } } } + /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ + public interface Camera2CameraInfoHostApi { + + @NonNull + Long createFrom(@NonNull Long cameraInfoIdentifier); + + @NonNull + Long getSupportedHardwareLevel(@NonNull Long identifier); + + @NonNull + String getCameraId(@NonNull Long identifier); + + /** The codec used by Camera2CameraInfoHostApi. */ + static @NonNull MessageCodec getCodec() { + return new StandardMessageCodec(); + } + /** + * Sets up an instance of `Camera2CameraInfoHostApi` to handle messages through the + * `binaryMessenger`. + */ + static void setup( + @NonNull BinaryMessenger binaryMessenger, @Nullable Camera2CameraInfoHostApi api) { + { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.Camera2CameraInfoHostApi.createFrom", + getCodec()); + if (api != null) { + channel.setMessageHandler( + (message, reply) -> { + ArrayList wrapped = new ArrayList(); + ArrayList args = (ArrayList) message; + Number cameraInfoIdentifierArg = (Number) args.get(0); + try { + Long output = + api.createFrom( + (cameraInfoIdentifierArg == null) + ? null + : cameraInfoIdentifierArg.longValue()); + wrapped.add(0, output); + } catch (Throwable exception) { + ArrayList wrappedError = wrapError(exception); + wrapped = wrappedError; + } + reply.reply(wrapped); + }); + } else { + channel.setMessageHandler(null); + } + } + { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.Camera2CameraInfoHostApi.getSupportedHardwareLevel", + getCodec()); + if (api != null) { + channel.setMessageHandler( + (message, reply) -> { + ArrayList wrapped = new ArrayList(); + ArrayList args = (ArrayList) message; + Number identifierArg = (Number) args.get(0); + try { + Long output = + api.getSupportedHardwareLevel( + (identifierArg == null) ? null : identifierArg.longValue()); + wrapped.add(0, output); + } catch (Throwable exception) { + ArrayList wrappedError = wrapError(exception); + wrapped = wrappedError; + } + reply.reply(wrapped); + }); + } else { + channel.setMessageHandler(null); + } + } + { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.Camera2CameraInfoHostApi.getCameraId", + getCodec()); + if (api != null) { + channel.setMessageHandler( + (message, reply) -> { + ArrayList wrapped = new ArrayList(); + ArrayList args = (ArrayList) message; + Number identifierArg = (Number) args.get(0); + try { + String output = + api.getCameraId((identifierArg == null) ? null : identifierArg.longValue()); + wrapped.add(0, output); + } catch (Throwable exception) { + ArrayList wrappedError = wrapError(exception); + wrapped = wrappedError; + } + reply.reply(wrapped); + }); + } else { + channel.setMessageHandler(null); + } + } + } + } + /** Generated class from Pigeon that represents Flutter messages that can be called from Java. */ + public static class Camera2CameraInfoFlutterApi { + private final @NonNull BinaryMessenger binaryMessenger; + + public Camera2CameraInfoFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { + this.binaryMessenger = argBinaryMessenger; + } + + /** Public interface for sending reply. */ + @SuppressWarnings("UnknownNullness") + public interface Reply { + void reply(T reply); + } + /** The codec used by Camera2CameraInfoFlutterApi. */ + static @NonNull MessageCodec getCodec() { + return new StandardMessageCodec(); + } + + public void create(@NonNull Long identifierArg, @NonNull Reply callback) { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, "dev.flutter.pigeon.Camera2CameraInfoFlutterApi.create", getCodec()); + channel.send( + new ArrayList(Collections.singletonList(identifierArg)), + channelReply -> callback.reply(null)); + } + } } diff --git a/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/Camera2CameraInfoTest.java b/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/Camera2CameraInfoTest.java new file mode 100644 index 00000000000..a5ab10ff79b --- /dev/null +++ b/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/Camera2CameraInfoTest.java @@ -0,0 +1,114 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.camerax; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import android.hardware.camera2.CameraCharacteristics; +import android.hardware.camera2.CameraMetadata; +import androidx.camera.camera2.interop.Camera2CameraInfo; +import androidx.camera.core.CameraInfo; +import io.flutter.plugin.common.BinaryMessenger; +import java.util.Objects; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockedStatic; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; +import org.mockito.stubbing.Answer; + +public class Camera2CameraInfoTest { + @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); + + @Mock public Camera2CameraInfo mockCamera2CameraInfo; + + InstanceManager testInstanceManager; + + @Before + public void setUp() { + testInstanceManager = InstanceManager.create(identifier -> {}); + } + + @After + public void tearDown() { + testInstanceManager.stopFinalizationListener(); + } + + @Test + public void createFrom_createsInstanceFromCameraInfoInstance() { + final Camera2CameraInfoHostApiImpl hostApi = + new Camera2CameraInfoHostApiImpl(mock(BinaryMessenger.class), testInstanceManager); + final long camera2CameraInfoIdentifier = 60; + final CameraInfo mockCameraInfo = mock(CameraInfo.class); + final long cameraInfoIdentifier = 92; + + testInstanceManager.addDartCreatedInstance(mockCameraInfo, cameraInfoIdentifier); + testInstanceManager.addDartCreatedInstance(mockCamera2CameraInfo, camera2CameraInfoIdentifier); + + try (MockedStatic mockedCamera2CameraInfo = + Mockito.mockStatic(Camera2CameraInfo.class)) { + mockedCamera2CameraInfo + .when(() -> Camera2CameraInfo.from(mockCameraInfo)) + .thenAnswer((Answer) invocation -> mockCamera2CameraInfo); + + hostApi.createFrom(cameraInfoIdentifier); + assertEquals( + testInstanceManager.getInstance(camera2CameraInfoIdentifier), mockCamera2CameraInfo); + } + } + + @Test + public void getSupportedHardwareLevel_returnsExpectedLevel() { + final Camera2CameraInfoHostApiImpl hostApi = + new Camera2CameraInfoHostApiImpl(mock(BinaryMessenger.class), testInstanceManager); + final long camera2CameraInfoIdentifier = 3; + final int expectedHardwareLevel = CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_FULL; + + testInstanceManager.addDartCreatedInstance(mockCamera2CameraInfo, camera2CameraInfoIdentifier); + when(mockCamera2CameraInfo.getCameraCharacteristic( + CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL)) + .thenReturn(expectedHardwareLevel); + + assertEquals( + expectedHardwareLevel, + hostApi.getSupportedHardwareLevel(camera2CameraInfoIdentifier).intValue()); + } + + @Test + public void getCameraId_returnsExpectedId() { + final Camera2CameraInfoHostApiImpl hostApi = + new Camera2CameraInfoHostApiImpl(mock(BinaryMessenger.class), testInstanceManager); + final long camera2CameraInfoIdentifier = 13; + final String expectedCameraId = "testCameraId"; + + testInstanceManager.addDartCreatedInstance(mockCamera2CameraInfo, camera2CameraInfoIdentifier); + when(mockCamera2CameraInfo.getCameraId()).thenReturn(expectedCameraId); + + assertEquals(expectedCameraId, hostApi.getCameraId(camera2CameraInfoIdentifier)); + } + + @Test + public void flutterApiCreate_makesCallToCreateInstanceOnDartSide() { + final Camera2CameraInfoFlutterApiImpl spyFlutterApi = + spy(new Camera2CameraInfoFlutterApiImpl(mock(BinaryMessenger.class), testInstanceManager)); + + spyFlutterApi.create(mockCamera2CameraInfo, reply -> {}); + + final long identifier = + Objects.requireNonNull( + testInstanceManager.getIdentifierForStrongReference(mockCamera2CameraInfo)); + verify(spyFlutterApi).create(eq(identifier), any()); + } +} diff --git a/packages/camera/camera_android_camerax/lib/src/android_camera_camerax.dart b/packages/camera/camera_android_camerax/lib/src/android_camera_camerax.dart index e6ef399b657..b73ce0186be 100644 --- a/packages/camera/camera_android_camerax/lib/src/android_camera_camerax.dart +++ b/packages/camera/camera_android_camerax/lib/src/android_camera_camerax.dart @@ -17,8 +17,10 @@ import 'analyzer.dart'; import 'aspect_ratio_strategy.dart'; import 'camera.dart'; import 'camera2_camera_control.dart'; +import 'camera2_camera_info.dart'; import 'camera_control.dart'; import 'camera_info.dart'; +import 'camera_metadata.dart'; import 'camera_selector.dart'; import 'camera_state.dart'; import 'camerax_library.g.dart'; @@ -261,6 +263,8 @@ class AndroidCameraCameraX extends CameraPlatform { cameraName = 'Camera $cameraCount'; cameraCount++; + // TODO(camsim99): Use camera ID retrieved from Camera2CameraInfo as + // camera name: https://github.com/flutter/flutter/issues/147545. cameraDescriptions.add(CameraDescription( name: cameraName, lensDirection: cameraLensDirection, @@ -291,9 +295,9 @@ class AndroidCameraCameraX extends CameraPlatform { /// uninitialized camera instance, this method retrieves a /// [ProcessCameraProvider] instance. /// - /// The specified [resolutionPreset] is the target resolution that CameraX - /// will attempt to select for the [UseCase]s constructed in this method - /// ([preview], [imageCapture], [imageAnalysis], [videoCapture]). If + /// The specified `mediaSettings.resolutionPreset` is the target resolution + /// that CameraX will attempt to select for the [UseCase]s constructed in this + /// method ([preview], [imageCapture], [imageAnalysis], [videoCapture]). If /// unavailable, a fallback behavior of targeting the next highest resolution /// will be attempted. See https://developer.android.com/media/camera/camerax/configuration#specify-resolution. /// @@ -779,7 +783,7 @@ class AndroidCameraCameraX extends CameraPlatform { @override Future resumePreview(int cameraId) async { _previewIsPaused = false; - await _bindPreviewToLifecycle(cameraId); + await _bindUseCaseToLifecycle(preview!, cameraId); } /// Returns a widget showing a live camera preview. @@ -804,6 +808,7 @@ class AndroidCameraCameraX extends CameraPlatform { /// [cameraId] is not used. @override Future takePicture(int cameraId) async { + await _bindUseCaseToLifecycle(imageCapture!, cameraId); // Set flash mode. if (_currentFlashMode != null) { await imageCapture!.setFlashMode(_currentFlashMode!); @@ -890,12 +895,50 @@ class AndroidCameraCameraX extends CameraPlatform { return; } - if (!(await processCameraProvider!.isBound(videoCapture!))) { - camera = await processCameraProvider! - .bindToLifecycle(cameraSelector!, [videoCapture!]); - await _updateCameraInfoAndLiveCameraState(options.cameraId); + dynamic Function(CameraImageData)? streamCallback = options.streamCallback; + if (!_previewIsPaused) { + // The plugin binds the preview use case to the camera lifecycle when + // createCamera is called, but camera use cases can become limited + // when video recording and displaying a preview concurrently. This logic + // will prioritize attempting to continue displaying the preview, + // stream images, and record video if specified and supported. Otherwise, + // the preview must be paused in order to allow those concurrently. See + // https://developer.android.com/media/camera/camerax/architecture#combine-use-cases + // for more information on supported concurrent camera use cases. + final Camera2CameraInfo camera2CameraInfo = + await proxy.getCamera2CameraInfo(cameraInfo!); + final int cameraInfoSupportedHardwareLevel = + await camera2CameraInfo.getSupportedHardwareLevel(); + + // Handle limited level device restrictions: + final bool cameraSupportsConcurrentImageCapture = + cameraInfoSupportedHardwareLevel != + CameraMetadata.infoSupportedHardwareLevelLegacy; + if (!cameraSupportsConcurrentImageCapture) { + // Concurrent preview + video recording + image capture is not supported + // unless the camera device is cameraSupportsHardwareLevelLimited or + // better. + await _unbindUseCaseFromLifecycle(imageCapture!); + } + + // Handle level 3 device restrictions: + final bool cameraSupportsHardwareLevel3 = + cameraInfoSupportedHardwareLevel == + CameraMetadata.infoSupportedHardwareLevel3; + if (!cameraSupportsHardwareLevel3 || streamCallback == null) { + // Concurrent preview + video recording + image streaming is not supported + // unless the camera device is cameraSupportsHardwareLevel3 or better. + streamCallback = null; + await _unbindUseCaseFromLifecycle(imageAnalysis!); + } else { + // If image streaming concurrently with video recording, image capture + // is unsupported. + await _unbindUseCaseFromLifecycle(imageCapture!); + } } + await _bindUseCaseToLifecycle(videoCapture!, options.cameraId); + // Set target rotation to default CameraX rotation only if capture // orientation not locked. if (!captureOrientationLocked && shouldSetDefaultRotation) { @@ -908,8 +951,8 @@ class AndroidCameraCameraX extends CameraPlatform { pendingRecording = await recorder!.prepareRecording(videoOutputPath!); recording = await pendingRecording!.start(); - if (options.streamCallback != null) { - onStreamedFrameAvailable(options.cameraId).listen(options.streamCallback); + if (streamCallback != null) { + onStreamedFrameAvailable(options.cameraId).listen(streamCallback); } } @@ -942,6 +985,7 @@ class AndroidCameraCameraX extends CameraPlatform { await recording!.close(); recording = null; pendingRecording = null; + await _unbindUseCaseFromLifecycle(videoCapture!); return XFile(videoOutputPath!); } @@ -975,7 +1019,7 @@ class AndroidCameraCameraX extends CameraPlatform { Stream onStreamedFrameAvailable(int cameraId, {CameraImageStreamOptions? options}) { cameraImageDataStreamController = StreamController( - onListen: () => _configureImageAnalysis(cameraId), + onListen: () async => _configureImageAnalysis(cameraId), onCancel: _onFrameStreamCancel, ); return cameraImageDataStreamController!.stream; @@ -984,26 +1028,32 @@ class AndroidCameraCameraX extends CameraPlatform { // Methods for binding UseCases to the lifecycle of the camera controlled // by a ProcessCameraProvider instance: - /// Binds [preview] instance to the camera lifecycle controlled by the - /// [processCameraProvider]. + /// Binds [useCase] to the camera lifecycle controlled by the + /// [processCameraProvider] if not already bound. /// /// [cameraId] used to build [CameraEvent]s should you wish to filter /// these based on a reference to a cameraId received from calling /// `createCamera(...)`. - Future _bindPreviewToLifecycle(int cameraId) async { - final bool previewIsBound = await processCameraProvider!.isBound(preview!); - if (previewIsBound || _previewIsPaused) { - // Only bind if preview is not already bound or intentionally paused. + Future _bindUseCaseToLifecycle(UseCase useCase, int cameraId) async { + final bool useCaseIsBound = await processCameraProvider!.isBound(useCase); + final bool useCaseIsPausedPreview = useCase is Preview && _previewIsPaused; + + if (useCaseIsBound || useCaseIsPausedPreview) { + // Only bind if useCase is not already bound or preview is intentionally + // paused. return; } camera = await processCameraProvider! - .bindToLifecycle(cameraSelector!, [preview!]); + .bindToLifecycle(cameraSelector!, [useCase]); + await _updateCameraInfoAndLiveCameraState(cameraId); } /// Configures the [imageAnalysis] instance for image streaming. Future _configureImageAnalysis(int cameraId) async { + await _bindUseCaseToLifecycle(imageAnalysis!, cameraId); + // Set target rotation to default CameraX rotation only if capture // orientation not locked. if (!captureOrientationLocked && shouldSetDefaultRotation) { @@ -1044,7 +1094,7 @@ class AndroidCameraCameraX extends CameraPlatform { } /// Unbinds [useCase] from camera lifecycle controlled by the - /// [processCameraProvider]. + /// [processCameraProvider] if not already unbound. Future _unbindUseCaseFromLifecycle(UseCase useCase) async { final bool useCaseIsBound = await processCameraProvider!.isBound(useCase); if (!useCaseIsBound) { @@ -1145,13 +1195,13 @@ class AndroidCameraCameraX extends CameraPlatform { int _getRotationConstantFromDeviceOrientation(DeviceOrientation orientation) { switch (orientation) { case DeviceOrientation.portraitUp: - return Surface.ROTATION_0; + return Surface.rotation0; case DeviceOrientation.landscapeLeft: - return Surface.ROTATION_90; + return Surface.rotation90; case DeviceOrientation.portraitDown: - return Surface.ROTATION_180; + return Surface.rotation180; case DeviceOrientation.landscapeRight: - return Surface.ROTATION_270; + return Surface.rotation270; } } diff --git a/packages/camera/camera_android_camerax/lib/src/android_camera_camerax_flutter_api_impls.dart b/packages/camera/camera_android_camerax/lib/src/android_camera_camerax_flutter_api_impls.dart index db7ec4b32d4..c4e95d0037f 100644 --- a/packages/camera/camera_android_camerax/lib/src/android_camera_camerax_flutter_api_impls.dart +++ b/packages/camera/camera_android_camerax/lib/src/android_camera_camerax_flutter_api_impls.dart @@ -4,6 +4,7 @@ import 'analyzer.dart'; import 'camera.dart'; +import 'camera2_camera_info.dart'; import 'camera_control.dart'; import 'camera_info.dart'; import 'camera_selector.dart'; @@ -52,7 +53,8 @@ class AndroidCameraXCameraFlutterApis { PlaneProxyFlutterApiImpl? planeProxyFlutterApiImpl, AnalyzerFlutterApiImpl? analyzerFlutterApiImpl, CameraControlFlutterApiImpl? cameraControlFlutterApiImpl, - FocusMeteringResultFlutterApiImpl? focusMeteringResultFlutterApiImpl}) { + FocusMeteringResultFlutterApiImpl? focusMeteringResultFlutterApiImpl, + Camera2CameraInfoFlutterApiImpl? camera2CameraInfoFlutterApiImpl}) { this.javaObjectFlutterApiImpl = javaObjectFlutterApiImpl ?? JavaObjectFlutterApiImpl(); this.cameraInfoFlutterApiImpl = @@ -99,6 +101,8 @@ class AndroidCameraXCameraFlutterApis { this.focusMeteringResultFlutterApiImpl = focusMeteringResultFlutterApiImpl ?? FocusMeteringResultFlutterApiImpl(); + this.camera2CameraInfoFlutterApiImpl = + camera2CameraInfoFlutterApiImpl ?? Camera2CameraInfoFlutterApiImpl(); } static bool _haveBeenSetUp = false; @@ -178,6 +182,9 @@ class AndroidCameraXCameraFlutterApis { late final FocusMeteringResultFlutterApiImpl focusMeteringResultFlutterApiImpl; + /// Fluter Api implementation for [Camera2CameraInfo]. + late final Camera2CameraInfoFlutterApiImpl camera2CameraInfoFlutterApiImpl; + /// Ensures all the Flutter APIs have been setup to receive calls from native code. void ensureSetUp() { if (!_haveBeenSetUp) { @@ -205,6 +212,7 @@ class AndroidCameraXCameraFlutterApis { ObserverFlutterApi.setup(observerFlutterApiImpl); CameraControlFlutterApi.setup(cameraControlFlutterApiImpl); FocusMeteringResultFlutterApi.setup(focusMeteringResultFlutterApiImpl); + Camera2CameraInfoFlutterApi.setup(camera2CameraInfoFlutterApiImpl); _haveBeenSetUp = true; } } diff --git a/packages/camera/camera_android_camerax/lib/src/camera2_camera_info.dart b/packages/camera/camera_android_camerax/lib/src/camera2_camera_info.dart new file mode 100644 index 00000000000..fafb90f0ecb --- /dev/null +++ b/packages/camera/camera_android_camerax/lib/src/camera2_camera_info.dart @@ -0,0 +1,131 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; + +import 'package:flutter/services.dart' show BinaryMessenger; +import 'package:meta/meta.dart' show immutable; + +import 'android_camera_camerax_flutter_api_impls.dart'; +import 'camera_info.dart'; +import 'camerax_library.g.dart'; +import 'instance_manager.dart'; +import 'java_object.dart'; + +/// Interface for retrieving Camera2-related camera information. +/// +/// See https://developer.android.com/reference/androidx/camera/camera2/interop/Camera2CameraInfo. +@immutable +class Camera2CameraInfo extends JavaObject { + /// Constructs a [Camera2CameraInfo] that is not automatically attached to a native object. + Camera2CameraInfo.detached( + {BinaryMessenger? binaryMessenger, InstanceManager? instanceManager}) + : super.detached( + binaryMessenger: binaryMessenger, + instanceManager: instanceManager) { + _api = _Camera2CameraInfoHostApiImpl( + binaryMessenger: binaryMessenger, instanceManager: instanceManager); + AndroidCameraXCameraFlutterApis.instance.ensureSetUp(); + } + + late final _Camera2CameraInfoHostApiImpl _api; + + /// Retrieves [Camera2CameraInfo] instance from [cameraInfo]. + static Future from(CameraInfo cameraInfo, + {BinaryMessenger? binaryMessenger, InstanceManager? instanceManager}) { + final _Camera2CameraInfoHostApiImpl api = _Camera2CameraInfoHostApiImpl( + binaryMessenger: binaryMessenger, instanceManager: instanceManager); + AndroidCameraXCameraFlutterApis.instance.ensureSetUp(); + return api.fromInstances(cameraInfo); + } + + /// Retrieves the value of `CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL` + /// for the device to which this instance pertains to. + /// + /// See https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics#INFO_SUPPORTED_HARDWARE_LEVEL + /// for more information. + Future getSupportedHardwareLevel() => + _api.getSupportedHardwareLevelFromInstance(this); + + /// Gets the camera ID. + /// + /// The ID may change based on the internal configuration of the camera to which + /// this instances pertains. + Future getCameraId() => _api.getCameraIdFromInstance(this); +} + +/// Host API implementation of [Camera2CameraInfo]. +class _Camera2CameraInfoHostApiImpl extends Camera2CameraInfoHostApi { + /// Constructs a [_Camera2CameraInfoHostApiImpl]. + _Camera2CameraInfoHostApiImpl( + {this.binaryMessenger, InstanceManager? instanceManager}) + : instanceManager = instanceManager ?? JavaObject.globalInstanceManager, + super(binaryMessenger: binaryMessenger); + + /// Maintains instances stored to communicate with native language objects. + late final InstanceManager instanceManager; + + /// Receives binary data across the Flutter platform barrier. + /// + /// If it is null, the default [BinaryMessenger] will be used which routes to + /// the host platform. + final BinaryMessenger? binaryMessenger; + + /// Gets sensor orientation degrees of the specified [CameraInfo] instance. + Future fromInstances( + CameraInfo cameraInfo, + ) async { + final int? cameraInfoIdentifier = instanceManager.getIdentifier(cameraInfo); + return instanceManager.getInstanceWithWeakReference( + await createFrom(cameraInfoIdentifier!))!; + } + + Future getSupportedHardwareLevelFromInstance( + Camera2CameraInfo instance) { + final int? identifier = instanceManager.getIdentifier(instance); + return getSupportedHardwareLevel(identifier!); + } + + Future getCameraIdFromInstance(Camera2CameraInfo instance) { + final int? identifier = instanceManager.getIdentifier(instance); + return getCameraId(identifier!); + } +} + +/// Flutter API Implementation of [Camera2CameraInfo]. +class Camera2CameraInfoFlutterApiImpl implements Camera2CameraInfoFlutterApi { + /// Constructs an [Camera2CameraInfoFlutterApiImpl]. + /// + /// If [binaryMessenger] is null, the default [BinaryMessenger] will be used, + /// which routes to the host platform. + /// + /// An [instanceManager] is typically passed when a copy of an instance + /// contained by an [InstanceManager] is being created. If left null, it + /// will default to the global instance defined in [JavaObject]. + Camera2CameraInfoFlutterApiImpl({ + BinaryMessenger? binaryMessenger, + InstanceManager? instanceManager, + }) : _binaryMessenger = binaryMessenger, + _instanceManager = instanceManager ?? JavaObject.globalInstanceManager; + + /// Receives binary data across the Flutter platform barrier. + final BinaryMessenger? _binaryMessenger; + + /// Maintains instances stored to communicate with native language objects. + final InstanceManager _instanceManager; + + @override + void create(int identifier) { + _instanceManager.addHostCreatedInstance( + Camera2CameraInfo.detached( + binaryMessenger: _binaryMessenger, instanceManager: _instanceManager), + identifier, + onCopy: (Camera2CameraInfo original) { + return Camera2CameraInfo.detached( + binaryMessenger: _binaryMessenger, + instanceManager: _instanceManager); + }, + ); + } +} diff --git a/packages/camera/camera_android_camerax/lib/src/camera_metadata.dart b/packages/camera/camera_android_camerax/lib/src/camera_metadata.dart new file mode 100644 index 00000000000..65098b747c6 --- /dev/null +++ b/packages/camera/camera_android_camerax/lib/src/camera_metadata.dart @@ -0,0 +1,42 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:meta/meta.dart' show immutable; + +/// Base class for camera controls and information. +/// +/// See https://developer.android.com/reference/android/hardware/camera2/CameraMetadata. +@immutable +class CameraMetadata { + /// Constant that specifies a camera device does not have enough to quality as + /// a [infoSupportedHardwareLevelFull] level device or better. + /// + /// See https://developer.android.com/reference/android/hardware/camera2/CameraMetadata#INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED. + static const int infoSupportedHardwareLevelLimited = 0; + + /// Constant that specifies a camera device is capable of supporting advanced + /// imaging applications. + /// + /// See https://developer.android.com/reference/android/hardware/camera2/CameraMetadata#INFO_SUPPORTED_HARDWARE_LEVEL_FULL. + static const int infoSupportedHardwareLevelFull = 1; + + /// Constant that specifies a camera device is running in backward + /// compatibility mode. + /// + /// See https://developer.android.com/reference/android/hardware/camera2/CameraMetadata#INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY. + static const int infoSupportedHardwareLevelLegacy = 2; + + /// Constant that specifies a camera device is capable of YUV reprocessing and + /// RAW data capture in addition to [infoSupportedHardwareLevelFull] level + /// capabilities. + /// + /// See https://developer.android.com/reference/android/hardware/camera2/CameraMetadata#INFO_SUPPORTED_HARDWARE_LEVEL_3. + static const int infoSupportedHardwareLevel3 = 3; + + /// Constant taht specifies a camera device is backed by an external camera + /// connected to this Android device. + /// + /// See https://developer.android.com/reference/android/hardware/camera2/CameraMetadata#INFO_SUPPORTED_HARDWARE_LEVEL_EXTERNAL. + static const int infoSupportedHardwareLevelExternal = 4; +} diff --git a/packages/camera/camera_android_camerax/lib/src/camerax_library.g.dart b/packages/camera/camera_android_camerax/lib/src/camerax_library.g.dart index ac66dfd0ae7..550854fba3e 100644 --- a/packages/camera/camera_android_camerax/lib/src/camerax_library.g.dart +++ b/packages/camera/camera_android_camerax/lib/src/camerax_library.g.dart @@ -3403,3 +3403,125 @@ class ResolutionFilterHostApi { } } } + +class Camera2CameraInfoHostApi { + /// Constructor for [Camera2CameraInfoHostApi]. The [binaryMessenger] named argument is + /// available for dependency injection. If it is left null, the default + /// BinaryMessenger will be used which routes to the host platform. + Camera2CameraInfoHostApi({BinaryMessenger? binaryMessenger}) + : _binaryMessenger = binaryMessenger; + final BinaryMessenger? _binaryMessenger; + + static const MessageCodec codec = StandardMessageCodec(); + + Future createFrom(int arg_cameraInfoIdentifier) async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.Camera2CameraInfoHostApi.createFrom', codec, + binaryMessenger: _binaryMessenger); + final List? replyList = await channel + .send([arg_cameraInfoIdentifier]) as List?; + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else if (replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (replyList[0] as int?)!; + } + } + + Future getSupportedHardwareLevel(int arg_identifier) async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.Camera2CameraInfoHostApi.getSupportedHardwareLevel', + codec, + binaryMessenger: _binaryMessenger); + final List? replyList = + await channel.send([arg_identifier]) as List?; + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else if (replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (replyList[0] as int?)!; + } + } + + Future getCameraId(int arg_identifier) async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.Camera2CameraInfoHostApi.getCameraId', codec, + binaryMessenger: _binaryMessenger); + final List? replyList = + await channel.send([arg_identifier]) as List?; + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else if (replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (replyList[0] as String?)!; + } + } +} + +abstract class Camera2CameraInfoFlutterApi { + static const MessageCodec codec = StandardMessageCodec(); + + void create(int identifier); + + static void setup(Camera2CameraInfoFlutterApi? api, + {BinaryMessenger? binaryMessenger}) { + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.Camera2CameraInfoFlutterApi.create', codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.Camera2CameraInfoFlutterApi.create was null.'); + final List args = (message as List?)!; + final int? arg_identifier = (args[0] as int?); + assert(arg_identifier != null, + 'Argument for dev.flutter.pigeon.Camera2CameraInfoFlutterApi.create was null, expected non-null int.'); + api.create(arg_identifier!); + return; + }); + } + } + } +} diff --git a/packages/camera/camera_android_camerax/lib/src/camerax_proxy.dart b/packages/camera/camera_android_camerax/lib/src/camerax_proxy.dart index 6fec50ce398..d81d1c761c6 100644 --- a/packages/camera/camera_android_camerax/lib/src/camerax_proxy.dart +++ b/packages/camera/camera_android_camerax/lib/src/camerax_proxy.dart @@ -7,6 +7,7 @@ import 'dart:ui' show Size; import 'analyzer.dart'; import 'aspect_ratio_strategy.dart'; import 'camera2_camera_control.dart'; +import 'camera2_camera_info.dart'; import 'camera_control.dart'; import 'camera_info.dart'; import 'camera_selector.dart'; @@ -64,6 +65,7 @@ class CameraXProxy { this.createAspectRatioStrategy = _createAttachedAspectRatioStrategy, this.createResolutionFilterWithOnePreferredSize = _createAttachedResolutionFilterWithOnePreferredSize, + this.getCamera2CameraInfo = _getCamera2CameraInfo, }); /// Returns a [ProcessCameraProvider] instance. @@ -154,7 +156,7 @@ class CameraXProxy { /// rotation constants. Future Function() getDefaultDisplayRotation; - /// Get [Camera2CameraControl] instance from [cameraControl]. + /// Gets [Camera2CameraControl] instance from [cameraControl]. Camera2CameraControl Function(CameraControl cameraControl) getCamera2CameraControl; @@ -183,6 +185,10 @@ class CameraXProxy { ResolutionFilter Function(Size preferredResolution) createResolutionFilterWithOnePreferredSize; + /// Gets [Camera2CameraInfo] instance from [cameraInfo]. + Future Function(CameraInfo cameraInfo) + getCamera2CameraInfo; + static Future _getProcessCameraProvider() { return ProcessCameraProvider.getInstance(); } @@ -324,4 +330,9 @@ class CameraXProxy { return ResolutionFilter.onePreferredSize( preferredResolution: preferredSize); } + + static Future _getCamera2CameraInfo( + CameraInfo cameraInfo) async { + return Camera2CameraInfo.from(cameraInfo); + } } diff --git a/packages/camera/camera_android_camerax/lib/src/surface.dart b/packages/camera/camera_android_camerax/lib/src/surface.dart index e0ca96f639e..925b43bf3c0 100644 --- a/packages/camera/camera_android_camerax/lib/src/surface.dart +++ b/packages/camera/camera_android_camerax/lib/src/surface.dart @@ -18,20 +18,20 @@ class Surface extends JavaObject { /// Rotation constant to signify the natural orientation. /// /// See https://developer.android.com/reference/android/view/Surface.html#ROTATION_0. - static const int ROTATION_0 = 0; + static const int rotation0 = 0; /// Rotation constant to signify a 90 degrees rotation. /// /// See https://developer.android.com/reference/android/view/Surface.html#ROTATION_90. - static const int ROTATION_90 = 1; + static const int rotation90 = 1; /// Rotation constant to signify a 180 degrees rotation. /// /// See https://developer.android.com/reference/android/view/Surface.html#ROTATION_180. - static const int ROTATION_180 = 2; + static const int rotation180 = 2; /// Rotation constant to signify a 270 degrees rotation. /// /// See https://developer.android.com/reference/android/view/Surface.html#ROTATION_270. - static const int ROTATION_270 = 3; + static const int rotation270 = 3; } diff --git a/packages/camera/camera_android_camerax/pigeons/camerax_library.dart b/packages/camera/camera_android_camerax/pigeons/camerax_library.dart index 18741904a8d..f51eae8c306 100644 --- a/packages/camera/camera_android_camerax/pigeons/camerax_library.dart +++ b/packages/camera/camera_android_camerax/pigeons/camerax_library.dart @@ -543,3 +543,17 @@ abstract class ResolutionFilterHostApi { void createWithOnePreferredSize( int identifier, ResolutionInfo preferredResolution); } + +@HostApi(dartHostTestHandler: 'TestCamera2CameraInfoHostApi') +abstract class Camera2CameraInfoHostApi { + int createFrom(int cameraInfoIdentifier); + + int getSupportedHardwareLevel(int identifier); + + String getCameraId(int identifier); +} + +@FlutterApi() +abstract class Camera2CameraInfoFlutterApi { + void create(int identifier); +} diff --git a/packages/camera/camera_android_camerax/pubspec.yaml b/packages/camera/camera_android_camerax/pubspec.yaml index b3ce1dfca29..8f1b5d11bbc 100644 --- a/packages/camera/camera_android_camerax/pubspec.yaml +++ b/packages/camera/camera_android_camerax/pubspec.yaml @@ -2,7 +2,7 @@ name: camera_android_camerax description: Android implementation of the camera plugin using the CameraX library. repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_android_camerax issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22 -version: 0.6.3 +version: 0.6.4 environment: sdk: ^3.1.0 diff --git a/packages/camera/camera_android_camerax/test/android_camera_camerax_test.dart b/packages/camera/camera_android_camerax/test/android_camera_camerax_test.dart index da1bd76b03d..f0caef74a24 100644 --- a/packages/camera/camera_android_camerax/test/android_camera_camerax_test.dart +++ b/packages/camera/camera_android_camerax/test/android_camera_camerax_test.dart @@ -11,8 +11,10 @@ import 'package:camera_android_camerax/src/analyzer.dart'; import 'package:camera_android_camerax/src/aspect_ratio_strategy.dart'; import 'package:camera_android_camerax/src/camera.dart'; import 'package:camera_android_camerax/src/camera2_camera_control.dart'; +import 'package:camera_android_camerax/src/camera2_camera_info.dart'; import 'package:camera_android_camerax/src/camera_control.dart'; import 'package:camera_android_camerax/src/camera_info.dart'; +import 'package:camera_android_camerax/src/camera_metadata.dart'; import 'package:camera_android_camerax/src/camera_selector.dart'; import 'package:camera_android_camerax/src/camera_state.dart'; import 'package:camera_android_camerax/src/camera_state_error.dart'; @@ -59,10 +61,12 @@ import 'test_camerax_library.g.dart'; @GenerateNiceMocks(>[ MockSpec(), MockSpec(), + MockSpec(), MockSpec(), MockSpec(), MockSpec(), MockSpec(), + MockSpec(), MockSpec(), MockSpec(), MockSpec(), @@ -82,10 +86,9 @@ import 'test_camerax_library.g.dart'; MockSpec(), MockSpec(), MockSpec(), - MockSpec(), - MockSpec(), MockSpec(), MockSpec(), + MockSpec(), MockSpec(), ]) @GenerateMocks([], customMocks: >[ @@ -384,6 +387,8 @@ void main() { createResolutionFilterWithOnePreferredSize: (_) => MockResolutionFilter(), ); + camera.processCameraProvider = mockProcessCameraProvider; + when(mockPreview.setSurfaceProvider()) .thenAnswer((_) async => testSurfaceTextureId); when(mockProcessCameraProvider.bindToLifecycle(mockBackCameraSelector, @@ -392,7 +397,6 @@ void main() { when(mockCamera.getCameraInfo()).thenAnswer((_) async => mockCameraInfo); when(mockCameraInfo.getCameraState()) .thenAnswer((_) async => mockLiveCameraState); - camera.processCameraProvider = mockProcessCameraProvider; expect( await camera.createCameraWithSettings( @@ -1259,6 +1263,8 @@ void main() { final MockCameraControl mockCameraControl = MockCameraControl(); final MockLiveCameraState mockLiveCameraState = MockLiveCameraState(); final MockLiveCameraState newMockLiveCameraState = MockLiveCameraState(); + final MockCamera2CameraInfo mockCamera2CameraInfo = + MockCamera2CameraInfo(); final TestSystemServicesHostApi mockSystemServicesApi = MockTestSystemServicesHostApi(); TestSystemServicesHostApi.setup(mockSystemServicesApi); @@ -1270,6 +1276,8 @@ void main() { camera.videoCapture = MockVideoCapture(); camera.cameraSelector = MockCameraSelector(); camera.liveCameraState = mockLiveCameraState; + camera.cameraInfo = MockCameraInfo(); + camera.imageAnalysis = MockImageAnalysis(); // Ignore setting target rotation for this test; tested seprately. camera.captureOrientationLocked = true; @@ -1277,7 +1285,9 @@ void main() { // Tell plugin to create detached Observer when camera info updated. camera.proxy = CameraXProxy( createCameraStateObserver: (void Function(Object) onChanged) => - Observer.detached(onChanged: onChanged)); + Observer.detached(onChanged: onChanged), + getCamera2CameraInfo: (CameraInfo cameraInfo) => + Future.value(mockCamera2CameraInfo)); const int cameraId = 17; const String outputPath = '/temp/MOV123.temp'; @@ -1299,6 +1309,8 @@ void main() { .thenAnswer((_) async => mockCameraControl); when(mockCameraInfo.getCameraState()) .thenAnswer((_) async => newMockLiveCameraState); + when(mockCamera2CameraInfo.getSupportedHardwareLevel()).thenAnswer( + (_) async => CameraMetadata.infoSupportedHardwareLevelLimited); await camera.startVideoCapturing(const VideoCaptureOptions(cameraId)); @@ -1332,6 +1344,8 @@ void main() { final MockRecording mockRecording = MockRecording(); final MockCamera mockCamera = MockCamera(); final MockCameraInfo mockCameraInfo = MockCameraInfo(); + final MockCamera2CameraInfo mockCamera2CameraInfo = + MockCamera2CameraInfo(); final TestSystemServicesHostApi mockSystemServicesApi = MockTestSystemServicesHostApi(); TestSystemServicesHostApi.setup(mockSystemServicesApi); @@ -1341,6 +1355,8 @@ void main() { camera.recorder = MockRecorder(); camera.videoCapture = MockVideoCapture(); camera.cameraSelector = MockCameraSelector(); + camera.cameraInfo = MockCameraInfo(); + camera.imageAnalysis = MockImageAnalysis(); // Ignore setting target rotation for this test; tested seprately. camera.captureOrientationLocked = true; @@ -1348,7 +1364,9 @@ void main() { // Tell plugin to create detached Observer when camera info updated. camera.proxy = CameraXProxy( createCameraStateObserver: (void Function(Object) onChanged) => - Observer.detached(onChanged: onChanged)); + Observer.detached(onChanged: onChanged), + getCamera2CameraInfo: (CameraInfo cameraInfo) => + Future.value(mockCamera2CameraInfo)); const int cameraId = 17; const String outputPath = '/temp/MOV123.temp'; @@ -1368,6 +1386,8 @@ void main() { .thenAnswer((_) => Future.value(mockCameraInfo)); when(mockCameraInfo.getCameraState()) .thenAnswer((_) async => MockLiveCameraState()); + when(mockCamera2CameraInfo.getSupportedHardwareLevel()).thenAnswer( + (_) async => CameraMetadata.infoSupportedHardwareLevelLimited); await camera.startVideoCapturing(const VideoCaptureOptions(cameraId)); @@ -1392,21 +1412,27 @@ void main() { () async { // Set up mocks and constants. final AndroidCameraCameraX camera = AndroidCameraCameraX(); - - // Set directly for test versus calling createCamera. final MockProcessCameraProvider mockProcessCameraProvider = MockProcessCameraProvider(); + final Recorder mockRecorder = MockRecorder(); + final MockPendingRecording mockPendingRecording = MockPendingRecording(); + final MockCameraInfo initialCameraInfo = MockCameraInfo(); + final MockCamera2CameraInfo mockCamera2CameraInfo = + MockCamera2CameraInfo(); + final TestSystemServicesHostApi mockSystemServicesApi = + MockTestSystemServicesHostApi(); + TestSystemServicesHostApi.setup(mockSystemServicesApi); + + // Set directly for test versus calling createCamera. + camera.processCameraProvider = mockProcessCameraProvider; camera.cameraSelector = MockCameraSelector(); camera.videoCapture = MockVideoCapture(); camera.imageAnalysis = MockImageAnalysis(); camera.camera = MockCamera(); - final Recorder mockRecorder = MockRecorder(); camera.recorder = mockRecorder; - final MockPendingRecording mockPendingRecording = MockPendingRecording(); - final TestSystemServicesHostApi mockSystemServicesApi = - MockTestSystemServicesHostApi(); - TestSystemServicesHostApi.setup(mockSystemServicesApi); + camera.cameraInfo = initialCameraInfo; + camera.imageCapture = MockImageCapture(); // Ignore setting target rotation for this test; tested seprately. camera.captureOrientationLocked = true; @@ -1415,7 +1441,11 @@ void main() { camera.proxy = CameraXProxy( createAnalyzer: (Future Function(ImageProxy imageProxy) analyze) => - Analyzer.detached(analyze: analyze)); + Analyzer.detached(analyze: analyze), + getCamera2CameraInfo: (CameraInfo cameraInfo) async => + cameraInfo == initialCameraInfo + ? mockCamera2CameraInfo + : MockCamera2CameraInfo()); const int cameraId = 17; const String outputPath = '/temp/MOV123.temp'; @@ -1429,6 +1459,8 @@ void main() { // Mock method calls. when(camera.processCameraProvider!.isBound(camera.videoCapture!)) .thenAnswer((_) async => true); + when(camera.processCameraProvider!.isBound(camera.imageAnalysis!)) + .thenAnswer((_) async => true); when(mockSystemServicesApi.getTempFilePath(camera.videoPrefix, '.temp')) .thenReturn(outputPath); when(camera.recorder!.prepareRecording(outputPath)) @@ -1437,6 +1469,8 @@ void main() { .thenAnswer((_) => Future.value(camera.camera)); when(camera.camera!.getCameraInfo()) .thenAnswer((_) => Future.value(MockCameraInfo())); + when(mockCamera2CameraInfo.getSupportedHardwareLevel()) + .thenAnswer((_) async => CameraMetadata.infoSupportedHardwareLevel3); await camera.startVideoCapturing(videoCaptureOptions); @@ -1455,10 +1489,13 @@ void main() { final MockPendingRecording mockPendingRecording = MockPendingRecording(); final MockRecording mockRecording = MockRecording(); final MockVideoCapture mockVideoCapture = MockVideoCapture(); + final MockCameraInfo initialCameraInfo = MockCameraInfo(); + final MockCamera2CameraInfo mockCamera2CameraInfo = + MockCamera2CameraInfo(); final TestSystemServicesHostApi mockSystemServicesApi = MockTestSystemServicesHostApi(); TestSystemServicesHostApi.setup(mockSystemServicesApi); - const int defaultTargetRotation = Surface.ROTATION_270; + const int defaultTargetRotation = Surface.rotation270; // Set directly for test versus calling createCamera. camera.processCameraProvider = MockProcessCameraProvider(); @@ -1466,11 +1503,17 @@ void main() { camera.recorder = MockRecorder(); camera.videoCapture = mockVideoCapture; camera.cameraSelector = MockCameraSelector(); + camera.imageAnalysis = MockImageAnalysis(); + camera.cameraInfo = initialCameraInfo; - // Tell plugin to mock call to get current video orientation. + // Tell plugin to mock call to get current video orientation and mock Camera2CameraInfo retrieval. camera.proxy = CameraXProxy( getDefaultDisplayRotation: () => - Future.value(defaultTargetRotation)); + Future.value(defaultTargetRotation), + getCamera2CameraInfo: (CameraInfo cameraInfo) async => + cameraInfo == initialCameraInfo + ? mockCamera2CameraInfo + : MockCamera2CameraInfo()); const int cameraId = 87; const String outputPath = '/temp/MOV123.temp'; @@ -1483,6 +1526,8 @@ void main() { when(mockPendingRecording.start()).thenAnswer((_) async => mockRecording); when(camera.processCameraProvider!.isBound(camera.videoCapture!)) .thenAnswer((_) async => true); + when(camera.processCameraProvider!.isBound(camera.imageAnalysis!)) + .thenAnswer((_) async => false); // Orientation is unlocked and plugin does not need to set default target // rotation manually. @@ -1578,67 +1623,114 @@ void main() { await camera.stopVideoRecording(0); }, throwsA(isA())); }); - }); - test( - 'stopVideoRecording throws a camera exception if ' - 'videoOutputPath is null, and sets recording to null', () async { - final AndroidCameraCameraX camera = AndroidCameraCameraX(); - final MockRecording mockRecording = MockRecording(); - final MockVideoCapture mockVideoCapture = MockVideoCapture(); + test( + 'stopVideoRecording throws a camera exception if ' + 'videoOutputPath is null, and sets recording to null', () async { + final AndroidCameraCameraX camera = AndroidCameraCameraX(); + final MockRecording mockRecording = MockRecording(); + final MockVideoCapture mockVideoCapture = MockVideoCapture(); - // Set directly for test versus calling startVideoCapturing. - camera.processCameraProvider = MockProcessCameraProvider(); - camera.recording = mockRecording; - camera.videoOutputPath = null; - camera.videoCapture = mockVideoCapture; + // Set directly for test versus calling startVideoCapturing. + camera.processCameraProvider = MockProcessCameraProvider(); + camera.recording = mockRecording; + camera.videoOutputPath = null; + camera.videoCapture = mockVideoCapture; - // Tell plugin that videoCapture use case was bound to start recording. - when(camera.processCameraProvider!.isBound(mockVideoCapture)) - .thenAnswer((_) async => true); + // Tell plugin that videoCapture use case was bound to start recording. + when(camera.processCameraProvider!.isBound(mockVideoCapture)) + .thenAnswer((_) async => true); - await expectLater(() async { - await camera.stopVideoRecording(0); - }, throwsA(isA())); - expect(camera.recording, null); - }); + await expectLater(() async { + await camera.stopVideoRecording(0); + }, throwsA(isA())); + expect(camera.recording, null); + }); - test( - 'calling stopVideoRecording twice stops the recording ' - 'and then throws a CameraException', () async { - final AndroidCameraCameraX camera = AndroidCameraCameraX(); - final MockRecording recording = MockRecording(); - final MockProcessCameraProvider processCameraProvider = - MockProcessCameraProvider(); - final MockVideoCapture videoCapture = MockVideoCapture(); - const String videoOutputPath = '/test/output/path'; + test( + 'calling stopVideoRecording twice stops the recording ' + 'and then throws a CameraException', () async { + final AndroidCameraCameraX camera = AndroidCameraCameraX(); + final MockRecording recording = MockRecording(); + final MockProcessCameraProvider processCameraProvider = + MockProcessCameraProvider(); + final MockVideoCapture videoCapture = MockVideoCapture(); + const String videoOutputPath = '/test/output/path'; - // Set directly for test versus calling createCamera and startVideoCapturing. - camera.processCameraProvider = processCameraProvider; - camera.recording = recording; - camera.videoCapture = videoCapture; - camera.videoOutputPath = videoOutputPath; + // Set directly for test versus calling createCamera and startVideoCapturing. + camera.processCameraProvider = processCameraProvider; + camera.recording = recording; + camera.videoCapture = videoCapture; + camera.videoOutputPath = videoOutputPath; - final XFile file = await camera.stopVideoRecording(0); - expect(file.path, videoOutputPath); + final XFile file = await camera.stopVideoRecording(0); + expect(file.path, videoOutputPath); - await expectLater(() async { - await camera.stopVideoRecording(0); - }, throwsA(isA())); + await expectLater(() async { + await camera.stopVideoRecording(0); + }, throwsA(isA())); + }); + + test( + 'VideoCapture use case is unbound from lifecycle when video recording stops', + () async { + final AndroidCameraCameraX camera = AndroidCameraCameraX(); + final MockRecording recording = MockRecording(); + final MockProcessCameraProvider processCameraProvider = + MockProcessCameraProvider(); + final MockVideoCapture videoCapture = MockVideoCapture(); + const String videoOutputPath = '/test/output/path'; + + // Set directly for test versus calling createCamera and startVideoCapturing. + camera.processCameraProvider = processCameraProvider; + camera.recording = recording; + camera.videoCapture = videoCapture; + camera.videoOutputPath = videoOutputPath; + + // Tell plugin that videoCapture use case was bound to start recording. + when(camera.processCameraProvider!.isBound(videoCapture)) + .thenAnswer((_) async => true); + + await camera.stopVideoRecording(90); + verify(processCameraProvider.unbind([videoCapture])); + + // Verify that recording stops. + verify(recording.close()); + verifyNoMoreInteractions(recording); + }); }); test( - 'takePicture binds and unbinds ImageCapture to lifecycle and makes call to take a picture', + 'takePicture binds ImageCapture to lifecycle and makes call to take a picture', () async { final AndroidCameraCameraX camera = AndroidCameraCameraX(); + final MockProcessCameraProvider mockProcessCameraProvider = + MockProcessCameraProvider(); + final MockCamera mockCamera = MockCamera(); + final MockCameraInfo mockCameraInfo = MockCameraInfo(); const String testPicturePath = 'test/absolute/path/to/picture'; // Set directly for test versus calling createCamera. camera.imageCapture = MockImageCapture(); + camera.processCameraProvider = mockProcessCameraProvider; + camera.cameraSelector = MockCameraSelector(); // Ignore setting target rotation for this test; tested seprately. camera.captureOrientationLocked = true; + // Tell plugin to create detached camera state observers. + camera.proxy = CameraXProxy( + createCameraStateObserver: (void Function(Object) onChanged) => + Observer.detached(onChanged: onChanged)); + + when(mockProcessCameraProvider.isBound(camera.imageCapture)) + .thenAnswer((_) async => false); + when(mockProcessCameraProvider.bindToLifecycle( + camera.cameraSelector, [camera.imageCapture!])) + .thenAnswer((_) async => mockCamera); + when(mockCamera.getCameraInfo()).thenAnswer((_) async => mockCameraInfo); + when(mockCameraInfo.getCameraState()) + .thenAnswer((_) async => MockLiveCameraState()); when(camera.imageCapture!.takePicture()) .thenAnswer((_) async => testPicturePath); @@ -1652,17 +1744,23 @@ void main() { () async { final AndroidCameraCameraX camera = AndroidCameraCameraX(); final MockImageCapture mockImageCapture = MockImageCapture(); + final MockProcessCameraProvider mockProcessCameraProvider = + MockProcessCameraProvider(); + const int cameraId = 3; - const int defaultTargetRotation = Surface.ROTATION_180; + const int defaultTargetRotation = Surface.rotation180; // Set directly for test versus calling createCamera. camera.imageCapture = mockImageCapture; + camera.processCameraProvider = mockProcessCameraProvider; // Tell plugin to mock call to get current photo orientation. camera.proxy = CameraXProxy( getDefaultDisplayRotation: () => Future.value(defaultTargetRotation)); + when(mockProcessCameraProvider.isBound(camera.imageCapture)) + .thenAnswer((_) async => true); when(camera.imageCapture!.takePicture()) .thenAnswer((_) async => 'test/absolute/path/to/picture'); @@ -1695,15 +1793,21 @@ void main() { test('takePicture turns non-torch flash mode off when torch mode enabled', () async { final AndroidCameraCameraX camera = AndroidCameraCameraX(); + final MockProcessCameraProvider mockProcessCameraProvider = + MockProcessCameraProvider(); const int cameraId = 77; // Set directly for test versus calling createCamera. camera.imageCapture = MockImageCapture(); camera.cameraControl = MockCameraControl(); + camera.processCameraProvider = mockProcessCameraProvider; // Ignore setting target rotation for this test; tested seprately. camera.captureOrientationLocked = true; + when(mockProcessCameraProvider.isBound(camera.imageCapture)) + .thenAnswer((_) async => true); + await camera.setFlashMode(cameraId, FlashMode.torch); await camera.takePicture(cameraId); verify(camera.imageCapture!.setFlashMode(ImageCapture.flashModeOff)); @@ -1715,6 +1819,8 @@ void main() { final AndroidCameraCameraX camera = AndroidCameraCameraX(); const int cameraId = 22; final MockCameraControl mockCameraControl = MockCameraControl(); + final MockProcessCameraProvider mockProcessCameraProvider = + MockProcessCameraProvider(); // Set directly for test versus calling createCamera. camera.imageCapture = MockImageCapture(); @@ -1722,6 +1828,10 @@ void main() { // Ignore setting target rotation for this test; tested seprately. camera.captureOrientationLocked = true; + camera.processCameraProvider = mockProcessCameraProvider; + + when(mockProcessCameraProvider.isBound(camera.imageCapture)) + .thenAnswer((_) async => true); for (final FlashMode flashMode in FlashMode.values) { await camera.setFlashMode(cameraId, flashMode); @@ -1939,6 +2049,8 @@ void main() { when(mockProcessCameraProvider.bindToLifecycle(any, any)) .thenAnswer((_) => Future.value(mockCamera)); + when(mockProcessCameraProvider.isBound(camera.imageAnalysis)) + .thenAnswer((_) async => true); when(mockCamera.getCameraInfo()) .thenAnswer((_) => Future.value(mockCameraInfo)); when(mockCameraInfo.getCameraState()) @@ -1962,8 +2074,6 @@ void main() { final AndroidCameraCameraX camera = AndroidCameraCameraX(); final MockProcessCameraProvider mockProcessCameraProvider = MockProcessCameraProvider(); - final MockCamera mockCamera = MockCamera(); - final MockCameraInfo mockCameraInfo = MockCameraInfo(); const int cameraId = 22; // Tell plugin to create detached Analyzer for testing. @@ -1980,12 +2090,8 @@ void main() { // Ignore setting target rotation for this test; tested seprately. camera.captureOrientationLocked = true; - when(mockProcessCameraProvider.bindToLifecycle(any, any)) - .thenAnswer((_) => Future.value(mockCamera)); - when(mockCamera.getCameraInfo()) - .thenAnswer((_) => Future.value(mockCameraInfo)); - when(mockCameraInfo.getCameraState()) - .thenAnswer((_) async => MockLiveCameraState()); + when(mockProcessCameraProvider.isBound(camera.imageAnalysis)) + .thenAnswer((_) async => true); final CameraImageData mockCameraImageData = MockCameraImageData(); final Stream imageStream = @@ -2034,7 +2140,9 @@ void main() { camera.proxy = CameraXProxy( createAnalyzer: (Future Function(ImageProxy imageProxy) analyze) => - Analyzer.detached(analyze: analyze)); + Analyzer.detached(analyze: analyze), + createCameraStateObserver: (void Function(Object) onChanged) => + Observer.detached(onChanged: onChanged)); // Set directly for test versus calling createCamera. camera.processCameraProvider = mockProcessCameraProvider; @@ -2045,7 +2153,7 @@ void main() { camera.captureOrientationLocked = true; when(mockProcessCameraProvider.isBound(mockImageAnalysis)) - .thenAnswer((_) async => Future.value(false)); + .thenAnswer((_) async => false); when(mockProcessCameraProvider .bindToLifecycle(mockCameraSelector, [mockImageAnalysis])) .thenAnswer((_) async => mockCamera); @@ -2053,7 +2161,7 @@ void main() { when(mockCameraInfo.getCameraState()) .thenAnswer((_) async => MockLiveCameraState()); when(mockImageProxy.getPlanes()) - .thenAnswer((_) => Future>.value(mockPlanes)); + .thenAnswer((_) async => Future>.value(mockPlanes)); when(mockPlane.buffer).thenReturn(buffer); when(mockPlane.rowStride).thenReturn(rowStride); when(mockPlane.pixelStride).thenReturn(pixelStride); @@ -2071,6 +2179,7 @@ void main() { }); // Test ImageAnalysis use case is bound to ProcessCameraProvider. + await untilCalled(mockImageAnalysis.setAnalyzer(any)); final Analyzer capturedAnalyzer = verify(mockImageAnalysis.setAnalyzer(captureAny)).captured.single as Analyzer; @@ -2097,9 +2206,12 @@ void main() { final AndroidCameraCameraX camera = AndroidCameraCameraX(); const int cameraId = 32; final MockImageAnalysis mockImageAnalysis = MockImageAnalysis(); + final MockProcessCameraProvider mockProcessCameraProvider = + MockProcessCameraProvider(); // Set directly for test versus calling createCamera. camera.imageAnalysis = mockImageAnalysis; + camera.processCameraProvider = mockProcessCameraProvider; // Ignore setting target rotation for this test; tested seprately. camera.captureOrientationLocked = true; @@ -2107,6 +2219,9 @@ void main() { // Tell plugin to create a detached analyzer for testing purposes. camera.proxy = CameraXProxy(createAnalyzer: (_) => MockAnalyzer()); + when(mockProcessCameraProvider.isBound(mockImageAnalysis)) + .thenAnswer((_) async => true); + final StreamSubscription imageStreamSubscription = camera .onStreamedFrameAvailable(cameraId) .listen((CameraImageData data) {}); @@ -2121,11 +2236,14 @@ void main() { () async { final AndroidCameraCameraX camera = AndroidCameraCameraX(); const int cameraId = 35; - const int defaultTargetRotation = Surface.ROTATION_90; + const int defaultTargetRotation = Surface.rotation90; final MockImageAnalysis mockImageAnalysis = MockImageAnalysis(); + final MockProcessCameraProvider mockProcessCameraProvider = + MockProcessCameraProvider(); // Set directly for test versus calling createCamera. camera.imageAnalysis = mockImageAnalysis; + camera.processCameraProvider = mockProcessCameraProvider; // Tell plugin to create a detached analyzer for testing purposes and mock // call to get current photo orientation. @@ -2134,6 +2252,9 @@ void main() { getDefaultDisplayRotation: () => Future.value(defaultTargetRotation)); + when(mockProcessCameraProvider.isBound(mockImageAnalysis)) + .thenAnswer((_) async => true); + // Orientation is unlocked and plugin does not need to set default target // rotation manually. StreamSubscription imageStreamSubscription = camera @@ -2195,13 +2316,13 @@ void main() { int? expectedTargetRotation; switch (orientation) { case DeviceOrientation.portraitUp: - expectedTargetRotation = Surface.ROTATION_0; + expectedTargetRotation = Surface.rotation0; case DeviceOrientation.landscapeLeft: - expectedTargetRotation = Surface.ROTATION_90; + expectedTargetRotation = Surface.rotation90; case DeviceOrientation.portraitDown: - expectedTargetRotation = Surface.ROTATION_180; + expectedTargetRotation = Surface.rotation180; case DeviceOrientation.landscapeRight: - expectedTargetRotation = Surface.ROTATION_270; + expectedTargetRotation = Surface.rotation270; } await camera.lockCaptureOrientation(cameraId, orientation); @@ -3496,4 +3617,427 @@ void main() { verificationResult.captured.single as FocusMeteringAction; expect(capturedAction.disableAutoCancel, isFalse); }); + + test( + 'onStreamedFrameAvailable binds ImageAnalysis use case when not already bound', + () async { + final AndroidCameraCameraX camera = AndroidCameraCameraX(); + const int cameraId = 22; + final MockImageAnalysis mockImageAnalysis = MockImageAnalysis(); + final MockProcessCameraProvider mockProcessCameraProvider = + MockProcessCameraProvider(); + final MockCamera mockCamera = MockCamera(); + final MockCameraInfo mockCameraInfo = MockCameraInfo(); + + // Set directly for test versus calling createCamera. + camera.imageAnalysis = mockImageAnalysis; + camera.processCameraProvider = mockProcessCameraProvider; + camera.cameraSelector = MockCameraSelector(); + + // Ignore setting target rotation for this test; tested seprately. + camera.captureOrientationLocked = true; + + // Tell plugin to create a detached analyzer for testing purposes. + camera.proxy = CameraXProxy( + createAnalyzer: (_) => MockAnalyzer(), + createCameraStateObserver: (_) => MockObserver(), + ); + + when(mockProcessCameraProvider.isBound(mockImageAnalysis)) + .thenAnswer((_) async => false); + when(mockProcessCameraProvider.bindToLifecycle( + any, [mockImageAnalysis])).thenAnswer((_) async => mockCamera); + when(mockCamera.getCameraInfo()).thenAnswer((_) async => mockCameraInfo); + when(mockCameraInfo.getCameraState()) + .thenAnswer((_) async => MockLiveCameraState()); + + final StreamSubscription imageStreamSubscription = camera + .onStreamedFrameAvailable(cameraId) + .listen((CameraImageData data) {}); + + await untilCalled(mockImageAnalysis.setAnalyzer(any)); + verify(mockProcessCameraProvider + .bindToLifecycle(camera.cameraSelector, [mockImageAnalysis])); + + await imageStreamSubscription.cancel(); + }); + + test( + 'startVideoCapturing unbinds ImageAnalysis use case when camera device is not at least level 3, no image streaming callback is specified, and preview is not paused', + () async { + // Set up mocks and constants. + final AndroidCameraCameraX camera = AndroidCameraCameraX(); + final MockPendingRecording mockPendingRecording = MockPendingRecording(); + final MockRecording mockRecording = MockRecording(); + final MockCamera mockCamera = MockCamera(); + final MockCameraInfo mockCameraInfo = MockCameraInfo(); + final MockCamera2CameraInfo mockCamera2CameraInfo = MockCamera2CameraInfo(); + final TestSystemServicesHostApi mockSystemServicesApi = + MockTestSystemServicesHostApi(); + TestSystemServicesHostApi.setup(mockSystemServicesApi); + + // Set directly for test versus calling createCamera. + camera.processCameraProvider = MockProcessCameraProvider(); + camera.recorder = MockRecorder(); + camera.videoCapture = MockVideoCapture(); + camera.cameraSelector = MockCameraSelector(); + camera.cameraInfo = MockCameraInfo(); + camera.imageAnalysis = MockImageAnalysis(); + + // Ignore setting target rotation for this test; tested seprately. + camera.captureOrientationLocked = true; + + // Tell plugin to create detached Observer when camera info updated. + camera.proxy = CameraXProxy( + createCameraStateObserver: (void Function(Object) onChanged) => + Observer.detached(onChanged: onChanged), + getCamera2CameraInfo: (CameraInfo cameraInfo) => + Future.value(mockCamera2CameraInfo)); + + const int cameraId = 7; + const String outputPath = '/temp/MOV123.temp'; + + // Mock method calls. + when(mockSystemServicesApi.getTempFilePath(camera.videoPrefix, '.temp')) + .thenReturn(outputPath); + when(camera.recorder!.prepareRecording(outputPath)) + .thenAnswer((_) async => mockPendingRecording); + when(mockPendingRecording.start()).thenAnswer((_) async => mockRecording); + when(camera.processCameraProvider!.isBound(camera.videoCapture!)) + .thenAnswer((_) async => false); + when(camera.processCameraProvider!.isBound(camera.imageAnalysis!)) + .thenAnswer((_) async => true); + when(camera.processCameraProvider!.bindToLifecycle( + camera.cameraSelector!, [camera.videoCapture!])) + .thenAnswer((_) async => mockCamera); + when(mockCamera.getCameraInfo()) + .thenAnswer((_) => Future.value(mockCameraInfo)); + when(mockCameraInfo.getCameraState()) + .thenAnswer((_) async => MockLiveCameraState()); + when(mockCamera2CameraInfo.getSupportedHardwareLevel()) + .thenAnswer((_) async => CameraMetadata.infoSupportedHardwareLevelFull); + + await camera.startVideoCapturing(const VideoCaptureOptions(cameraId)); + + verify( + camera.processCameraProvider!.unbind([camera.imageAnalysis!])); + }); + + test( + 'startVideoCapturing unbinds ImageAnalysis use case when image streaming callback not specified, camera device is level 3, and preview is not paused', + () async { + // Set up mocks and constants. + final AndroidCameraCameraX camera = AndroidCameraCameraX(); + final MockPendingRecording mockPendingRecording = MockPendingRecording(); + final MockRecording mockRecording = MockRecording(); + final MockCamera mockCamera = MockCamera(); + final MockCameraInfo mockCameraInfo = MockCameraInfo(); + final MockCamera2CameraInfo mockCamera2CameraInfo = MockCamera2CameraInfo(); + final TestSystemServicesHostApi mockSystemServicesApi = + MockTestSystemServicesHostApi(); + TestSystemServicesHostApi.setup(mockSystemServicesApi); + + // Set directly for test versus calling createCamera. + camera.processCameraProvider = MockProcessCameraProvider(); + camera.recorder = MockRecorder(); + camera.videoCapture = MockVideoCapture(); + camera.cameraSelector = MockCameraSelector(); + camera.cameraInfo = MockCameraInfo(); + camera.imageAnalysis = MockImageAnalysis(); + + // Ignore setting target rotation for this test; tested seprately. + camera.captureOrientationLocked = true; + + // Tell plugin to create detached Observer when camera info updated. + camera.proxy = CameraXProxy( + createCameraStateObserver: (void Function(Object) onChanged) => + Observer.detached(onChanged: onChanged), + getCamera2CameraInfo: (CameraInfo cameraInfo) => + Future.value(mockCamera2CameraInfo)); + + const int cameraId = 77; + const String outputPath = '/temp/MOV123.temp'; + + // Mock method calls. + when(mockSystemServicesApi.getTempFilePath(camera.videoPrefix, '.temp')) + .thenReturn(outputPath); + when(camera.recorder!.prepareRecording(outputPath)) + .thenAnswer((_) async => mockPendingRecording); + when(mockPendingRecording.start()).thenAnswer((_) async => mockRecording); + when(camera.processCameraProvider!.isBound(camera.videoCapture!)) + .thenAnswer((_) async => false); + when(camera.processCameraProvider!.isBound(camera.imageAnalysis!)) + .thenAnswer((_) async => true); + when(camera.processCameraProvider!.bindToLifecycle( + camera.cameraSelector!, [camera.videoCapture!])) + .thenAnswer((_) async => mockCamera); + when(mockCamera.getCameraInfo()) + .thenAnswer((_) => Future.value(mockCameraInfo)); + when(mockCameraInfo.getCameraState()) + .thenAnswer((_) async => MockLiveCameraState()); + when(mockCamera2CameraInfo.getSupportedHardwareLevel()) + .thenAnswer((_) async => CameraMetadata.infoSupportedHardwareLevel3); + + await camera.startVideoCapturing(const VideoCaptureOptions(cameraId)); + + verify( + camera.processCameraProvider!.unbind([camera.imageAnalysis!])); + }); + + test( + 'startVideoCapturing unbinds ImageAnalysis use case when image streaming callback is specified, camera device is not at least level 3, and preview is not paused', + () async { + // Set up mocks and constants. + final AndroidCameraCameraX camera = AndroidCameraCameraX(); + final MockPendingRecording mockPendingRecording = MockPendingRecording(); + final MockRecording mockRecording = MockRecording(); + final MockCamera mockCamera = MockCamera(); + final MockCameraInfo mockCameraInfo = MockCameraInfo(); + final MockCamera2CameraInfo mockCamera2CameraInfo = MockCamera2CameraInfo(); + final TestSystemServicesHostApi mockSystemServicesApi = + MockTestSystemServicesHostApi(); + TestSystemServicesHostApi.setup(mockSystemServicesApi); + + // Set directly for test versus calling createCamera. + camera.processCameraProvider = MockProcessCameraProvider(); + camera.recorder = MockRecorder(); + camera.videoCapture = MockVideoCapture(); + camera.cameraSelector = MockCameraSelector(); + camera.cameraInfo = MockCameraInfo(); + camera.imageAnalysis = MockImageAnalysis(); + + // Ignore setting target rotation for this test; tested seprately. + camera.captureOrientationLocked = true; + + // Tell plugin to create detached Observer when camera info updated. + camera.proxy = CameraXProxy( + createCameraStateObserver: (void Function(Object) onChanged) => + Observer.detached(onChanged: onChanged), + getCamera2CameraInfo: (CameraInfo cameraInfo) => + Future.value(mockCamera2CameraInfo)); + + const int cameraId = 87; + const String outputPath = '/temp/MOV123.temp'; + + // Mock method calls. + when(mockSystemServicesApi.getTempFilePath(camera.videoPrefix, '.temp')) + .thenReturn(outputPath); + when(camera.recorder!.prepareRecording(outputPath)) + .thenAnswer((_) async => mockPendingRecording); + when(mockPendingRecording.start()).thenAnswer((_) async => mockRecording); + when(camera.processCameraProvider!.isBound(camera.videoCapture!)) + .thenAnswer((_) async => false); + when(camera.processCameraProvider!.isBound(camera.imageAnalysis!)) + .thenAnswer((_) async => true); + when(camera.processCameraProvider!.bindToLifecycle( + camera.cameraSelector!, [camera.videoCapture!])) + .thenAnswer((_) async => mockCamera); + when(mockCamera.getCameraInfo()) + .thenAnswer((_) => Future.value(mockCameraInfo)); + when(mockCameraInfo.getCameraState()) + .thenAnswer((_) async => MockLiveCameraState()); + when(mockCamera2CameraInfo.getSupportedHardwareLevel()).thenAnswer( + (_) async => CameraMetadata.infoSupportedHardwareLevelExternal); + + await camera.startVideoCapturing(VideoCaptureOptions(cameraId, + streamCallback: (CameraImageData image) {})); + verify( + camera.processCameraProvider!.unbind([camera.imageAnalysis!])); + }); + + test( + 'startVideoCapturing unbinds ImageCapture use case when image streaming callback is specified, camera device is at least level 3, and preview is not paused', + () async { + // Set up mocks and constants. + final AndroidCameraCameraX camera = AndroidCameraCameraX(); + final MockPendingRecording mockPendingRecording = MockPendingRecording(); + final MockRecording mockRecording = MockRecording(); + final MockCamera mockCamera = MockCamera(); + final MockCameraInfo mockCameraInfo = MockCameraInfo(); + final MockCamera2CameraInfo mockCamera2CameraInfo = MockCamera2CameraInfo(); + final TestSystemServicesHostApi mockSystemServicesApi = + MockTestSystemServicesHostApi(); + TestSystemServicesHostApi.setup(mockSystemServicesApi); + + // Set directly for test versus calling createCamera. + camera.processCameraProvider = MockProcessCameraProvider(); + camera.recorder = MockRecorder(); + camera.videoCapture = MockVideoCapture(); + camera.cameraSelector = MockCameraSelector(); + camera.cameraInfo = MockCameraInfo(); + camera.imageAnalysis = MockImageAnalysis(); + camera.imageCapture = MockImageCapture(); + + // Ignore setting target rotation for this test; tested seprately. + camera.captureOrientationLocked = true; + + // Tell plugin to create detached Observer when camera info updated. + camera.proxy = CameraXProxy( + createAnalyzer: + (Future Function(ImageProxy imageProxy) analyze) => + Analyzer.detached(analyze: analyze), + createCameraStateObserver: (void Function(Object) onChanged) => + Observer.detached(onChanged: onChanged), + getCamera2CameraInfo: (CameraInfo cameraInfo) => + Future.value(mockCamera2CameraInfo)); + + const int cameraId = 107; + const String outputPath = '/temp/MOV123.temp'; + + // Mock method calls. + when(mockSystemServicesApi.getTempFilePath(camera.videoPrefix, '.temp')) + .thenReturn(outputPath); + when(camera.recorder!.prepareRecording(outputPath)) + .thenAnswer((_) async => mockPendingRecording); + when(mockPendingRecording.start()).thenAnswer((_) async => mockRecording); + when(camera.processCameraProvider!.isBound(camera.videoCapture!)) + .thenAnswer((_) async => false); + when(camera.processCameraProvider!.isBound(camera.imageCapture!)) + .thenAnswer((_) async => true); + when(camera.processCameraProvider!.isBound(camera.imageAnalysis!)) + .thenAnswer((_) async => true); + when(camera.processCameraProvider!.bindToLifecycle( + camera.cameraSelector!, [camera.videoCapture!])) + .thenAnswer((_) async => mockCamera); + when(mockCamera.getCameraInfo()) + .thenAnswer((_) => Future.value(mockCameraInfo)); + when(mockCameraInfo.getCameraState()) + .thenAnswer((_) async => MockLiveCameraState()); + when(mockCamera2CameraInfo.getSupportedHardwareLevel()) + .thenAnswer((_) async => CameraMetadata.infoSupportedHardwareLevel3); + + await camera.startVideoCapturing(VideoCaptureOptions(cameraId, + streamCallback: (CameraImageData image) {})); + verify( + camera.processCameraProvider!.unbind([camera.imageCapture!])); + }); + + test( + 'startVideoCapturing does not unbind ImageCapture or ImageAnalysis use cases when preview is paused', + () async { + // Set up mocks and constants. + final AndroidCameraCameraX camera = AndroidCameraCameraX(); + final MockPendingRecording mockPendingRecording = MockPendingRecording(); + final MockRecording mockRecording = MockRecording(); + final MockCamera mockCamera = MockCamera(); + final MockCameraInfo mockCameraInfo = MockCameraInfo(); + final MockCamera2CameraInfo mockCamera2CameraInfo = MockCamera2CameraInfo(); + final TestSystemServicesHostApi mockSystemServicesApi = + MockTestSystemServicesHostApi(); + TestSystemServicesHostApi.setup(mockSystemServicesApi); + + // Set directly for test versus calling createCamera. + camera.processCameraProvider = MockProcessCameraProvider(); + camera.recorder = MockRecorder(); + camera.videoCapture = MockVideoCapture(); + camera.cameraSelector = MockCameraSelector(); + camera.cameraInfo = MockCameraInfo(); + camera.imageAnalysis = MockImageAnalysis(); + camera.imageCapture = MockImageCapture(); + camera.preview = MockPreview(); + + // Ignore setting target rotation for this test; tested seprately. + camera.captureOrientationLocked = true; + + // Tell plugin to create detached Observer when camera info updated. + camera.proxy = CameraXProxy( + createCameraStateObserver: (void Function(Object) onChanged) => + Observer.detached(onChanged: onChanged), + getCamera2CameraInfo: (CameraInfo cameraInfo) => + Future.value(mockCamera2CameraInfo)); + + const int cameraId = 97; + const String outputPath = '/temp/MOV123.temp'; + + // Mock method calls. + when(mockSystemServicesApi.getTempFilePath(camera.videoPrefix, '.temp')) + .thenReturn(outputPath); + when(camera.recorder!.prepareRecording(outputPath)) + .thenAnswer((_) async => mockPendingRecording); + when(mockPendingRecording.start()).thenAnswer((_) async => mockRecording); + when(camera.processCameraProvider!.isBound(camera.videoCapture!)) + .thenAnswer((_) async => false); + when(camera.processCameraProvider!.bindToLifecycle( + camera.cameraSelector!, [camera.videoCapture!])) + .thenAnswer((_) async => mockCamera); + when(mockCamera.getCameraInfo()) + .thenAnswer((_) => Future.value(mockCameraInfo)); + when(mockCameraInfo.getCameraState()) + .thenAnswer((_) async => MockLiveCameraState()); + + await camera.pausePreview(cameraId); + await camera.startVideoCapturing(const VideoCaptureOptions(cameraId)); + + verifyNever( + camera.processCameraProvider!.unbind([camera.imageCapture!])); + verifyNever( + camera.processCameraProvider!.unbind([camera.imageAnalysis!])); + }); + + test( + 'startVideoCapturing unbinds ImageCapture and ImageAnalysis use cases when running on a legacy hardware device', + () async { + // Set up mocks and constants. + final AndroidCameraCameraX camera = AndroidCameraCameraX(); + final MockPendingRecording mockPendingRecording = MockPendingRecording(); + final MockRecording mockRecording = MockRecording(); + final MockCamera mockCamera = MockCamera(); + final MockCameraInfo mockCameraInfo = MockCameraInfo(); + final MockCamera2CameraInfo mockCamera2CameraInfo = MockCamera2CameraInfo(); + final TestSystemServicesHostApi mockSystemServicesApi = + MockTestSystemServicesHostApi(); + TestSystemServicesHostApi.setup(mockSystemServicesApi); + + // Set directly for test versus calling createCamera. + camera.processCameraProvider = MockProcessCameraProvider(); + camera.recorder = MockRecorder(); + camera.videoCapture = MockVideoCapture(); + camera.cameraSelector = MockCameraSelector(); + camera.cameraInfo = MockCameraInfo(); + camera.imageAnalysis = MockImageAnalysis(); + camera.imageCapture = MockImageCapture(); + camera.preview = MockPreview(); + + // Ignore setting target rotation for this test; tested seprately. + camera.captureOrientationLocked = true; + + // Tell plugin to create detached Observer when camera info updated. + camera.proxy = CameraXProxy( + createCameraStateObserver: (void Function(Object) onChanged) => + Observer.detached(onChanged: onChanged), + getCamera2CameraInfo: (CameraInfo cameraInfo) => + Future.value(mockCamera2CameraInfo)); + + const int cameraId = 44; + const String outputPath = '/temp/MOV123.temp'; + + // Mock method calls. + when(mockSystemServicesApi.getTempFilePath(camera.videoPrefix, '.temp')) + .thenReturn(outputPath); + when(camera.recorder!.prepareRecording(outputPath)) + .thenAnswer((_) async => mockPendingRecording); + when(mockPendingRecording.start()).thenAnswer((_) async => mockRecording); + when(camera.processCameraProvider!.isBound(camera.videoCapture!)) + .thenAnswer((_) async => false); + when(camera.processCameraProvider!.isBound(camera.imageCapture!)) + .thenAnswer((_) async => true); + when(camera.processCameraProvider!.isBound(camera.imageAnalysis!)) + .thenAnswer((_) async => true); + when(camera.processCameraProvider!.bindToLifecycle( + camera.cameraSelector!, [camera.videoCapture!])) + .thenAnswer((_) async => mockCamera); + when(mockCamera.getCameraInfo()) + .thenAnswer((_) => Future.value(mockCameraInfo)); + when(mockCameraInfo.getCameraState()) + .thenAnswer((_) async => MockLiveCameraState()); + when(mockCamera2CameraInfo.getSupportedHardwareLevel()).thenAnswer( + (_) async => CameraMetadata.infoSupportedHardwareLevelLegacy); + + await camera.startVideoCapturing(const VideoCaptureOptions(cameraId)); + + verify( + camera.processCameraProvider!.unbind([camera.imageCapture!])); + verify( + camera.processCameraProvider!.unbind([camera.imageAnalysis!])); + }); } diff --git a/packages/camera/camera_android_camerax/test/android_camera_camerax_test.mocks.dart b/packages/camera/camera_android_camerax/test/android_camera_camerax_test.mocks.dart index 5d6d2051212..0bdfc06af92 100644 --- a/packages/camera/camera_android_camerax/test/android_camera_camerax_test.mocks.dart +++ b/packages/camera/camera_android_camerax/test/android_camera_camerax_test.mocks.dart @@ -4,50 +4,51 @@ // ignore_for_file: no_leading_underscores_for_library_prefixes import 'dart:async' as _i17; -import 'dart:typed_data' as _i33; -import 'dart:ui' as _i11; +import 'dart:typed_data' as _i34; +import 'dart:ui' as _i14; import 'package:camera_android_camerax/src/analyzer.dart' as _i16; import 'package:camera_android_camerax/src/aspect_ratio_strategy.dart' as _i19; -import 'package:camera_android_camerax/src/camera.dart' as _i9; +import 'package:camera_android_camerax/src/camera.dart' as _i12; import 'package:camera_android_camerax/src/camera2_camera_control.dart' as _i24; -import 'package:camera_android_camerax/src/camera_control.dart' as _i3; -import 'package:camera_android_camerax/src/camera_info.dart' as _i2; -import 'package:camera_android_camerax/src/camera_selector.dart' as _i26; +import 'package:camera_android_camerax/src/camera2_camera_info.dart' as _i26; +import 'package:camera_android_camerax/src/camera_control.dart' as _i6; +import 'package:camera_android_camerax/src/camera_info.dart' as _i5; +import 'package:camera_android_camerax/src/camera_selector.dart' as _i28; import 'package:camera_android_camerax/src/camera_state.dart' as _i20; -import 'package:camera_android_camerax/src/camerax_library.g.dart' as _i7; +import 'package:camera_android_camerax/src/camerax_library.g.dart' as _i10; import 'package:camera_android_camerax/src/capture_request_options.dart' as _i25; -import 'package:camera_android_camerax/src/exposure_state.dart' as _i5; -import 'package:camera_android_camerax/src/fallback_strategy.dart' as _i27; +import 'package:camera_android_camerax/src/exposure_state.dart' as _i8; +import 'package:camera_android_camerax/src/fallback_strategy.dart' as _i29; import 'package:camera_android_camerax/src/focus_metering_action.dart' as _i23; import 'package:camera_android_camerax/src/focus_metering_result.dart' as _i22; -import 'package:camera_android_camerax/src/image_analysis.dart' as _i28; -import 'package:camera_android_camerax/src/image_capture.dart' as _i29; +import 'package:camera_android_camerax/src/image_analysis.dart' as _i30; +import 'package:camera_android_camerax/src/image_capture.dart' as _i31; import 'package:camera_android_camerax/src/image_proxy.dart' as _i18; -import 'package:camera_android_camerax/src/live_data.dart' as _i4; -import 'package:camera_android_camerax/src/observer.dart' as _i32; -import 'package:camera_android_camerax/src/pending_recording.dart' as _i10; -import 'package:camera_android_camerax/src/plane_proxy.dart' as _i31; -import 'package:camera_android_camerax/src/preview.dart' as _i34; +import 'package:camera_android_camerax/src/live_data.dart' as _i7; +import 'package:camera_android_camerax/src/observer.dart' as _i33; +import 'package:camera_android_camerax/src/pending_recording.dart' as _i13; +import 'package:camera_android_camerax/src/plane_proxy.dart' as _i32; +import 'package:camera_android_camerax/src/preview.dart' as _i35; import 'package:camera_android_camerax/src/process_camera_provider.dart' - as _i35; -import 'package:camera_android_camerax/src/quality_selector.dart' as _i37; -import 'package:camera_android_camerax/src/recorder.dart' as _i12; -import 'package:camera_android_camerax/src/recording.dart' as _i8; -import 'package:camera_android_camerax/src/resolution_filter.dart' as _i38; -import 'package:camera_android_camerax/src/resolution_selector.dart' as _i39; -import 'package:camera_android_camerax/src/resolution_strategy.dart' as _i40; -import 'package:camera_android_camerax/src/use_case.dart' as _i36; -import 'package:camera_android_camerax/src/video_capture.dart' as _i41; + as _i36; +import 'package:camera_android_camerax/src/quality_selector.dart' as _i38; +import 'package:camera_android_camerax/src/recorder.dart' as _i15; +import 'package:camera_android_camerax/src/recording.dart' as _i11; +import 'package:camera_android_camerax/src/resolution_filter.dart' as _i39; +import 'package:camera_android_camerax/src/resolution_selector.dart' as _i40; +import 'package:camera_android_camerax/src/resolution_strategy.dart' as _i41; +import 'package:camera_android_camerax/src/use_case.dart' as _i37; +import 'package:camera_android_camerax/src/video_capture.dart' as _i43; import 'package:camera_android_camerax/src/zoom_state.dart' as _i21; import 'package:camera_platform_interface/camera_platform_interface.dart' - as _i6; -import 'package:flutter/foundation.dart' as _i15; -import 'package:flutter/services.dart' as _i14; -import 'package:flutter/widgets.dart' as _i13; + as _i9; +import 'package:flutter/foundation.dart' as _i4; +import 'package:flutter/services.dart' as _i3; +import 'package:flutter/widgets.dart' as _i2; import 'package:mockito/mockito.dart' as _i1; -import 'package:mockito/src/dummies.dart' as _i30; +import 'package:mockito/src/dummies.dart' as _i27; import 'test_camerax_library.g.dart' as _i42; @@ -64,39 +65,55 @@ import 'test_camerax_library.g.dart' as _i42; // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class -class _FakeCameraInfo_0 extends _i1.SmartFake implements _i2.CameraInfo { - _FakeCameraInfo_0( +class _FakeWidget_0 extends _i1.SmartFake implements _i2.Widget { + _FakeWidget_0( Object parent, Invocation parentInvocation, ) : super( parent, parentInvocation, ); + + @override + String toString({_i3.DiagnosticLevel? minLevel = _i3.DiagnosticLevel.info}) => + super.toString(); } -class _FakeCameraControl_1 extends _i1.SmartFake implements _i3.CameraControl { - _FakeCameraControl_1( +class _FakeInheritedWidget_1 extends _i1.SmartFake + implements _i2.InheritedWidget { + _FakeInheritedWidget_1( Object parent, Invocation parentInvocation, ) : super( parent, parentInvocation, ); + + @override + String toString({_i3.DiagnosticLevel? minLevel = _i3.DiagnosticLevel.info}) => + super.toString(); } -class _FakeLiveData_2 extends _i1.SmartFake - implements _i4.LiveData { - _FakeLiveData_2( +class _FakeDiagnosticsNode_2 extends _i1.SmartFake + implements _i4.DiagnosticsNode { + _FakeDiagnosticsNode_2( Object parent, Invocation parentInvocation, ) : super( parent, parentInvocation, ); + + @override + String toString({ + _i4.TextTreeConfiguration? parentConfiguration, + _i3.DiagnosticLevel? minLevel = _i3.DiagnosticLevel.info, + }) => + super.toString(); } -class _FakeExposureState_3 extends _i1.SmartFake implements _i5.ExposureState { - _FakeExposureState_3( +class _FakeCameraInfo_3 extends _i1.SmartFake implements _i5.CameraInfo { + _FakeCameraInfo_3( Object parent, Invocation parentInvocation, ) : super( @@ -105,9 +122,8 @@ class _FakeExposureState_3 extends _i1.SmartFake implements _i5.ExposureState { ); } -class _FakeCameraImageFormat_4 extends _i1.SmartFake - implements _i6.CameraImageFormat { - _FakeCameraImageFormat_4( +class _FakeCameraControl_4 extends _i1.SmartFake implements _i6.CameraControl { + _FakeCameraControl_4( Object parent, Invocation parentInvocation, ) : super( @@ -116,9 +132,9 @@ class _FakeCameraImageFormat_4 extends _i1.SmartFake ); } -class _FakeExposureCompensationRange_5 extends _i1.SmartFake - implements _i7.ExposureCompensationRange { - _FakeExposureCompensationRange_5( +class _FakeLiveData_5 extends _i1.SmartFake + implements _i7.LiveData { + _FakeLiveData_5( Object parent, Invocation parentInvocation, ) : super( @@ -127,8 +143,8 @@ class _FakeExposureCompensationRange_5 extends _i1.SmartFake ); } -class _FakeRecording_6 extends _i1.SmartFake implements _i8.Recording { - _FakeRecording_6( +class _FakeExposureState_6 extends _i1.SmartFake implements _i8.ExposureState { + _FakeExposureState_6( Object parent, Invocation parentInvocation, ) : super( @@ -137,9 +153,9 @@ class _FakeRecording_6 extends _i1.SmartFake implements _i8.Recording { ); } -class _FakeResolutionInfo_7 extends _i1.SmartFake - implements _i7.ResolutionInfo { - _FakeResolutionInfo_7( +class _FakeCameraImageFormat_7 extends _i1.SmartFake + implements _i9.CameraImageFormat { + _FakeCameraImageFormat_7( Object parent, Invocation parentInvocation, ) : super( @@ -148,8 +164,9 @@ class _FakeResolutionInfo_7 extends _i1.SmartFake ); } -class _FakeCamera_8 extends _i1.SmartFake implements _i9.Camera { - _FakeCamera_8( +class _FakeExposureCompensationRange_8 extends _i1.SmartFake + implements _i10.ExposureCompensationRange { + _FakeExposureCompensationRange_8( Object parent, Invocation parentInvocation, ) : super( @@ -158,9 +175,8 @@ class _FakeCamera_8 extends _i1.SmartFake implements _i9.Camera { ); } -class _FakePendingRecording_9 extends _i1.SmartFake - implements _i10.PendingRecording { - _FakePendingRecording_9( +class _FakeRecording_9 extends _i1.SmartFake implements _i11.Recording { + _FakeRecording_9( Object parent, Invocation parentInvocation, ) : super( @@ -169,8 +185,9 @@ class _FakePendingRecording_9 extends _i1.SmartFake ); } -class _FakeSize_10 extends _i1.SmartFake implements _i11.Size { - _FakeSize_10( +class _FakeResolutionInfo_10 extends _i1.SmartFake + implements _i10.ResolutionInfo { + _FakeResolutionInfo_10( Object parent, Invocation parentInvocation, ) : super( @@ -179,8 +196,8 @@ class _FakeSize_10 extends _i1.SmartFake implements _i11.Size { ); } -class _FakeRecorder_11 extends _i1.SmartFake implements _i12.Recorder { - _FakeRecorder_11( +class _FakeCamera_11 extends _i1.SmartFake implements _i12.Camera { + _FakeCamera_11( Object parent, Invocation parentInvocation, ) : super( @@ -189,53 +206,35 @@ class _FakeRecorder_11 extends _i1.SmartFake implements _i12.Recorder { ); } -class _FakeWidget_12 extends _i1.SmartFake implements _i13.Widget { - _FakeWidget_12( +class _FakePendingRecording_12 extends _i1.SmartFake + implements _i13.PendingRecording { + _FakePendingRecording_12( Object parent, Invocation parentInvocation, ) : super( parent, parentInvocation, ); - - @override - String toString( - {_i14.DiagnosticLevel? minLevel = _i14.DiagnosticLevel.info}) => - super.toString(); } -class _FakeInheritedWidget_13 extends _i1.SmartFake - implements _i13.InheritedWidget { - _FakeInheritedWidget_13( +class _FakeSize_13 extends _i1.SmartFake implements _i14.Size { + _FakeSize_13( Object parent, Invocation parentInvocation, ) : super( parent, parentInvocation, ); - - @override - String toString( - {_i14.DiagnosticLevel? minLevel = _i14.DiagnosticLevel.info}) => - super.toString(); } -class _FakeDiagnosticsNode_14 extends _i1.SmartFake - implements _i15.DiagnosticsNode { - _FakeDiagnosticsNode_14( +class _FakeRecorder_14 extends _i1.SmartFake implements _i15.Recorder { + _FakeRecorder_14( Object parent, Invocation parentInvocation, ) : super( parent, parentInvocation, ); - - @override - String toString({ - _i15.TextTreeConfiguration? parentConfiguration, - _i14.DiagnosticLevel? minLevel = _i14.DiagnosticLevel.info, - }) => - super.toString(); } /// A class which mocks [Analyzer]. @@ -274,18 +273,202 @@ class MockAspectRatioStrategy extends _i1.Mock ) as int); } +/// A class which mocks [BuildContext]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockBuildContext extends _i1.Mock implements _i2.BuildContext { + @override + _i2.Widget get widget => (super.noSuchMethod( + Invocation.getter(#widget), + returnValue: _FakeWidget_0( + this, + Invocation.getter(#widget), + ), + returnValueForMissingStub: _FakeWidget_0( + this, + Invocation.getter(#widget), + ), + ) as _i2.Widget); + + @override + bool get mounted => (super.noSuchMethod( + Invocation.getter(#mounted), + returnValue: false, + returnValueForMissingStub: false, + ) as bool); + + @override + bool get debugDoingBuild => (super.noSuchMethod( + Invocation.getter(#debugDoingBuild), + returnValue: false, + returnValueForMissingStub: false, + ) as bool); + + @override + _i2.InheritedWidget dependOnInheritedElement( + _i2.InheritedElement? ancestor, { + Object? aspect, + }) => + (super.noSuchMethod( + Invocation.method( + #dependOnInheritedElement, + [ancestor], + {#aspect: aspect}, + ), + returnValue: _FakeInheritedWidget_1( + this, + Invocation.method( + #dependOnInheritedElement, + [ancestor], + {#aspect: aspect}, + ), + ), + returnValueForMissingStub: _FakeInheritedWidget_1( + this, + Invocation.method( + #dependOnInheritedElement, + [ancestor], + {#aspect: aspect}, + ), + ), + ) as _i2.InheritedWidget); + + @override + void visitAncestorElements(_i2.ConditionalElementVisitor? visitor) => + super.noSuchMethod( + Invocation.method( + #visitAncestorElements, + [visitor], + ), + returnValueForMissingStub: null, + ); + + @override + void visitChildElements(_i2.ElementVisitor? visitor) => super.noSuchMethod( + Invocation.method( + #visitChildElements, + [visitor], + ), + returnValueForMissingStub: null, + ); + + @override + void dispatchNotification(_i2.Notification? notification) => + super.noSuchMethod( + Invocation.method( + #dispatchNotification, + [notification], + ), + returnValueForMissingStub: null, + ); + + @override + _i4.DiagnosticsNode describeElement( + String? name, { + _i4.DiagnosticsTreeStyle? style = _i4.DiagnosticsTreeStyle.errorProperty, + }) => + (super.noSuchMethod( + Invocation.method( + #describeElement, + [name], + {#style: style}, + ), + returnValue: _FakeDiagnosticsNode_2( + this, + Invocation.method( + #describeElement, + [name], + {#style: style}, + ), + ), + returnValueForMissingStub: _FakeDiagnosticsNode_2( + this, + Invocation.method( + #describeElement, + [name], + {#style: style}, + ), + ), + ) as _i4.DiagnosticsNode); + + @override + _i4.DiagnosticsNode describeWidget( + String? name, { + _i4.DiagnosticsTreeStyle? style = _i4.DiagnosticsTreeStyle.errorProperty, + }) => + (super.noSuchMethod( + Invocation.method( + #describeWidget, + [name], + {#style: style}, + ), + returnValue: _FakeDiagnosticsNode_2( + this, + Invocation.method( + #describeWidget, + [name], + {#style: style}, + ), + ), + returnValueForMissingStub: _FakeDiagnosticsNode_2( + this, + Invocation.method( + #describeWidget, + [name], + {#style: style}, + ), + ), + ) as _i4.DiagnosticsNode); + + @override + List<_i4.DiagnosticsNode> describeMissingAncestor( + {required Type? expectedAncestorType}) => + (super.noSuchMethod( + Invocation.method( + #describeMissingAncestor, + [], + {#expectedAncestorType: expectedAncestorType}, + ), + returnValue: <_i4.DiagnosticsNode>[], + returnValueForMissingStub: <_i4.DiagnosticsNode>[], + ) as List<_i4.DiagnosticsNode>); + + @override + _i4.DiagnosticsNode describeOwnershipChain(String? name) => + (super.noSuchMethod( + Invocation.method( + #describeOwnershipChain, + [name], + ), + returnValue: _FakeDiagnosticsNode_2( + this, + Invocation.method( + #describeOwnershipChain, + [name], + ), + ), + returnValueForMissingStub: _FakeDiagnosticsNode_2( + this, + Invocation.method( + #describeOwnershipChain, + [name], + ), + ), + ) as _i4.DiagnosticsNode); +} + /// A class which mocks [Camera]. /// /// See the documentation for Mockito's code generation for more information. // ignore: must_be_immutable -class MockCamera extends _i1.Mock implements _i9.Camera { +class MockCamera extends _i1.Mock implements _i12.Camera { @override - _i17.Future<_i2.CameraInfo> getCameraInfo() => (super.noSuchMethod( + _i17.Future<_i5.CameraInfo> getCameraInfo() => (super.noSuchMethod( Invocation.method( #getCameraInfo, [], ), - returnValue: _i17.Future<_i2.CameraInfo>.value(_FakeCameraInfo_0( + returnValue: _i17.Future<_i5.CameraInfo>.value(_FakeCameraInfo_3( this, Invocation.method( #getCameraInfo, @@ -293,22 +476,22 @@ class MockCamera extends _i1.Mock implements _i9.Camera { ), )), returnValueForMissingStub: - _i17.Future<_i2.CameraInfo>.value(_FakeCameraInfo_0( + _i17.Future<_i5.CameraInfo>.value(_FakeCameraInfo_3( this, Invocation.method( #getCameraInfo, [], ), )), - ) as _i17.Future<_i2.CameraInfo>); + ) as _i17.Future<_i5.CameraInfo>); @override - _i17.Future<_i3.CameraControl> getCameraControl() => (super.noSuchMethod( + _i17.Future<_i6.CameraControl> getCameraControl() => (super.noSuchMethod( Invocation.method( #getCameraControl, [], ), - returnValue: _i17.Future<_i3.CameraControl>.value(_FakeCameraControl_1( + returnValue: _i17.Future<_i6.CameraControl>.value(_FakeCameraControl_4( this, Invocation.method( #getCameraControl, @@ -316,21 +499,21 @@ class MockCamera extends _i1.Mock implements _i9.Camera { ), )), returnValueForMissingStub: - _i17.Future<_i3.CameraControl>.value(_FakeCameraControl_1( + _i17.Future<_i6.CameraControl>.value(_FakeCameraControl_4( this, Invocation.method( #getCameraControl, [], ), )), - ) as _i17.Future<_i3.CameraControl>); + ) as _i17.Future<_i6.CameraControl>); } /// A class which mocks [CameraInfo]. /// /// See the documentation for Mockito's code generation for more information. // ignore: must_be_immutable -class MockCameraInfo extends _i1.Mock implements _i2.CameraInfo { +class MockCameraInfo extends _i1.Mock implements _i5.CameraInfo { @override _i17.Future getSensorRotationDegrees() => (super.noSuchMethod( Invocation.method( @@ -342,14 +525,14 @@ class MockCameraInfo extends _i1.Mock implements _i2.CameraInfo { ) as _i17.Future); @override - _i17.Future<_i4.LiveData<_i20.CameraState>> getCameraState() => + _i17.Future<_i7.LiveData<_i20.CameraState>> getCameraState() => (super.noSuchMethod( Invocation.method( #getCameraState, [], ), - returnValue: _i17.Future<_i4.LiveData<_i20.CameraState>>.value( - _FakeLiveData_2<_i20.CameraState>( + returnValue: _i17.Future<_i7.LiveData<_i20.CameraState>>.value( + _FakeLiveData_5<_i20.CameraState>( this, Invocation.method( #getCameraState, @@ -357,23 +540,23 @@ class MockCameraInfo extends _i1.Mock implements _i2.CameraInfo { ), )), returnValueForMissingStub: - _i17.Future<_i4.LiveData<_i20.CameraState>>.value( - _FakeLiveData_2<_i20.CameraState>( + _i17.Future<_i7.LiveData<_i20.CameraState>>.value( + _FakeLiveData_5<_i20.CameraState>( this, Invocation.method( #getCameraState, [], ), )), - ) as _i17.Future<_i4.LiveData<_i20.CameraState>>); + ) as _i17.Future<_i7.LiveData<_i20.CameraState>>); @override - _i17.Future<_i5.ExposureState> getExposureState() => (super.noSuchMethod( + _i17.Future<_i8.ExposureState> getExposureState() => (super.noSuchMethod( Invocation.method( #getExposureState, [], ), - returnValue: _i17.Future<_i5.ExposureState>.value(_FakeExposureState_3( + returnValue: _i17.Future<_i8.ExposureState>.value(_FakeExposureState_6( this, Invocation.method( #getExposureState, @@ -381,24 +564,24 @@ class MockCameraInfo extends _i1.Mock implements _i2.CameraInfo { ), )), returnValueForMissingStub: - _i17.Future<_i5.ExposureState>.value(_FakeExposureState_3( + _i17.Future<_i8.ExposureState>.value(_FakeExposureState_6( this, Invocation.method( #getExposureState, [], ), )), - ) as _i17.Future<_i5.ExposureState>); + ) as _i17.Future<_i8.ExposureState>); @override - _i17.Future<_i4.LiveData<_i21.ZoomState>> getZoomState() => + _i17.Future<_i7.LiveData<_i21.ZoomState>> getZoomState() => (super.noSuchMethod( Invocation.method( #getZoomState, [], ), - returnValue: _i17.Future<_i4.LiveData<_i21.ZoomState>>.value( - _FakeLiveData_2<_i21.ZoomState>( + returnValue: _i17.Future<_i7.LiveData<_i21.ZoomState>>.value( + _FakeLiveData_5<_i21.ZoomState>( this, Invocation.method( #getZoomState, @@ -406,22 +589,22 @@ class MockCameraInfo extends _i1.Mock implements _i2.CameraInfo { ), )), returnValueForMissingStub: - _i17.Future<_i4.LiveData<_i21.ZoomState>>.value( - _FakeLiveData_2<_i21.ZoomState>( + _i17.Future<_i7.LiveData<_i21.ZoomState>>.value( + _FakeLiveData_5<_i21.ZoomState>( this, Invocation.method( #getZoomState, [], ), )), - ) as _i17.Future<_i4.LiveData<_i21.ZoomState>>); + ) as _i17.Future<_i7.LiveData<_i21.ZoomState>>); } /// A class which mocks [CameraControl]. /// /// See the documentation for Mockito's code generation for more information. // ignore: must_be_immutable -class MockCameraControl extends _i1.Mock implements _i3.CameraControl { +class MockCameraControl extends _i1.Mock implements _i6.CameraControl { @override _i17.Future enableTorch(bool? torch) => (super.noSuchMethod( Invocation.method( @@ -484,17 +667,17 @@ class MockCameraControl extends _i1.Mock implements _i3.CameraControl { class MockCamera2CameraControl extends _i1.Mock implements _i24.Camera2CameraControl { @override - _i3.CameraControl get cameraControl => (super.noSuchMethod( + _i6.CameraControl get cameraControl => (super.noSuchMethod( Invocation.getter(#cameraControl), - returnValue: _FakeCameraControl_1( + returnValue: _FakeCameraControl_4( this, Invocation.getter(#cameraControl), ), - returnValueForMissingStub: _FakeCameraControl_1( + returnValueForMissingStub: _FakeCameraControl_4( this, Invocation.getter(#cameraControl), ), - ) as _i3.CameraControl); + ) as _i6.CameraControl); @override _i17.Future addCaptureRequestOptions( @@ -509,23 +692,62 @@ class MockCamera2CameraControl extends _i1.Mock ) as _i17.Future); } +/// A class which mocks [Camera2CameraInfo]. +/// +/// See the documentation for Mockito's code generation for more information. +// ignore: must_be_immutable +class MockCamera2CameraInfo extends _i1.Mock implements _i26.Camera2CameraInfo { + @override + _i17.Future getSupportedHardwareLevel() => (super.noSuchMethod( + Invocation.method( + #getSupportedHardwareLevel, + [], + ), + returnValue: _i17.Future.value(0), + returnValueForMissingStub: _i17.Future.value(0), + ) as _i17.Future); + + @override + _i17.Future getCameraId() => (super.noSuchMethod( + Invocation.method( + #getCameraId, + [], + ), + returnValue: _i17.Future.value(_i27.dummyValue( + this, + Invocation.method( + #getCameraId, + [], + ), + )), + returnValueForMissingStub: + _i17.Future.value(_i27.dummyValue( + this, + Invocation.method( + #getCameraId, + [], + ), + )), + ) as _i17.Future); +} + /// A class which mocks [CameraImageData]. /// /// See the documentation for Mockito's code generation for more information. // ignore: must_be_immutable -class MockCameraImageData extends _i1.Mock implements _i6.CameraImageData { +class MockCameraImageData extends _i1.Mock implements _i9.CameraImageData { @override - _i6.CameraImageFormat get format => (super.noSuchMethod( + _i9.CameraImageFormat get format => (super.noSuchMethod( Invocation.getter(#format), - returnValue: _FakeCameraImageFormat_4( + returnValue: _FakeCameraImageFormat_7( this, Invocation.getter(#format), ), - returnValueForMissingStub: _FakeCameraImageFormat_4( + returnValueForMissingStub: _FakeCameraImageFormat_7( this, Invocation.getter(#format), ), - ) as _i6.CameraImageFormat); + ) as _i9.CameraImageFormat); @override int get height => (super.noSuchMethod( @@ -542,50 +764,50 @@ class MockCameraImageData extends _i1.Mock implements _i6.CameraImageData { ) as int); @override - List<_i6.CameraImagePlane> get planes => (super.noSuchMethod( + List<_i9.CameraImagePlane> get planes => (super.noSuchMethod( Invocation.getter(#planes), - returnValue: <_i6.CameraImagePlane>[], - returnValueForMissingStub: <_i6.CameraImagePlane>[], - ) as List<_i6.CameraImagePlane>); + returnValue: <_i9.CameraImagePlane>[], + returnValueForMissingStub: <_i9.CameraImagePlane>[], + ) as List<_i9.CameraImagePlane>); } /// A class which mocks [CameraSelector]. /// /// See the documentation for Mockito's code generation for more information. // ignore: must_be_immutable -class MockCameraSelector extends _i1.Mock implements _i26.CameraSelector { +class MockCameraSelector extends _i1.Mock implements _i28.CameraSelector { @override - _i17.Future> filter(List<_i2.CameraInfo>? cameraInfos) => + _i17.Future> filter(List<_i5.CameraInfo>? cameraInfos) => (super.noSuchMethod( Invocation.method( #filter, [cameraInfos], ), returnValue: - _i17.Future>.value(<_i2.CameraInfo>[]), + _i17.Future>.value(<_i5.CameraInfo>[]), returnValueForMissingStub: - _i17.Future>.value(<_i2.CameraInfo>[]), - ) as _i17.Future>); + _i17.Future>.value(<_i5.CameraInfo>[]), + ) as _i17.Future>); } /// A class which mocks [ExposureState]. /// /// See the documentation for Mockito's code generation for more information. // ignore: must_be_immutable -class MockExposureState extends _i1.Mock implements _i5.ExposureState { +class MockExposureState extends _i1.Mock implements _i8.ExposureState { @override - _i7.ExposureCompensationRange get exposureCompensationRange => + _i10.ExposureCompensationRange get exposureCompensationRange => (super.noSuchMethod( Invocation.getter(#exposureCompensationRange), - returnValue: _FakeExposureCompensationRange_5( + returnValue: _FakeExposureCompensationRange_8( this, Invocation.getter(#exposureCompensationRange), ), - returnValueForMissingStub: _FakeExposureCompensationRange_5( + returnValueForMissingStub: _FakeExposureCompensationRange_8( this, Invocation.getter(#exposureCompensationRange), ), - ) as _i7.ExposureCompensationRange); + ) as _i10.ExposureCompensationRange); @override double get exposureCompensationStep => (super.noSuchMethod( @@ -599,21 +821,21 @@ class MockExposureState extends _i1.Mock implements _i5.ExposureState { /// /// See the documentation for Mockito's code generation for more information. // ignore: must_be_immutable -class MockFallbackStrategy extends _i1.Mock implements _i27.FallbackStrategy { +class MockFallbackStrategy extends _i1.Mock implements _i29.FallbackStrategy { @override - _i7.VideoQuality get quality => (super.noSuchMethod( + _i10.VideoQuality get quality => (super.noSuchMethod( Invocation.getter(#quality), - returnValue: _i7.VideoQuality.SD, - returnValueForMissingStub: _i7.VideoQuality.SD, - ) as _i7.VideoQuality); + returnValue: _i10.VideoQuality.SD, + returnValueForMissingStub: _i10.VideoQuality.SD, + ) as _i10.VideoQuality); @override - _i7.VideoResolutionFallbackRule get fallbackRule => (super.noSuchMethod( + _i10.VideoResolutionFallbackRule get fallbackRule => (super.noSuchMethod( Invocation.getter(#fallbackRule), - returnValue: _i7.VideoResolutionFallbackRule.higherQualityOrLowerThan, + returnValue: _i10.VideoResolutionFallbackRule.higherQualityOrLowerThan, returnValueForMissingStub: - _i7.VideoResolutionFallbackRule.higherQualityOrLowerThan, - ) as _i7.VideoResolutionFallbackRule); + _i10.VideoResolutionFallbackRule.higherQualityOrLowerThan, + ) as _i10.VideoResolutionFallbackRule); } /// A class which mocks [FocusMeteringResult]. @@ -637,7 +859,7 @@ class MockFocusMeteringResult extends _i1.Mock /// /// See the documentation for Mockito's code generation for more information. // ignore: must_be_immutable -class MockImageAnalysis extends _i1.Mock implements _i28.ImageAnalysis { +class MockImageAnalysis extends _i1.Mock implements _i30.ImageAnalysis { @override _i17.Future setTargetRotation(int? rotation) => (super.noSuchMethod( Invocation.method( @@ -673,7 +895,7 @@ class MockImageAnalysis extends _i1.Mock implements _i28.ImageAnalysis { /// /// See the documentation for Mockito's code generation for more information. // ignore: must_be_immutable -class MockImageCapture extends _i1.Mock implements _i29.ImageCapture { +class MockImageCapture extends _i1.Mock implements _i31.ImageCapture { @override _i17.Future setTargetRotation(int? rotation) => (super.noSuchMethod( Invocation.method( @@ -700,7 +922,7 @@ class MockImageCapture extends _i1.Mock implements _i29.ImageCapture { #takePicture, [], ), - returnValue: _i17.Future.value(_i30.dummyValue( + returnValue: _i17.Future.value(_i27.dummyValue( this, Invocation.method( #takePicture, @@ -708,7 +930,7 @@ class MockImageCapture extends _i1.Mock implements _i29.ImageCapture { ), )), returnValueForMissingStub: - _i17.Future.value(_i30.dummyValue( + _i17.Future.value(_i27.dummyValue( this, Invocation.method( #takePicture, @@ -745,16 +967,16 @@ class MockImageProxy extends _i1.Mock implements _i18.ImageProxy { ) as int); @override - _i17.Future> getPlanes() => (super.noSuchMethod( + _i17.Future> getPlanes() => (super.noSuchMethod( Invocation.method( #getPlanes, [], ), returnValue: - _i17.Future>.value(<_i31.PlaneProxy>[]), + _i17.Future>.value(<_i32.PlaneProxy>[]), returnValueForMissingStub: - _i17.Future>.value(<_i31.PlaneProxy>[]), - ) as _i17.Future>); + _i17.Future>.value(<_i32.PlaneProxy>[]), + ) as _i17.Future>); @override _i17.Future close() => (super.noSuchMethod( @@ -771,7 +993,7 @@ class MockImageProxy extends _i1.Mock implements _i18.ImageProxy { /// /// See the documentation for Mockito's code generation for more information. // ignore: must_be_immutable -class MockObserver extends _i1.Mock implements _i32.Observer<_i20.CameraState> { +class MockObserver extends _i1.Mock implements _i33.Observer<_i20.CameraState> { @override void Function(Object) get onChanged => (super.noSuchMethod( Invocation.getter(#onChanged), @@ -793,14 +1015,14 @@ class MockObserver extends _i1.Mock implements _i32.Observer<_i20.CameraState> { /// /// See the documentation for Mockito's code generation for more information. // ignore: must_be_immutable -class MockPendingRecording extends _i1.Mock implements _i10.PendingRecording { +class MockPendingRecording extends _i1.Mock implements _i13.PendingRecording { @override - _i17.Future<_i8.Recording> start() => (super.noSuchMethod( + _i17.Future<_i11.Recording> start() => (super.noSuchMethod( Invocation.method( #start, [], ), - returnValue: _i17.Future<_i8.Recording>.value(_FakeRecording_6( + returnValue: _i17.Future<_i11.Recording>.value(_FakeRecording_9( this, Invocation.method( #start, @@ -808,27 +1030,27 @@ class MockPendingRecording extends _i1.Mock implements _i10.PendingRecording { ), )), returnValueForMissingStub: - _i17.Future<_i8.Recording>.value(_FakeRecording_6( + _i17.Future<_i11.Recording>.value(_FakeRecording_9( this, Invocation.method( #start, [], ), )), - ) as _i17.Future<_i8.Recording>); + ) as _i17.Future<_i11.Recording>); } /// A class which mocks [PlaneProxy]. /// /// See the documentation for Mockito's code generation for more information. // ignore: must_be_immutable -class MockPlaneProxy extends _i1.Mock implements _i31.PlaneProxy { +class MockPlaneProxy extends _i1.Mock implements _i32.PlaneProxy { @override - _i33.Uint8List get buffer => (super.noSuchMethod( + _i34.Uint8List get buffer => (super.noSuchMethod( Invocation.getter(#buffer), - returnValue: _i33.Uint8List(0), - returnValueForMissingStub: _i33.Uint8List(0), - ) as _i33.Uint8List); + returnValue: _i34.Uint8List(0), + returnValueForMissingStub: _i34.Uint8List(0), + ) as _i34.Uint8List); @override int get pixelStride => (super.noSuchMethod( @@ -849,7 +1071,7 @@ class MockPlaneProxy extends _i1.Mock implements _i31.PlaneProxy { /// /// See the documentation for Mockito's code generation for more information. // ignore: must_be_immutable -class MockPreview extends _i1.Mock implements _i34.Preview { +class MockPreview extends _i1.Mock implements _i35.Preview { @override _i17.Future setTargetRotation(int? rotation) => (super.noSuchMethod( Invocation.method( @@ -880,13 +1102,13 @@ class MockPreview extends _i1.Mock implements _i34.Preview { ); @override - _i17.Future<_i7.ResolutionInfo> getResolutionInfo() => (super.noSuchMethod( + _i17.Future<_i10.ResolutionInfo> getResolutionInfo() => (super.noSuchMethod( Invocation.method( #getResolutionInfo, [], ), returnValue: - _i17.Future<_i7.ResolutionInfo>.value(_FakeResolutionInfo_7( + _i17.Future<_i10.ResolutionInfo>.value(_FakeResolutionInfo_10( this, Invocation.method( #getResolutionInfo, @@ -894,14 +1116,14 @@ class MockPreview extends _i1.Mock implements _i34.Preview { ), )), returnValueForMissingStub: - _i17.Future<_i7.ResolutionInfo>.value(_FakeResolutionInfo_7( + _i17.Future<_i10.ResolutionInfo>.value(_FakeResolutionInfo_10( this, Invocation.method( #getResolutionInfo, [], ), )), - ) as _i17.Future<_i7.ResolutionInfo>); + ) as _i17.Future<_i10.ResolutionInfo>); } /// A class which mocks [ProcessCameraProvider]. @@ -909,24 +1131,24 @@ class MockPreview extends _i1.Mock implements _i34.Preview { /// See the documentation for Mockito's code generation for more information. // ignore: must_be_immutable class MockProcessCameraProvider extends _i1.Mock - implements _i35.ProcessCameraProvider { + implements _i36.ProcessCameraProvider { @override - _i17.Future> getAvailableCameraInfos() => + _i17.Future> getAvailableCameraInfos() => (super.noSuchMethod( Invocation.method( #getAvailableCameraInfos, [], ), returnValue: - _i17.Future>.value(<_i2.CameraInfo>[]), + _i17.Future>.value(<_i5.CameraInfo>[]), returnValueForMissingStub: - _i17.Future>.value(<_i2.CameraInfo>[]), - ) as _i17.Future>); + _i17.Future>.value(<_i5.CameraInfo>[]), + ) as _i17.Future>); @override - _i17.Future<_i9.Camera> bindToLifecycle( - _i26.CameraSelector? cameraSelector, - List<_i36.UseCase>? useCases, + _i17.Future<_i12.Camera> bindToLifecycle( + _i28.CameraSelector? cameraSelector, + List<_i37.UseCase>? useCases, ) => (super.noSuchMethod( Invocation.method( @@ -936,7 +1158,7 @@ class MockProcessCameraProvider extends _i1.Mock useCases, ], ), - returnValue: _i17.Future<_i9.Camera>.value(_FakeCamera_8( + returnValue: _i17.Future<_i12.Camera>.value(_FakeCamera_11( this, Invocation.method( #bindToLifecycle, @@ -946,7 +1168,8 @@ class MockProcessCameraProvider extends _i1.Mock ], ), )), - returnValueForMissingStub: _i17.Future<_i9.Camera>.value(_FakeCamera_8( + returnValueForMissingStub: + _i17.Future<_i12.Camera>.value(_FakeCamera_11( this, Invocation.method( #bindToLifecycle, @@ -956,10 +1179,10 @@ class MockProcessCameraProvider extends _i1.Mock ], ), )), - ) as _i17.Future<_i9.Camera>); + ) as _i17.Future<_i12.Camera>); @override - _i17.Future isBound(_i36.UseCase? useCase) => (super.noSuchMethod( + _i17.Future isBound(_i37.UseCase? useCase) => (super.noSuchMethod( Invocation.method( #isBound, [useCase], @@ -969,7 +1192,7 @@ class MockProcessCameraProvider extends _i1.Mock ) as _i17.Future); @override - void unbind(List<_i36.UseCase>? useCases) => super.noSuchMethod( + void unbind(List<_i37.UseCase>? useCases) => super.noSuchMethod( Invocation.method( #unbind, [useCases], @@ -991,29 +1214,29 @@ class MockProcessCameraProvider extends _i1.Mock /// /// See the documentation for Mockito's code generation for more information. // ignore: must_be_immutable -class MockQualitySelector extends _i1.Mock implements _i37.QualitySelector { +class MockQualitySelector extends _i1.Mock implements _i38.QualitySelector { @override - List<_i7.VideoQualityData> get qualityList => (super.noSuchMethod( + List<_i10.VideoQualityData> get qualityList => (super.noSuchMethod( Invocation.getter(#qualityList), - returnValue: <_i7.VideoQualityData>[], - returnValueForMissingStub: <_i7.VideoQualityData>[], - ) as List<_i7.VideoQualityData>); + returnValue: <_i10.VideoQualityData>[], + returnValueForMissingStub: <_i10.VideoQualityData>[], + ) as List<_i10.VideoQualityData>); } /// A class which mocks [Recorder]. /// /// See the documentation for Mockito's code generation for more information. // ignore: must_be_immutable -class MockRecorder extends _i1.Mock implements _i12.Recorder { +class MockRecorder extends _i1.Mock implements _i15.Recorder { @override - _i17.Future<_i10.PendingRecording> prepareRecording(String? path) => + _i17.Future<_i13.PendingRecording> prepareRecording(String? path) => (super.noSuchMethod( Invocation.method( #prepareRecording, [path], ), returnValue: - _i17.Future<_i10.PendingRecording>.value(_FakePendingRecording_9( + _i17.Future<_i13.PendingRecording>.value(_FakePendingRecording_12( this, Invocation.method( #prepareRecording, @@ -1021,33 +1244,33 @@ class MockRecorder extends _i1.Mock implements _i12.Recorder { ), )), returnValueForMissingStub: - _i17.Future<_i10.PendingRecording>.value(_FakePendingRecording_9( + _i17.Future<_i13.PendingRecording>.value(_FakePendingRecording_12( this, Invocation.method( #prepareRecording, [path], ), )), - ) as _i17.Future<_i10.PendingRecording>); + ) as _i17.Future<_i13.PendingRecording>); } /// A class which mocks [ResolutionFilter]. /// /// See the documentation for Mockito's code generation for more information. // ignore: must_be_immutable -class MockResolutionFilter extends _i1.Mock implements _i38.ResolutionFilter { +class MockResolutionFilter extends _i1.Mock implements _i39.ResolutionFilter { @override - _i11.Size get preferredResolution => (super.noSuchMethod( + _i14.Size get preferredResolution => (super.noSuchMethod( Invocation.getter(#preferredResolution), - returnValue: _FakeSize_10( + returnValue: _FakeSize_13( this, Invocation.getter(#preferredResolution), ), - returnValueForMissingStub: _FakeSize_10( + returnValueForMissingStub: _FakeSize_13( this, Invocation.getter(#preferredResolution), ), - ) as _i11.Size); + ) as _i14.Size); } /// A class which mocks [ResolutionSelector]. @@ -1055,20 +1278,20 @@ class MockResolutionFilter extends _i1.Mock implements _i38.ResolutionFilter { /// See the documentation for Mockito's code generation for more information. // ignore: must_be_immutable class MockResolutionSelector extends _i1.Mock - implements _i39.ResolutionSelector {} + implements _i40.ResolutionSelector {} /// A class which mocks [ResolutionStrategy]. /// /// See the documentation for Mockito's code generation for more information. // ignore: must_be_immutable class MockResolutionStrategy extends _i1.Mock - implements _i40.ResolutionStrategy {} + implements _i41.ResolutionStrategy {} /// A class which mocks [Recording]. /// /// See the documentation for Mockito's code generation for more information. // ignore: must_be_immutable -class MockRecording extends _i1.Mock implements _i8.Recording { +class MockRecording extends _i1.Mock implements _i11.Recording { @override _i17.Future close() => (super.noSuchMethod( Invocation.method( @@ -1110,229 +1333,6 @@ class MockRecording extends _i1.Mock implements _i8.Recording { ) as _i17.Future); } -/// A class which mocks [VideoCapture]. -/// -/// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable -class MockVideoCapture extends _i1.Mock implements _i41.VideoCapture { - @override - _i17.Future setTargetRotation(int? rotation) => (super.noSuchMethod( - Invocation.method( - #setTargetRotation, - [rotation], - ), - returnValue: _i17.Future.value(), - returnValueForMissingStub: _i17.Future.value(), - ) as _i17.Future); - - @override - _i17.Future<_i12.Recorder> getOutput() => (super.noSuchMethod( - Invocation.method( - #getOutput, - [], - ), - returnValue: _i17.Future<_i12.Recorder>.value(_FakeRecorder_11( - this, - Invocation.method( - #getOutput, - [], - ), - )), - returnValueForMissingStub: - _i17.Future<_i12.Recorder>.value(_FakeRecorder_11( - this, - Invocation.method( - #getOutput, - [], - ), - )), - ) as _i17.Future<_i12.Recorder>); -} - -/// A class which mocks [BuildContext]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockBuildContext extends _i1.Mock implements _i13.BuildContext { - @override - _i13.Widget get widget => (super.noSuchMethod( - Invocation.getter(#widget), - returnValue: _FakeWidget_12( - this, - Invocation.getter(#widget), - ), - returnValueForMissingStub: _FakeWidget_12( - this, - Invocation.getter(#widget), - ), - ) as _i13.Widget); - - @override - bool get mounted => (super.noSuchMethod( - Invocation.getter(#mounted), - returnValue: false, - returnValueForMissingStub: false, - ) as bool); - - @override - bool get debugDoingBuild => (super.noSuchMethod( - Invocation.getter(#debugDoingBuild), - returnValue: false, - returnValueForMissingStub: false, - ) as bool); - - @override - _i13.InheritedWidget dependOnInheritedElement( - _i13.InheritedElement? ancestor, { - Object? aspect, - }) => - (super.noSuchMethod( - Invocation.method( - #dependOnInheritedElement, - [ancestor], - {#aspect: aspect}, - ), - returnValue: _FakeInheritedWidget_13( - this, - Invocation.method( - #dependOnInheritedElement, - [ancestor], - {#aspect: aspect}, - ), - ), - returnValueForMissingStub: _FakeInheritedWidget_13( - this, - Invocation.method( - #dependOnInheritedElement, - [ancestor], - {#aspect: aspect}, - ), - ), - ) as _i13.InheritedWidget); - - @override - void visitAncestorElements(_i13.ConditionalElementVisitor? visitor) => - super.noSuchMethod( - Invocation.method( - #visitAncestorElements, - [visitor], - ), - returnValueForMissingStub: null, - ); - - @override - void visitChildElements(_i13.ElementVisitor? visitor) => super.noSuchMethod( - Invocation.method( - #visitChildElements, - [visitor], - ), - returnValueForMissingStub: null, - ); - - @override - void dispatchNotification(_i13.Notification? notification) => - super.noSuchMethod( - Invocation.method( - #dispatchNotification, - [notification], - ), - returnValueForMissingStub: null, - ); - - @override - _i15.DiagnosticsNode describeElement( - String? name, { - _i15.DiagnosticsTreeStyle? style = _i15.DiagnosticsTreeStyle.errorProperty, - }) => - (super.noSuchMethod( - Invocation.method( - #describeElement, - [name], - {#style: style}, - ), - returnValue: _FakeDiagnosticsNode_14( - this, - Invocation.method( - #describeElement, - [name], - {#style: style}, - ), - ), - returnValueForMissingStub: _FakeDiagnosticsNode_14( - this, - Invocation.method( - #describeElement, - [name], - {#style: style}, - ), - ), - ) as _i15.DiagnosticsNode); - - @override - _i15.DiagnosticsNode describeWidget( - String? name, { - _i15.DiagnosticsTreeStyle? style = _i15.DiagnosticsTreeStyle.errorProperty, - }) => - (super.noSuchMethod( - Invocation.method( - #describeWidget, - [name], - {#style: style}, - ), - returnValue: _FakeDiagnosticsNode_14( - this, - Invocation.method( - #describeWidget, - [name], - {#style: style}, - ), - ), - returnValueForMissingStub: _FakeDiagnosticsNode_14( - this, - Invocation.method( - #describeWidget, - [name], - {#style: style}, - ), - ), - ) as _i15.DiagnosticsNode); - - @override - List<_i15.DiagnosticsNode> describeMissingAncestor( - {required Type? expectedAncestorType}) => - (super.noSuchMethod( - Invocation.method( - #describeMissingAncestor, - [], - {#expectedAncestorType: expectedAncestorType}, - ), - returnValue: <_i15.DiagnosticsNode>[], - returnValueForMissingStub: <_i15.DiagnosticsNode>[], - ) as List<_i15.DiagnosticsNode>); - - @override - _i15.DiagnosticsNode describeOwnershipChain(String? name) => - (super.noSuchMethod( - Invocation.method( - #describeOwnershipChain, - [name], - ), - returnValue: _FakeDiagnosticsNode_14( - this, - Invocation.method( - #describeOwnershipChain, - [name], - ), - ), - returnValueForMissingStub: _FakeDiagnosticsNode_14( - this, - Invocation.method( - #describeOwnershipChain, - [name], - ), - ), - ) as _i15.DiagnosticsNode); -} - /// A class which mocks [TestInstanceManagerHostApi]. /// /// See the documentation for Mockito's code generation for more information. @@ -1354,17 +1354,17 @@ class MockTestInstanceManagerHostApi extends _i1.Mock class MockTestSystemServicesHostApi extends _i1.Mock implements _i42.TestSystemServicesHostApi { @override - _i17.Future<_i7.CameraPermissionsErrorData?> requestCameraPermissions( + _i17.Future<_i10.CameraPermissionsErrorData?> requestCameraPermissions( bool? enableAudio) => (super.noSuchMethod( Invocation.method( #requestCameraPermissions, [enableAudio], ), - returnValue: _i17.Future<_i7.CameraPermissionsErrorData?>.value(), + returnValue: _i17.Future<_i10.CameraPermissionsErrorData?>.value(), returnValueForMissingStub: - _i17.Future<_i7.CameraPermissionsErrorData?>.value(), - ) as _i17.Future<_i7.CameraPermissionsErrorData?>); + _i17.Future<_i10.CameraPermissionsErrorData?>.value(), + ) as _i17.Future<_i10.CameraPermissionsErrorData?>); @override String getTempFilePath( @@ -1379,7 +1379,7 @@ class MockTestSystemServicesHostApi extends _i1.Mock suffix, ], ), - returnValue: _i30.dummyValue( + returnValue: _i27.dummyValue( this, Invocation.method( #getTempFilePath, @@ -1389,7 +1389,7 @@ class MockTestSystemServicesHostApi extends _i1.Mock ], ), ), - returnValueForMissingStub: _i30.dummyValue( + returnValueForMissingStub: _i27.dummyValue( this, Invocation.method( #getTempFilePath, @@ -1402,6 +1402,45 @@ class MockTestSystemServicesHostApi extends _i1.Mock ) as String); } +/// A class which mocks [VideoCapture]. +/// +/// See the documentation for Mockito's code generation for more information. +// ignore: must_be_immutable +class MockVideoCapture extends _i1.Mock implements _i43.VideoCapture { + @override + _i17.Future setTargetRotation(int? rotation) => (super.noSuchMethod( + Invocation.method( + #setTargetRotation, + [rotation], + ), + returnValue: _i17.Future.value(), + returnValueForMissingStub: _i17.Future.value(), + ) as _i17.Future); + + @override + _i17.Future<_i15.Recorder> getOutput() => (super.noSuchMethod( + Invocation.method( + #getOutput, + [], + ), + returnValue: _i17.Future<_i15.Recorder>.value(_FakeRecorder_14( + this, + Invocation.method( + #getOutput, + [], + ), + )), + returnValueForMissingStub: + _i17.Future<_i15.Recorder>.value(_FakeRecorder_14( + this, + Invocation.method( + #getOutput, + [], + ), + )), + ) as _i17.Future<_i15.Recorder>); +} + /// A class which mocks [ZoomState]. /// /// See the documentation for Mockito's code generation for more information. @@ -1427,13 +1466,13 @@ class MockZoomState extends _i1.Mock implements _i21.ZoomState { /// See the documentation for Mockito's code generation for more information. // ignore: must_be_immutable class MockLiveCameraState extends _i1.Mock - implements _i4.LiveData<_i20.CameraState> { + implements _i7.LiveData<_i20.CameraState> { MockLiveCameraState() { _i1.throwOnMissingStub(this); } @override - _i17.Future observe(_i32.Observer<_i20.CameraState>? observer) => + _i17.Future observe(_i33.Observer<_i20.CameraState>? observer) => (super.noSuchMethod( Invocation.method( #observe, @@ -1459,13 +1498,13 @@ class MockLiveCameraState extends _i1.Mock /// See the documentation for Mockito's code generation for more information. // ignore: must_be_immutable class MockLiveZoomState extends _i1.Mock - implements _i4.LiveData<_i21.ZoomState> { + implements _i7.LiveData<_i21.ZoomState> { MockLiveZoomState() { _i1.throwOnMissingStub(this); } @override - _i17.Future observe(_i32.Observer<_i21.ZoomState>? observer) => + _i17.Future observe(_i33.Observer<_i21.ZoomState>? observer) => (super.noSuchMethod( Invocation.method( #observe, diff --git a/packages/camera/camera_android_camerax/test/camera2_camera_info_test.dart b/packages/camera/camera_android_camerax/test/camera2_camera_info_test.dart new file mode 100644 index 00000000000..0766eee37e8 --- /dev/null +++ b/packages/camera/camera_android_camerax/test/camera2_camera_info_test.dart @@ -0,0 +1,155 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:camera_android_camerax/src/camera2_camera_info.dart'; +import 'package:camera_android_camerax/src/camera_info.dart'; +import 'package:camera_android_camerax/src/camera_metadata.dart'; +import 'package:camera_android_camerax/src/camerax_library.g.dart'; +import 'package:camera_android_camerax/src/instance_manager.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/annotations.dart'; +import 'package:mockito/mockito.dart'; + +import 'camera2_camera_info_test.mocks.dart'; +import 'test_camerax_library.g.dart'; + +@GenerateMocks([ + TestCamera2CameraInfoHostApi, + TestInstanceManagerHostApi, + CameraInfo +]) +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + // Mocks the call to clear the native InstanceManager. + TestInstanceManagerHostApi.setup(MockTestInstanceManagerHostApi()); + + group('Camera2CameraInfo', () { + tearDown(() => TestCamera2CameraInfoHostApi.setup(null)); + + test('from returns expected Camera2CameraInfo instance', () async { + final MockTestCamera2CameraInfoHostApi mockApi = + MockTestCamera2CameraInfoHostApi(); + TestCamera2CameraInfoHostApi.setup(mockApi); + + final InstanceManager instanceManager = InstanceManager( + onWeakReferenceRemoved: (_) {}, + ); + final Camera2CameraInfo camera2CameraInfo = Camera2CameraInfo.detached( + instanceManager: instanceManager, + ); + final CameraInfo mockCameraInfo = MockCameraInfo(); + const int camera2CameraInfoId = 33; + const int mockCameraInfoId = 44; + + instanceManager.addHostCreatedInstance( + camera2CameraInfo, + camera2CameraInfoId, + onCopy: (_) => Camera2CameraInfo.detached(), + ); + instanceManager.addHostCreatedInstance( + mockCameraInfo, + mockCameraInfoId, + onCopy: (_) => CameraInfo.detached(), + ); + + when(mockApi.createFrom(mockCameraInfoId)) + .thenAnswer((_) => camera2CameraInfoId); + expect( + await Camera2CameraInfo.from(mockCameraInfo, + instanceManager: instanceManager), + equals(camera2CameraInfo)); + verify(mockApi.createFrom(mockCameraInfoId)); + }); + + test('detached constructor does not create Camera2CameraInfo on Java side', + () async { + final MockTestCamera2CameraInfoHostApi mockApi = + MockTestCamera2CameraInfoHostApi(); + TestCamera2CameraInfoHostApi.setup(mockApi); + + final InstanceManager instanceManager = InstanceManager( + onWeakReferenceRemoved: (_) {}, + ); + Camera2CameraInfo.detached( + instanceManager: instanceManager, + ); + + verifyNever(mockApi.createFrom(argThat(isA()))); + }); + + test( + 'getSupportedHardwareLevel makes call to retrieve supported hardware level', + () async { + final MockTestCamera2CameraInfoHostApi mockApi = + MockTestCamera2CameraInfoHostApi(); + TestCamera2CameraInfoHostApi.setup(mockApi); + + final InstanceManager instanceManager = InstanceManager( + onWeakReferenceRemoved: (_) {}, + ); + final Camera2CameraInfo camera2CameraInfo = Camera2CameraInfo.detached( + instanceManager: instanceManager, + ); + const int camera2CameraInfoId = 9; + + instanceManager.addHostCreatedInstance( + camera2CameraInfo, + camera2CameraInfoId, + onCopy: (_) => Camera2CameraInfo.detached(), + ); + + const int expectedSupportedHardwareLevel = + CameraMetadata.infoSupportedHardwareLevelExternal; + when(mockApi.getSupportedHardwareLevel(camera2CameraInfoId)) + .thenReturn(expectedSupportedHardwareLevel); + expect(await camera2CameraInfo.getSupportedHardwareLevel(), + equals(expectedSupportedHardwareLevel)); + + verify(mockApi.getSupportedHardwareLevel(camera2CameraInfoId)); + }); + + test('getCameraId makes call to retrieve camera ID', () async { + final MockTestCamera2CameraInfoHostApi mockApi = + MockTestCamera2CameraInfoHostApi(); + TestCamera2CameraInfoHostApi.setup(mockApi); + + final InstanceManager instanceManager = InstanceManager( + onWeakReferenceRemoved: (_) {}, + ); + final Camera2CameraInfo camera2CameraInfo = Camera2CameraInfo.detached( + instanceManager: instanceManager, + ); + const int camera2CameraInfoId = 19; + + instanceManager.addHostCreatedInstance( + camera2CameraInfo, + camera2CameraInfoId, + onCopy: (_) => Camera2CameraInfo.detached(), + ); + + const String expectedCameraId = 'testCameraId'; + when(mockApi.getCameraId(camera2CameraInfoId)) + .thenReturn(expectedCameraId); + expect(await camera2CameraInfo.getCameraId(), equals(expectedCameraId)); + + verify(mockApi.getCameraId(camera2CameraInfoId)); + }); + + test('flutterApi create makes call to create expected instance type', () { + final InstanceManager instanceManager = InstanceManager( + onWeakReferenceRemoved: (_) {}, + ); + final Camera2CameraInfoFlutterApi flutterApi = + Camera2CameraInfoFlutterApiImpl( + instanceManager: instanceManager, + ); + + flutterApi.create(0); + + expect(instanceManager.getInstanceWithWeakReference(0), + isA()); + }); + }); +} diff --git a/packages/camera/camera_android_camerax/test/camera2_camera_info_test.mocks.dart b/packages/camera/camera_android_camerax/test/camera2_camera_info_test.mocks.dart new file mode 100644 index 00000000000..9060c51874a --- /dev/null +++ b/packages/camera/camera_android_camerax/test/camera2_camera_info_test.mocks.dart @@ -0,0 +1,179 @@ +// Mocks generated by Mockito 5.4.4 from annotations +// in camera_android_camerax/test/camera2_camera_info_test.dart. +// Do not manually edit this file. + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:async' as _i7; + +import 'package:camera_android_camerax/src/camera_info.dart' as _i6; +import 'package:camera_android_camerax/src/camera_state.dart' as _i8; +import 'package:camera_android_camerax/src/exposure_state.dart' as _i3; +import 'package:camera_android_camerax/src/live_data.dart' as _i2; +import 'package:camera_android_camerax/src/zoom_state.dart' as _i9; +import 'package:mockito/mockito.dart' as _i1; +import 'package:mockito/src/dummies.dart' as _i5; + +import 'test_camerax_library.g.dart' as _i4; + +// ignore_for_file: type=lint +// ignore_for_file: avoid_redundant_argument_values +// ignore_for_file: avoid_setters_without_getters +// ignore_for_file: comment_references +// ignore_for_file: deprecated_member_use +// ignore_for_file: deprecated_member_use_from_same_package +// ignore_for_file: implementation_imports +// ignore_for_file: invalid_use_of_visible_for_testing_member +// ignore_for_file: prefer_const_constructors +// ignore_for_file: unnecessary_parenthesis +// ignore_for_file: camel_case_types +// ignore_for_file: subtype_of_sealed_class + +class _FakeLiveData_0 extends _i1.SmartFake + implements _i2.LiveData { + _FakeLiveData_0( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeExposureState_1 extends _i1.SmartFake implements _i3.ExposureState { + _FakeExposureState_1( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +/// A class which mocks [TestCamera2CameraInfoHostApi]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockTestCamera2CameraInfoHostApi extends _i1.Mock + implements _i4.TestCamera2CameraInfoHostApi { + MockTestCamera2CameraInfoHostApi() { + _i1.throwOnMissingStub(this); + } + + @override + int createFrom(int? cameraInfoIdentifier) => (super.noSuchMethod( + Invocation.method( + #createFrom, + [cameraInfoIdentifier], + ), + returnValue: 0, + ) as int); + + @override + int getSupportedHardwareLevel(int? identifier) => (super.noSuchMethod( + Invocation.method( + #getSupportedHardwareLevel, + [identifier], + ), + returnValue: 0, + ) as int); + + @override + String getCameraId(int? identifier) => (super.noSuchMethod( + Invocation.method( + #getCameraId, + [identifier], + ), + returnValue: _i5.dummyValue( + this, + Invocation.method( + #getCameraId, + [identifier], + ), + ), + ) as String); +} + +/// A class which mocks [TestInstanceManagerHostApi]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockTestInstanceManagerHostApi extends _i1.Mock + implements _i4.TestInstanceManagerHostApi { + MockTestInstanceManagerHostApi() { + _i1.throwOnMissingStub(this); + } + + @override + void clear() => super.noSuchMethod( + Invocation.method( + #clear, + [], + ), + returnValueForMissingStub: null, + ); +} + +/// A class which mocks [CameraInfo]. +/// +/// See the documentation for Mockito's code generation for more information. +// ignore: must_be_immutable +class MockCameraInfo extends _i1.Mock implements _i6.CameraInfo { + MockCameraInfo() { + _i1.throwOnMissingStub(this); + } + + @override + _i7.Future getSensorRotationDegrees() => (super.noSuchMethod( + Invocation.method( + #getSensorRotationDegrees, + [], + ), + returnValue: _i7.Future.value(0), + ) as _i7.Future); + + @override + _i7.Future<_i2.LiveData<_i8.CameraState>> getCameraState() => + (super.noSuchMethod( + Invocation.method( + #getCameraState, + [], + ), + returnValue: _i7.Future<_i2.LiveData<_i8.CameraState>>.value( + _FakeLiveData_0<_i8.CameraState>( + this, + Invocation.method( + #getCameraState, + [], + ), + )), + ) as _i7.Future<_i2.LiveData<_i8.CameraState>>); + + @override + _i7.Future<_i3.ExposureState> getExposureState() => (super.noSuchMethod( + Invocation.method( + #getExposureState, + [], + ), + returnValue: _i7.Future<_i3.ExposureState>.value(_FakeExposureState_1( + this, + Invocation.method( + #getExposureState, + [], + ), + )), + ) as _i7.Future<_i3.ExposureState>); + + @override + _i7.Future<_i2.LiveData<_i9.ZoomState>> getZoomState() => (super.noSuchMethod( + Invocation.method( + #getZoomState, + [], + ), + returnValue: _i7.Future<_i2.LiveData<_i9.ZoomState>>.value( + _FakeLiveData_0<_i9.ZoomState>( + this, + Invocation.method( + #getZoomState, + [], + ), + )), + ) as _i7.Future<_i2.LiveData<_i9.ZoomState>>); +} diff --git a/packages/camera/camera_android_camerax/test/device_orientation_manager_test.dart b/packages/camera/camera_android_camerax/test/device_orientation_manager_test.dart index 145ceeb278a..de24bb0b3f4 100644 --- a/packages/camera/camera_android_camerax/test/device_orientation_manager_test.dart +++ b/packages/camera/camera_android_camerax/test/device_orientation_manager_test.dart @@ -52,7 +52,7 @@ void main() { final MockTestDeviceOrientationManagerHostApi mockApi = MockTestDeviceOrientationManagerHostApi(); TestDeviceOrientationManagerHostApi.setup(mockApi); - const int expectedRotation = Surface.ROTATION_180; + const int expectedRotation = Surface.rotation180; when(mockApi.getDefaultDisplayRotation()).thenReturn(expectedRotation); diff --git a/packages/camera/camera_android_camerax/test/image_analysis_test.dart b/packages/camera/camera_android_camerax/test/image_analysis_test.dart index 1db792cf6d3..df220357508 100644 --- a/packages/camera/camera_android_camerax/test/image_analysis_test.dart +++ b/packages/camera/camera_android_camerax/test/image_analysis_test.dart @@ -41,7 +41,7 @@ void main() { ); ImageAnalysis.detached( - initialTargetRotation: Surface.ROTATION_270, + initialTargetRotation: Surface.rotation270, resolutionSelector: MockResolutionSelector(), instanceManager: instanceManager, ); @@ -58,7 +58,7 @@ void main() { onWeakReferenceRemoved: (_) {}, ); - const int targetRotation = Surface.ROTATION_90; + const int targetRotation = Surface.rotation90; final MockResolutionSelector mockResolutionSelector = MockResolutionSelector(); const int mockResolutionSelectorId = 24; @@ -91,7 +91,7 @@ void main() { final InstanceManager instanceManager = InstanceManager( onWeakReferenceRemoved: (_) {}, ); - const int targetRotation = Surface.ROTATION_180; + const int targetRotation = Surface.rotation180; final ImageAnalysis imageAnalysis = ImageAnalysis.detached( instanceManager: instanceManager, ); diff --git a/packages/camera/camera_android_camerax/test/image_capture_test.dart b/packages/camera/camera_android_camerax/test/image_capture_test.dart index e9e9f0c1855..56cbd8fcc18 100644 --- a/packages/camera/camera_android_camerax/test/image_capture_test.dart +++ b/packages/camera/camera_android_camerax/test/image_capture_test.dart @@ -36,7 +36,7 @@ void main() { ); ImageCapture.detached( instanceManager: instanceManager, - initialTargetRotation: Surface.ROTATION_180, + initialTargetRotation: Surface.rotation180, targetFlashMode: ImageCapture.flashModeOn, resolutionSelector: MockResolutionSelector(), ); @@ -53,7 +53,7 @@ void main() { onWeakReferenceRemoved: (_) {}, ); - const int targetRotation = Surface.ROTATION_270; + const int targetRotation = Surface.rotation270; const int targetFlashMode = ImageCapture.flashModeAuto; final MockResolutionSelector mockResolutionSelector = MockResolutionSelector(); @@ -112,7 +112,7 @@ void main() { final InstanceManager instanceManager = InstanceManager( onWeakReferenceRemoved: (_) {}, ); - const int targetRotation = Surface.ROTATION_180; + const int targetRotation = Surface.rotation180; final ImageCapture imageCapture = ImageCapture.detached( instanceManager: instanceManager, ); diff --git a/packages/camera/camera_android_camerax/test/preview_test.dart b/packages/camera/camera_android_camerax/test/preview_test.dart index cda1252d538..b3cbc257b0c 100644 --- a/packages/camera/camera_android_camerax/test/preview_test.dart +++ b/packages/camera/camera_android_camerax/test/preview_test.dart @@ -34,7 +34,7 @@ void main() { ); Preview.detached( instanceManager: instanceManager, - initialTargetRotation: Surface.ROTATION_90, + initialTargetRotation: Surface.rotation90, resolutionSelector: MockResolutionSelector(), ); @@ -49,7 +49,7 @@ void main() { final InstanceManager instanceManager = InstanceManager( onWeakReferenceRemoved: (_) {}, ); - const int targetRotation = Surface.ROTATION_90; + const int targetRotation = Surface.rotation90; final MockResolutionSelector mockResolutionSelector = MockResolutionSelector(); const int mockResolutionSelectorId = 24; @@ -81,7 +81,7 @@ void main() { final InstanceManager instanceManager = InstanceManager( onWeakReferenceRemoved: (_) {}, ); - const int targetRotation = Surface.ROTATION_180; + const int targetRotation = Surface.rotation180; final Preview preview = Preview.detached( instanceManager: instanceManager, ); diff --git a/packages/camera/camera_android_camerax/test/test_camerax_library.g.dart b/packages/camera/camera_android_camerax/test/test_camerax_library.g.dart index 8080e4276fc..8a659e460cd 100644 --- a/packages/camera/camera_android_camerax/test/test_camerax_library.g.dart +++ b/packages/camera/camera_android_camerax/test/test_camerax_library.g.dart @@ -2428,3 +2428,86 @@ abstract class TestResolutionFilterHostApi { } } } + +abstract class TestCamera2CameraInfoHostApi { + static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => + TestDefaultBinaryMessengerBinding.instance; + static const MessageCodec codec = StandardMessageCodec(); + + int createFrom(int cameraInfoIdentifier); + + int getSupportedHardwareLevel(int identifier); + + String getCameraId(int identifier); + + static void setup(TestCamera2CameraInfoHostApi? api, + {BinaryMessenger? binaryMessenger}) { + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.Camera2CameraInfoHostApi.createFrom', codec, + binaryMessenger: binaryMessenger); + if (api == null) { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, null); + } else { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, + (Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.Camera2CameraInfoHostApi.createFrom was null.'); + final List args = (message as List?)!; + final int? arg_cameraInfoIdentifier = (args[0] as int?); + assert(arg_cameraInfoIdentifier != null, + 'Argument for dev.flutter.pigeon.Camera2CameraInfoHostApi.createFrom was null, expected non-null int.'); + final int output = api.createFrom(arg_cameraInfoIdentifier!); + return [output]; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.Camera2CameraInfoHostApi.getSupportedHardwareLevel', + codec, + binaryMessenger: binaryMessenger); + if (api == null) { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, null); + } else { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, + (Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.Camera2CameraInfoHostApi.getSupportedHardwareLevel was null.'); + final List args = (message as List?)!; + final int? arg_identifier = (args[0] as int?); + assert(arg_identifier != null, + 'Argument for dev.flutter.pigeon.Camera2CameraInfoHostApi.getSupportedHardwareLevel was null, expected non-null int.'); + final int output = api.getSupportedHardwareLevel(arg_identifier!); + return [output]; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.Camera2CameraInfoHostApi.getCameraId', codec, + binaryMessenger: binaryMessenger); + if (api == null) { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, null); + } else { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, + (Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.Camera2CameraInfoHostApi.getCameraId was null.'); + final List args = (message as List?)!; + final int? arg_identifier = (args[0] as int?); + assert(arg_identifier != null, + 'Argument for dev.flutter.pigeon.Camera2CameraInfoHostApi.getCameraId was null, expected non-null int.'); + final String output = api.getCameraId(arg_identifier!); + return [output]; + }); + } + } + } +} diff --git a/packages/camera/camera_android_camerax/test/video_capture_test.dart b/packages/camera/camera_android_camerax/test/video_capture_test.dart index 6954b352ade..c5fd1f078b9 100644 --- a/packages/camera/camera_android_camerax/test/video_capture_test.dart +++ b/packages/camera/camera_android_camerax/test/video_capture_test.dart @@ -60,7 +60,7 @@ void main() { final InstanceManager instanceManager = InstanceManager( onWeakReferenceRemoved: (_) {}, ); - const int targetRotation = Surface.ROTATION_180; + const int targetRotation = Surface.rotation180; final VideoCapture videoCapture = VideoCapture.detached( instanceManager: instanceManager, ); diff --git a/packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md b/packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md index f5e5680598a..1b95c312d91 100644 --- a/packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md +++ b/packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.3.5 + +* Replaces `getCountryCode` with `countryCode`. + ## 0.3.4+1 * Adds documentation for UserChoice and Alternative Billing. diff --git a/packages/in_app_purchase/in_app_purchase_android/lib/src/in_app_purchase_android_platform.dart b/packages/in_app_purchase/in_app_purchase_android/lib/src/in_app_purchase_android_platform.dart index 9b9e2f1b1ea..afa6932776b 100644 --- a/packages/in_app_purchase/in_app_purchase_android/lib/src/in_app_purchase_android_platform.dart +++ b/packages/in_app_purchase/in_app_purchase_android/lib/src/in_app_purchase_android_platform.dart @@ -317,9 +317,14 @@ class InAppPurchaseAndroidPlatform extends InAppPurchasePlatform { /// /// See: https://developer.android.com/reference/com/android/billingclient/api/BillingConfig /// See: https://unicode.org/cldr/charts/latest/supplemental/territory_containment_un_m_49.html - Future getCountryCode() async { + @override + Future countryCode() async { final BillingConfigWrapper billingConfig = await billingClientManager .runWithClient((BillingClient client) => client.getBillingConfig()); return billingConfig.countryCode; } + + /// Use countryCode instead. + @Deprecated('Use countryCode') + Future getCountryCode() => countryCode(); } diff --git a/packages/in_app_purchase/in_app_purchase_android/pubspec.yaml b/packages/in_app_purchase/in_app_purchase_android/pubspec.yaml index 0e711948aef..b47cc1d5b12 100644 --- a/packages/in_app_purchase/in_app_purchase_android/pubspec.yaml +++ b/packages/in_app_purchase/in_app_purchase_android/pubspec.yaml @@ -2,7 +2,7 @@ name: in_app_purchase_android description: An implementation for the Android platform of the Flutter `in_app_purchase` plugin. This uses the Android BillingClient APIs. repository: https://github.com/flutter/packages/tree/main/packages/in_app_purchase/in_app_purchase_android issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+in_app_purchase%22 -version: 0.3.4+1 +version: 0.3.5 environment: sdk: ^3.1.0 diff --git a/packages/in_app_purchase/in_app_purchase_android/test/in_app_purchase_android_platform_test.dart b/packages/in_app_purchase/in_app_purchase_android/test/in_app_purchase_android_platform_test.dart index c5e5d628ef8..ee183eeba71 100644 --- a/packages/in_app_purchase/in_app_purchase_android/test/in_app_purchase_android_platform_test.dart +++ b/packages/in_app_purchase/in_app_purchase_android/test/in_app_purchase_android_platform_test.dart @@ -760,9 +760,12 @@ void main() { when(mockApi.getBillingConfigAsync()) .thenAnswer((_) async => platformBillingConfigFromWrapper(expected)); - final String countryCode = await iapAndroidPlatform.getCountryCode(); + final String countryCode = await iapAndroidPlatform.countryCode(); expect(countryCode, equals(expectedCountryCode)); + // Ensure deprecated code keeps working until removed. + expect(await iapAndroidPlatform.getCountryCode(), + equals(expectedCountryCode)); }); }); } diff --git a/packages/in_app_purchase/in_app_purchase_storekit/CHANGELOG.md b/packages/in_app_purchase/in_app_purchase_storekit/CHANGELOG.md index 114dc9e8df5..46c455c8093 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/CHANGELOG.md +++ b/packages/in_app_purchase/in_app_purchase_storekit/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.3.15 + +* Replaces `getCountryCode` with `countryCode`. + ## 0.3.14 * Adds `countryCode` API. diff --git a/packages/in_app_purchase/in_app_purchase_storekit/lib/src/in_app_purchase_storekit_platform.dart b/packages/in_app_purchase/in_app_purchase_storekit/lib/src/in_app_purchase_storekit_platform.dart index acdc4a2979c..713a8c909e6 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/lib/src/in_app_purchase_storekit_platform.dart +++ b/packages/in_app_purchase/in_app_purchase_storekit/lib/src/in_app_purchase_storekit_platform.dart @@ -158,9 +158,14 @@ class InAppPurchaseStoreKitPlatform extends InAppPurchasePlatform { /// /// Uses the ISO 3166-1 Alpha-3 country code representation. /// See: https://developer.apple.com/documentation/storekit/skstorefront?language=objc - Future getCountryCode() async { - return (await _skPaymentQueueWrapper.storefront())?.countryCode; + @override + Future countryCode() async { + return (await _skPaymentQueueWrapper.storefront())?.countryCode ?? ''; } + + /// Use countryCode instead. + @Deprecated('Use countryCode') + Future getCountryCode() => countryCode(); } enum _TransactionRestoreState { diff --git a/packages/in_app_purchase/in_app_purchase_storekit/pubspec.yaml b/packages/in_app_purchase/in_app_purchase_storekit/pubspec.yaml index d20cdec6ff1..a2b005787b3 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/pubspec.yaml +++ b/packages/in_app_purchase/in_app_purchase_storekit/pubspec.yaml @@ -2,7 +2,7 @@ name: in_app_purchase_storekit description: An implementation for the iOS and macOS platforms of the Flutter `in_app_purchase` plugin. This uses the StoreKit Framework. repository: https://github.com/flutter/packages/tree/main/packages/in_app_purchase/in_app_purchase_storekit issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+in_app_purchase%22 -version: 0.3.14 +version: 0.3.15 environment: sdk: ^3.2.3 diff --git a/packages/in_app_purchase/in_app_purchase_storekit/test/in_app_purchase_storekit_platform_test.dart b/packages/in_app_purchase/in_app_purchase_storekit/test/in_app_purchase_storekit_platform_test.dart index 97d13509fdb..56dc89fb190 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/test/in_app_purchase_storekit_platform_test.dart +++ b/packages/in_app_purchase/in_app_purchase_storekit/test/in_app_purchase_storekit_platform_test.dart @@ -576,8 +576,10 @@ void main() { const String expectedCountryCode = 'CA'; fakeStoreKitPlatform.setStoreFrontInfo( countryCode: expectedCountryCode, identifier: 'ABC'); - final String? countryCode = await iapStoreKitPlatform.getCountryCode(); + final String countryCode = await iapStoreKitPlatform.countryCode(); expect(countryCode, expectedCountryCode); + // Ensure deprecated code keeps working until removed. + expect(await iapStoreKitPlatform.countryCode(), expectedCountryCode); }); }); } diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index fb01483089c..59a4bd93380 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,3 +1,9 @@ +## 18.0.1 + +* Fixes unnecessary calls of `toList` and `fromList` when encoding/decoding data classes. +* [kotlin] Changes to some code to make it more idiomatic. +* Removes collisions with the word `list`. + ## 18.0.0 * Adds message channel suffix option to all APIs. diff --git a/packages/pigeon/example/app/android/app/src/main/java/io/flutter/plugins/Messages.java b/packages/pigeon/example/app/android/app/src/main/java/io/flutter/plugins/Messages.java index 897f40e9bee..f8029ebcd92 100644 --- a/packages/pigeon/example/app/android/app/src/main/java/io/flutter/plugins/Messages.java +++ b/packages/pigeon/example/app/android/app/src/main/java/io/flutter/plugins/Messages.java @@ -186,15 +186,15 @@ ArrayList toList() { return toListResult; } - static @NonNull MessageData fromList(@NonNull ArrayList list) { + static @NonNull MessageData fromList(@NonNull ArrayList __pigeon_list) { MessageData pigeonResult = new MessageData(); - Object name = list.get(0); + Object name = __pigeon_list.get(0); pigeonResult.setName((String) name); - Object description = list.get(1); + Object description = __pigeon_list.get(1); pigeonResult.setDescription((String) description); - Object code = list.get(2); + Object code = __pigeon_list.get(2); pigeonResult.setCode(Code.values()[(int) code]); - Object data = list.get(3); + Object data = __pigeon_list.get(3); pigeonResult.setData((Map) data); return pigeonResult; } diff --git a/packages/pigeon/example/app/android/app/src/main/kotlin/dev/flutter/pigeon_example_app/Messages.g.kt b/packages/pigeon/example/app/android/app/src/main/kotlin/dev/flutter/pigeon_example_app/Messages.g.kt index 350895738d6..48981666f24 100644 --- a/packages/pigeon/example/app/android/app/src/main/kotlin/dev/flutter/pigeon_example_app/Messages.g.kt +++ b/packages/pigeon/example/app/android/app/src/main/kotlin/dev/flutter/pigeon_example_app/Messages.g.kt @@ -3,6 +3,7 @@ // found in the LICENSE file. // Autogenerated from Pigeon, do not edit directly. // See also: https://pub.dev/packages/pigeon +@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass") import android.util.Log import io.flutter.plugin.common.BasicMessageChannel @@ -17,10 +18,10 @@ private fun wrapResult(result: Any?): List { } private fun wrapError(exception: Throwable): List { - if (exception is FlutterError) { - return listOf(exception.code, exception.message, exception.details) + return if (exception is FlutterError) { + listOf(exception.code, exception.message, exception.details) } else { - return listOf( + listOf( exception.javaClass.simpleName, exception.toString(), "Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception)) @@ -64,12 +65,12 @@ data class MessageData( val data: Map ) { companion object { - @Suppress("UNCHECKED_CAST") - fun fromList(list: List): MessageData { - val name = list[0] as String? - val description = list[1] as String? - val code = Code.ofRaw(list[2] as Int)!! - val data = list[3] as Map + @Suppress("LocalVariableName") + fun fromList(__pigeon_list: List): MessageData { + val name = __pigeon_list[0] as String? + val description = __pigeon_list[1] as String? + val code = Code.ofRaw(__pigeon_list[2] as Int)!! + val data = __pigeon_list[3] as Map return MessageData(name, description, code, data) } } @@ -84,7 +85,6 @@ data class MessageData( } } -@Suppress("UNCHECKED_CAST") private object ExampleHostApiCodec : StandardMessageCodec() { override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { return when (type) { @@ -118,7 +118,6 @@ interface ExampleHostApi { /** The codec used by ExampleHostApi. */ val codec: MessageCodec by lazy { ExampleHostApiCodec } /** Sets up an instance of `ExampleHostApi` to handle messages through the `binaryMessenger`. */ - @Suppress("UNCHECKED_CAST") fun setUp( binaryMessenger: BinaryMessenger, api: ExampleHostApi?, @@ -134,12 +133,12 @@ interface ExampleHostApi { codec) if (api != null) { channel.setMessageHandler { _, reply -> - var wrapped: List - try { - wrapped = listOf(api.getHostLanguage()) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.getHostLanguage()) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -155,14 +154,14 @@ interface ExampleHostApi { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List - val aArg = args[0].let { if (it is Int) it.toLong() else it as Long } - val bArg = args[1].let { if (it is Int) it.toLong() else it as Long } - var wrapped: List - try { - wrapped = listOf(api.add(aArg, bArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val aArg = args[0].let { num -> if (num is Int) num.toLong() else num as Long } + val bArg = args[1].let { num -> if (num is Int) num.toLong() else num as Long } + val wrapped: List = + try { + listOf(api.add(aArg, bArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -197,7 +196,6 @@ interface ExampleHostApi { } } /** Generated class from Pigeon that represents Flutter messages that can be called from Kotlin. */ -@Suppress("UNCHECKED_CAST") class MessageFlutterApi( private val binaryMessenger: BinaryMessenger, private val messageChannelSuffix: String = "" diff --git a/packages/pigeon/example/app/ios/Runner/Messages.g.swift b/packages/pigeon/example/app/ios/Runner/Messages.g.swift index 313c1974e02..7155583cfab 100644 --- a/packages/pigeon/example/app/ios/Runner/Messages.g.swift +++ b/packages/pigeon/example/app/ios/Runner/Messages.g.swift @@ -60,11 +60,12 @@ struct MessageData { var code: Code var data: [String?: String?] - static func fromList(_ list: [Any?]) -> MessageData? { - let name: String? = nilOrValue(list[0]) - let description: String? = nilOrValue(list[1]) - let code = Code(rawValue: list[2] as! Int)! - let data = list[3] as! [String?: String?] + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ __pigeon_list: [Any?]) -> MessageData? { + let name: String? = nilOrValue(__pigeon_list[0]) + let description: String? = nilOrValue(__pigeon_list[1]) + let code = Code(rawValue: __pigeon_list[2] as! Int)! + let data = __pigeon_list[3] as! [String?: String?] return MessageData( name: name, diff --git a/packages/pigeon/lib/ast.dart b/packages/pigeon/lib/ast.dart index 08eef8cc6c7..d7bc2139729 100644 --- a/packages/pigeon/lib/ast.dart +++ b/packages/pigeon/lib/ast.dart @@ -518,7 +518,7 @@ class TypeDeclaration { @override String toString() { final String typeArgumentsStr = - typeArguments.isEmpty ? '' : 'typeArguments:$typeArguments'; + typeArguments.isEmpty ? '' : ' typeArguments:$typeArguments'; return '(TypeDeclaration baseName:$baseName isNullable:$isNullable$typeArgumentsStr isEnum:$isEnum isClass:$isClass isProxyApi:$isProxyApi)'; } } diff --git a/packages/pigeon/lib/cpp_generator.dart b/packages/pigeon/lib/cpp_generator.dart index 92d6fd56d1f..00a156b0c5d 100644 --- a/packages/pigeon/lib/cpp_generator.dart +++ b/packages/pigeon/lib/cpp_generator.dart @@ -787,8 +787,12 @@ class CppSourceGenerator extends StructuredGenerator { final HostDatatype hostDatatype = getFieldHostDatatype(field, _shortBaseCppTypeForBuiltinDartType); final String encodableValue = _wrappedHostApiArgumentExpression( - root, _makeInstanceVariableName(field), field.type, hostDatatype, - preSerializeClasses: true); + root, + _makeInstanceVariableName(field), + field.type, + hostDatatype, + true, + ); indent.writeln('list.push_back($encodableValue);'); } indent.writeln('return list;'); @@ -815,11 +819,8 @@ class CppSourceGenerator extends StructuredGenerator { } else { final HostDatatype hostDatatype = getFieldHostDatatype(field, _shortBaseCppTypeForBuiltinDartType); - if (!hostDatatype.isBuiltin && - root.classes - .map((Class x) => x.name) - .contains(field.type.baseName)) { - return '${hostDatatype.datatype}::FromEncodableList(std::get($encodable))'; + if (field.type.isClass) { + return _classReferenceFromEncodableValue(hostDatatype, encodable); } else { return 'std::get<${hostDatatype.datatype}>($encodable)'; } @@ -960,8 +961,12 @@ class CppSourceGenerator extends StructuredGenerator { indent.addScoped('EncodableValue(EncodableList{', '});', () { for (final _HostNamedType param in hostParameters) { final String encodedArgument = _wrappedHostApiArgumentExpression( - root, param.name, param.originalType, param.hostType, - preSerializeClasses: false); + root, + param.name, + param.originalType, + param.hostType, + false, + ); indent.writeln('$encodedArgument,'); } }); @@ -1452,27 +1457,20 @@ ${prefix}reply(EncodableValue(std::move(wrapped)));'''; /// Returns the expression to create an EncodableValue from a host API argument /// with the given [variableName] and types. - /// - /// If [preSerializeClasses] is true, custom classes will be returned as - /// encodable lists rather than CustomEncodableValues; see - /// https://github.com/flutter/flutter/issues/119351 for why this is currently - /// needed. - String _wrappedHostApiArgumentExpression(Root root, String variableName, - TypeDeclaration dartType, HostDatatype hostType, - {required bool preSerializeClasses}) { + String _wrappedHostApiArgumentExpression( + Root root, + String variableName, + TypeDeclaration dartType, + HostDatatype hostType, + bool isNestedClass, + ) { final String encodableValue; if (!hostType.isBuiltin && root.classes.any((Class c) => c.name == dartType.baseName)) { - if (preSerializeClasses) { - final String operator = - hostType.isNullable || _isPointerField(hostType) ? '->' : '.'; - encodableValue = - 'EncodableValue($variableName${operator}ToEncodableList())'; - } else { - final String nonNullValue = - hostType.isNullable ? '*$variableName' : variableName; - encodableValue = 'CustomEncodableValue($nonNullValue)'; - } + final String nonNullValue = hostType.isNullable || isNestedClass + ? '*$variableName' + : variableName; + encodableValue = 'CustomEncodableValue($nonNullValue)'; } else if (!hostType.isBuiltin && root.enums.any((Enum e) => e.name == dartType.baseName)) { final String nonNullValue = @@ -1537,7 +1535,7 @@ ${prefix}reply(EncodableValue(std::move(wrapped)));'''; } } else { indent.writeln( - 'const auto* $argName = &(std::any_cast(std::get($encodableArgName)));'); + 'const auto* $argName = &(${_classReferenceFromEncodableValue(hostType, encodableArgName)});'); } } else { // Non-nullable arguments are either passed by value or reference, but the @@ -1562,7 +1560,7 @@ ${prefix}reply(EncodableValue(std::move(wrapped)));'''; 'const ${hostType.datatype}& $argName = (${hostType.datatype})$encodableArgName.LongValue();'); } else { indent.writeln( - 'const auto& $argName = std::any_cast(std::get($encodableArgName));'); + 'const auto& $argName = ${_classReferenceFromEncodableValue(hostType, encodableArgName)};'); } } } @@ -1573,6 +1571,13 @@ ${prefix}reply(EncodableValue(std::move(wrapped)));'''; String? _shortBaseCppTypeForBuiltinDartType(TypeDeclaration type) { return _baseCppTypeForBuiltinDartType(type, includeFlutterNamespace: false); } + + /// Returns the code to extract a `const {type.datatype}&` from an EncodableValue + /// variable [variableName] that contains an instance of [type]. + String _classReferenceFromEncodableValue( + HostDatatype type, String variableName) { + return 'std::any_cast(std::get($variableName))'; + } } /// Contains information about a host function argument. diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index adc0aef5cc9..0129ae4210d 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -230,11 +230,7 @@ class DartGenerator extends StructuredGenerator { for (final NamedType field in getFieldsInSerializationOrder(classDefinition)) { final String conditional = field.type.isNullable ? '?' : ''; - if (field.type.isClass) { - indent.writeln( - '${field.name}$conditional.encode(),', - ); - } else if (field.type.isEnum) { + if (field.type.isEnum) { indent.writeln( '${field.name}$conditional.index,', ); @@ -260,18 +256,7 @@ class DartGenerator extends StructuredGenerator { final String genericType = _makeGenericTypeArguments(field.type); final String castCall = _makeGenericCastCall(field.type); final String nullableTag = field.type.isNullable ? '?' : ''; - if (field.type.isClass) { - final String nonNullValue = - '${field.type.baseName}.decode($resultAt! as List)'; - if (field.type.isNullable) { - indent.format(''' -$resultAt != null -\t\t? $nonNullValue -\t\t: null''', leadingSpace: false, trailingNewline: false); - } else { - indent.add(nonNullValue); - } - } else if (field.type.isEnum) { + if (field.type.isEnum) { final String nonNullValue = '${field.type.baseName}.values[$resultAt! as int]'; if (field.type.isNullable) { @@ -512,7 +497,7 @@ final BinaryMessenger? ${_varNamePrefix}binaryMessenger; // Each API has a private codec instance used by every host method, // constructor, or non-static field. - final String codecInstanceName = '${_varNamePrefix}codec${api.name}'; + final String codecInstanceName = '${varNamePrefix}codec${api.name}'; // AST class used by code_builder to generate the code. final cb.Class proxyApi = cb.Class( @@ -795,15 +780,15 @@ PlatformException _createConnectionError(String channelName) { indent.writeln( "$constOrFinal String ${_varNamePrefix}channelName = '$channelName$channelSuffix';"); indent.writeScoped( - 'final BasicMessageChannel ${_varNamePrefix}channel = BasicMessageChannel(', + 'final BasicMessageChannel ${varNamePrefix}channel = BasicMessageChannel(', ');', () { - indent.writeln('${_varNamePrefix}channelName,'); + indent.writeln('${varNamePrefix}channelName,'); indent.writeln('$_pigeonChannelCodec,'); - indent.writeln('binaryMessenger: ${_varNamePrefix}binaryMessenger,'); + indent.writeln('binaryMessenger: ${varNamePrefix}binaryMessenger,'); }); final String returnTypeName = _makeGenericTypeArguments(returnType); final String genericCastCall = _makeGenericCastCall(returnType); - const String accessor = '${_varNamePrefix}replyList[0]'; + const String accessor = '${varNamePrefix}replyList[0]'; // Avoid warnings from pointlessly casting to `Object?`. final String nullablyTypedAccessor = returnTypeName == 'Object' ? accessor @@ -826,22 +811,22 @@ PlatformException _createConnectionError(String channelName) { returnStatement = '$returnStatement;'; indent.format(''' -final List? ${_varNamePrefix}replyList = -\t\tawait ${_varNamePrefix}channel.send($sendArgument) as List?; -if (${_varNamePrefix}replyList == null) { -\tthrow _createConnectionError(${_varNamePrefix}channelName); -} else if (${_varNamePrefix}replyList.length > 1) { +final List? ${varNamePrefix}replyList = +\t\tawait ${varNamePrefix}channel.send($sendArgument) as List?; +if (${varNamePrefix}replyList == null) { +\tthrow _createConnectionError(${varNamePrefix}channelName); +} else if (${varNamePrefix}replyList.length > 1) { \tthrow PlatformException( -\t\tcode: ${_varNamePrefix}replyList[0]! as String, -\t\tmessage: ${_varNamePrefix}replyList[1] as String?, -\t\tdetails: ${_varNamePrefix}replyList[2], +\t\tcode: ${varNamePrefix}replyList[0]! as String, +\t\tmessage: ${varNamePrefix}replyList[1] as String?, +\t\tdetails: ${varNamePrefix}replyList[2], \t);'''); // On iOS we can return nil from functions to accommodate error // handling. Returning a nil value and not returning an error is an // exception. if (!returnType.isNullable && !returnType.isVoid) { indent.format(''' -} else if (${_varNamePrefix}replyList[0] == null) { +} else if (${varNamePrefix}replyList[0] == null) { \tthrow PlatformException( \t\tcode: 'null-error', \t\tmessage: 'Host platform returned null value for non-null return value.', @@ -870,7 +855,7 @@ if (${_varNamePrefix}replyList == null) { indent.write(''); indent.addScoped('{', '}', () { indent.writeln( - 'final BasicMessageChannel ${_varNamePrefix}channel = BasicMessageChannel(', + 'final BasicMessageChannel ${varNamePrefix}channel = BasicMessageChannel(', ); indent.nest(2, () { final String channelSuffix = @@ -881,8 +866,8 @@ if (${_varNamePrefix}replyList == null) { ); }); final String messageHandlerSetterWithOpeningParentheses = isMockHandler - ? '_testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(${_varNamePrefix}channel, ' - : '${_varNamePrefix}channel.setMessageHandler('; + ? '_testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(${varNamePrefix}channel, ' + : '${varNamePrefix}channel.setMessageHandler('; indent.write('if ($nullHandlerExpression) '); indent.addScoped('{', '}', () { indent.writeln('${messageHandlerSetterWithOpeningParentheses}null);'); @@ -1079,7 +1064,7 @@ if (${_varNamePrefix}replyList == null) { channelName: channelName, parameters: [ Parameter( - name: '${_varNamePrefix}instanceIdentifier', + name: '${varNamePrefix}instanceIdentifier', type: const TypeDeclaration( baseName: 'int', isNullable: false, @@ -1098,12 +1083,12 @@ if (${_varNamePrefix}replyList == null) { builder.statements.addAll([ const cb.Code( - 'final int ${_varNamePrefix}instanceIdentifier = $_instanceManagerVarName.addDartCreatedInstance(this);', + 'final int ${varNamePrefix}instanceIdentifier = $_instanceManagerVarName.addDartCreatedInstance(this);', ), cb.Code('final $codecName $_pigeonChannelCodec =\n' ' $codecInstanceName;'), cb.Code( - 'final BinaryMessenger? ${_varNamePrefix}binaryMessenger = ${binaryMessengerParameter.name};', + 'final BinaryMessenger? ${varNamePrefix}binaryMessenger = ${binaryMessengerParameter.name};', ), const cb.Code('() async {'), cb.Code(messageCallSink.toString()), @@ -1356,7 +1341,7 @@ if (${_varNamePrefix}replyList == null) { field.documentationComments, _docCommentSpec, )) - ..assignment = cb.Code('$_varNamePrefix${field.name}()'), + ..assignment = cb.Code('$varNamePrefix${field.name}()'), ); } } @@ -1581,11 +1566,11 @@ if (${_varNamePrefix}replyList == null) { yield cb.Method( (cb.MethodBuilder builder) { final String type = _addGenericTypesNullable(field.type); - const String instanceName = '${_varNamePrefix}instance'; + const String instanceName = '${varNamePrefix}instance'; const String identifierInstanceName = - '${_varNamePrefix}instanceIdentifier'; + '${varNamePrefix}instanceIdentifier'; builder - ..name = '$_varNamePrefix${field.name}' + ..name = '$varNamePrefix${field.name}' ..static = field.isStatic ..returns = cb.refer(type) ..body = cb.Block( @@ -1629,7 +1614,7 @@ if (${_varNamePrefix}replyList == null) { cb.Code('final $codecName $_pigeonChannelCodec =\n' ' $codecInstanceName;'), const cb.Code( - 'final BinaryMessenger? ${_varNamePrefix}binaryMessenger = ${classMemberNamePrefix}binaryMessenger;', + 'final BinaryMessenger? ${varNamePrefix}binaryMessenger = ${classMemberNamePrefix}binaryMessenger;', ), const cb.Code( 'final int $identifierInstanceName = $_instanceManagerVarName.addDartCreatedInstance($instanceName);', @@ -1642,7 +1627,7 @@ if (${_varNamePrefix}replyList == null) { 'final $codecName $_pigeonChannelCodec = $codecName($instanceManagerClassName.instance);', ), const cb.Code( - 'final BinaryMessenger ${_varNamePrefix}binaryMessenger = ServicesBinding.instance.defaultBinaryMessenger;', + 'final BinaryMessenger ${varNamePrefix}binaryMessenger = ServicesBinding.instance.defaultBinaryMessenger;', ), const cb.Code( 'final int $identifierInstanceName = $instanceManagerClassName.instance.addDartCreatedInstance($instanceName);', @@ -1743,7 +1728,7 @@ if (${_varNamePrefix}replyList == null) { 'final $codecName $_pigeonChannelCodec = $codecName($_instanceManagerVarName ?? $instanceManagerClassName.instance);', ), const cb.Code( - 'final BinaryMessenger? ${_varNamePrefix}binaryMessenger = ${classMemberNamePrefix}binaryMessenger;', + 'final BinaryMessenger? ${varNamePrefix}binaryMessenger = ${classMemberNamePrefix}binaryMessenger;', ), cb.Code(messageCallSink.toString()), ]); diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index 76c9abf1886..98f27ad0fec 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -13,7 +13,13 @@ import 'ast.dart'; /// The current version of pigeon. /// /// This must match the version in pubspec.yaml. -const String pigeonVersion = '18.0.0'; +const String pigeonVersion = '18.0.1'; + +/// Prefix for all local variables in methods. +/// +/// This lowers the chances of variable name collisions with +/// user defined parameters. +const String varNamePrefix = '__pigeon_'; /// Read all the content from [stdin] to a String. String readStdin() { diff --git a/packages/pigeon/lib/java_generator.dart b/packages/pigeon/lib/java_generator.dart index 5e8fbb2c045..f8e15bb24f9 100644 --- a/packages/pigeon/lib/java_generator.dart +++ b/packages/pigeon/lib/java_generator.dart @@ -341,9 +341,7 @@ class JavaGenerator extends StructuredGenerator { in getFieldsInSerializationOrder(classDefinition)) { String toWriteValue = ''; final String fieldName = field.name; - if (field.type.isClass) { - toWriteValue = '($fieldName == null) ? null : $fieldName.toList()'; - } else if (field.type.isEnum) { + if (field.type.isEnum) { toWriteValue = '$fieldName == null ? null : $fieldName.index'; } else { toWriteValue = field.name; @@ -364,7 +362,7 @@ class JavaGenerator extends StructuredGenerator { }) { indent.newln(); indent.write( - 'static @NonNull ${classDefinition.name} fromList(@NonNull ArrayList list) '); + 'static @NonNull ${classDefinition.name} fromList(@NonNull ArrayList ${varNamePrefix}list) '); indent.addScoped('{', '}', () { const String result = 'pigeonResult'; indent.writeln( @@ -373,7 +371,8 @@ class JavaGenerator extends StructuredGenerator { (int index, final NamedType field) { final String fieldVariable = field.name; final String setter = _makeSetter(field); - indent.writeln('Object $fieldVariable = list.get($index);'); + indent.writeln( + 'Object $fieldVariable = ${varNamePrefix}list.get($index);'); if (field.type.isEnum) { indent.writeln( '$result.$setter(${_intToEnum(fieldVariable, field.type.baseName, field.type.isNullable)});'); @@ -1123,8 +1122,6 @@ String _castObject(NamedType field, String varName) { field, (TypeDeclaration x) => _javaTypeForBuiltinDartType(x)); if (field.type.baseName == 'int') { return '($varName == null) ? null : (($varName instanceof Integer) ? (Integer) $varName : (${hostDatatype.datatype}) $varName)'; - } else if (field.type.isClass) { - return '($varName == null) ? null : ${hostDatatype.datatype}.fromList((ArrayList) $varName)'; } else { return _cast(varName, javaType: hostDatatype.datatype); } diff --git a/packages/pigeon/lib/kotlin_generator.dart b/packages/pigeon/lib/kotlin_generator.dart index c81df1295ed..18df439d740 100644 --- a/packages/pigeon/lib/kotlin_generator.dart +++ b/packages/pigeon/lib/kotlin_generator.dart @@ -97,6 +97,7 @@ class KotlinGenerator extends StructuredGenerator { } indent.writeln('// ${getGeneratedCodeWarning()}'); indent.writeln('// $seeAlsoWarning'); + indent.writeln('@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass")'); } @override @@ -174,7 +175,6 @@ class KotlinGenerator extends StructuredGenerator { addDocumentationComments( indent, classDefinition.documentationComments, _docCommentSpec, generatorComments: generatedMessages); - indent.write('data class ${classDefinition.name} '); indent.addScoped('(', '', () { for (final NamedType element @@ -220,13 +220,10 @@ class KotlinGenerator extends StructuredGenerator { indent.addScoped('(', ')', () { for (final NamedType field in getFieldsInSerializationOrder(classDefinition)) { - final HostDatatype hostDatatype = _getHostDatatype(root, field); String toWriteValue = ''; final String fieldName = field.name; final String safeCall = field.type.isNullable ? '?' : ''; - if (field.type.isClass) { - toWriteValue = '$fieldName$safeCall.toList()'; - } else if (!hostDatatype.isBuiltin && field.type.isEnum) { + if (field.type.isEnum) { toWriteValue = '$fieldName$safeCall.raw'; } else { toWriteValue = fieldName; @@ -249,37 +246,29 @@ class KotlinGenerator extends StructuredGenerator { indent.write('companion object '); indent.addScoped('{', '}', () { - indent.writeln('@Suppress("UNCHECKED_CAST")'); - indent.write('fun fromList(list: List): $className '); + indent.writeln('@Suppress("LocalVariableName")'); + indent + .write('fun fromList(${varNamePrefix}list: List): $className '); indent.addScoped('{', '}', () { enumerate(getFieldsInSerializationOrder(classDefinition), (int index, final NamedType field) { - final String listValue = 'list[$index]'; + final String listValue = '${varNamePrefix}list[$index]'; final String fieldType = _kotlinTypeForDartType(field.type); if (field.type.isNullable) { - if (field.type.isClass) { - indent.write('val ${field.name}: $fieldType? = '); - indent.add('($listValue as List?)?.let '); - indent.addScoped('{', '}', () { - indent.writeln('$fieldType.fromList(it)'); - }); - } else if (field.type.isEnum) { + if (field.type.isEnum) { indent.write('val ${field.name}: $fieldType? = '); indent.add('($listValue as Int?)?.let '); - indent.addScoped('{', '}', () { - indent.writeln('$fieldType.ofRaw(it)'); + indent.addScoped('{ num ->', '}', () { + indent.writeln('$fieldType.ofRaw(num)'); }); } else { indent.writeln( 'val ${field.name} = ${_cast(indent, listValue, type: field.type)}'); } } else { - if (field.type.isClass) { - indent.writeln( - 'val ${field.name} = $fieldType.fromList($listValue as List)'); - } else if (field.type.isEnum) { + if (field.type.isEnum) { indent.writeln( 'val ${field.name} = $fieldType.ofRaw($listValue as Int)!!'); } else { @@ -353,7 +342,6 @@ class KotlinGenerator extends StructuredGenerator { generatorComments: generatedMessages); final String apiName = api.name; - indent.writeln('@Suppress("UNCHECKED_CAST")'); indent.write( 'class $apiName(private val binaryMessenger: BinaryMessenger, private val messageChannelSuffix: String = "") '); indent.addScoped('{', '}', () { @@ -442,7 +430,6 @@ class KotlinGenerator extends StructuredGenerator { }); indent.writeln( '/** Sets up an instance of `$apiName` to handle messages through the `binaryMessenger`. */'); - indent.writeln('@Suppress("UNCHECKED_CAST")'); indent.write( 'fun setUp(binaryMessenger: BinaryMessenger, api: $apiName?, messageChannelSuffix: String = "") '); indent.addScoped('{', '}', () { @@ -472,7 +459,6 @@ class KotlinGenerator extends StructuredGenerator { assert(getCodecClasses(api, root).isNotEmpty); final Iterable codecClasses = getCodecClasses(api, root); final String codecName = _getCodecName(api); - indent.writeln('@Suppress("UNCHECKED_CAST")'); indent.write('private object $codecName : StandardMessageCodec() '); indent.addScoped('{', '}', () { indent.write( @@ -524,19 +510,17 @@ class KotlinGenerator extends StructuredGenerator { indent.newln(); indent.write('private fun wrapError(exception: Throwable): List '); indent.addScoped('{', '}', () { - indent - .write('if (exception is ${_getErrorClassName(generatorOptions)}) '); + indent.write( + 'return if (exception is ${_getErrorClassName(generatorOptions)}) '); indent.addScoped('{', '}', () { - indent.write('return '); - indent.addScoped('listOf(', ')', () { + indent.writeScoped('listOf(', ')', () { indent.writeln('exception.code,'); indent.writeln('exception.message,'); indent.writeln('exception.details'); }); }, addTrailingNewline: false); indent.addScoped(' else {', '}', () { - indent.write('return '); - indent.addScoped('listOf(', ')', () { + indent.writeScoped('listOf(', ')', () { indent.writeln('exception.javaClass.simpleName,'); indent.writeln('exception.toString(),'); indent.writeln( @@ -731,24 +715,22 @@ class KotlinGenerator extends StructuredGenerator { }); }); } else { - indent.writeln('var wrapped: List'); - indent.write('try '); - indent.addScoped('{', '}', () { + indent.writeScoped('val wrapped: List = try {', '}', () { if (returnType.isVoid) { indent.writeln(call); - indent.writeln('wrapped = listOf(null)'); + indent.writeln('listOf(null)'); } else { String enumTag = ''; if (returnType.isEnum) { final String safeUnwrap = returnType.isNullable ? '?' : ''; enumTag = '$safeUnwrap.raw'; } - indent.writeln('wrapped = listOf($call$enumTag)'); + indent.writeln('listOf($call$enumTag)'); } }, addTrailingNewline: false); indent.add(' catch (exception: Throwable) '); indent.addScoped('{', '}', () { - indent.writeln('wrapped = wrapError(exception)'); + indent.writeln('wrapError(exception)'); }); indent.writeln('reply.reply(wrapped)'); } @@ -839,9 +821,9 @@ class KotlinGenerator extends StructuredGenerator { const String output = 'output'; // Nullable enums require special handling. if (returnType.isEnum && returnType.isNullable) { - indent.writeScoped('val $output = (it[0] as Int?)?.let {', '}', - () { - indent.writeln('${returnType.baseName}.ofRaw(it)'); + indent.writeScoped( + 'val $output = (it[0] as Int?)?.let { num ->', '}', () { + indent.writeln('${returnType.baseName}.ofRaw(num)'); }); } else { indent.writeln( @@ -859,11 +841,6 @@ class KotlinGenerator extends StructuredGenerator { } } -HostDatatype _getHostDatatype(Root root, NamedType field) { - return getFieldHostDatatype( - field, (TypeDeclaration x) => _kotlinTypeForBuiltinDartType(x)); -} - /// Calculates the name of the codec that will be generated for [api]. String _getCodecName(Api api) => '${api.name}Codec'; @@ -971,8 +948,8 @@ String _cast(Indent indent, String variable, {required TypeDeclaration type}) { } if (type.isEnum) { if (type.isNullable) { - return '($variable as Int?)?.let {\n' - '${indent.str} $typeString.ofRaw(it)\n' + return '($variable as Int?)?.let { num ->\n' + '${indent.str} $typeString.ofRaw(num)\n' '${indent.str}}'; } return '${type.baseName}.ofRaw($variable as Int)!!'; @@ -982,5 +959,5 @@ String _cast(Indent indent, String variable, {required TypeDeclaration type}) { String _castInt(bool isNullable) { final String nullability = isNullable ? '?' : ''; - return '.let { if (it is Int) it.toLong() else it as Long$nullability }'; + return '.let { num -> if (num is Int) num.toLong() else num as Long$nullability }'; } diff --git a/packages/pigeon/lib/objc_generator.dart b/packages/pigeon/lib/objc_generator.dart index c40869a9b24..5e7784bf8ba 100644 --- a/packages/pigeon/lib/objc_generator.dart +++ b/packages/pigeon/lib/objc_generator.dart @@ -580,8 +580,7 @@ class ObjcSourceGenerator extends StructuredGenerator { enumerate(getFieldsInSerializationOrder(classDefinition), (int index, final NamedType field) { final bool isEnumType = field.type.isEnum; - final String valueGetter = - _listGetter('list', field, index, generatorOptions.prefix); + final String valueGetter = 'GetNullableObjectAtIndex(list, $index)'; final String? primitiveExtractionMethod = _nsnumberExtractionMethod(field.type); final String ivarValueExpression; @@ -1500,22 +1499,8 @@ String _makeObjcSignature({ /// provided [options]. void generateObjcHeader(ObjcOptions options, Root root, Indent indent) {} -String _listGetter(String list, NamedType field, int index, String? prefix) { - if (field.type.isClass) { - String className = field.type.baseName; - if (prefix != null) { - className = '$prefix$className'; - } - return '[$className nullableFromList:(GetNullableObjectAtIndex($list, $index))]'; - } else { - return 'GetNullableObjectAtIndex($list, $index)'; - } -} - String _arrayValue(NamedType field) { - if (field.type.isClass) { - return '(self.${field.name} ? [self.${field.name} toList] : [NSNull null])'; - } else if (field.type.isEnum) { + if (field.type.isEnum) { if (field.type.isNullable) { return '(self.${field.name} == nil ? [NSNull null] : [NSNumber numberWithInteger:self.${field.name}.value])'; } diff --git a/packages/pigeon/lib/swift_generator.dart b/packages/pigeon/lib/swift_generator.dart index 854c2c835f2..b644e561d5e 100644 --- a/packages/pigeon/lib/swift_generator.dart +++ b/packages/pigeon/lib/swift_generator.dart @@ -213,9 +213,7 @@ class SwiftGenerator extends StructuredGenerator { String toWriteValue = ''; final String fieldName = field.name; final String nullsafe = field.type.isNullable ? '?' : ''; - if (field.type.isClass) { - toWriteValue = '$fieldName$nullsafe.toList()'; - } else if (field.type.isEnum) { + if (field.type.isEnum) { toWriteValue = '$fieldName$nullsafe.rawValue'; } else { toWriteValue = field.name; @@ -236,12 +234,14 @@ class SwiftGenerator extends StructuredGenerator { required String dartPackageName, }) { final String className = classDefinition.name; - indent.write('static func fromList(_ list: [Any?]) -> $className? '); + indent.writeln('// swift-format-ignore: AlwaysUseLowerCamelCase'); + indent.write( + 'static func fromList(_ ${varNamePrefix}list: [Any?]) -> $className? '); indent.addScoped('{', '}', () { enumerate(getFieldsInSerializationOrder(classDefinition), (int index, final NamedType field) { - final String listValue = 'list[$index]'; + final String listValue = '${varNamePrefix}list[$index]'; _writeDecodeCasting( indent: indent, @@ -578,48 +578,23 @@ class SwiftGenerator extends StructuredGenerator { required TypeDeclaration type, }) { final String fieldType = _swiftTypeForDartType(type); - - if (type.isNullable) { - if (type.isClass) { - indent.writeln('var $variableName: $fieldType? = nil'); - indent - .write('if let ${variableName}List: [Any?] = nilOrValue($value) '); - indent.addScoped('{', '}', () { - indent.writeln( - '$variableName = $fieldType.fromList(${variableName}List)'); - }); - } else if (type.isEnum) { - indent.writeln('var $variableName: $fieldType? = nil'); + if (type.isNullable && type.isEnum) { + indent.writeln('var $variableName: $fieldType? = nil'); + indent.writeln( + 'let ${variableName}EnumVal: Int? = ${_castForceUnwrap(value, const TypeDeclaration(baseName: 'Int', isNullable: true))}'); + indent.write('if let ${variableName}RawValue = ${variableName}EnumVal '); + indent.addScoped('{', '}', () { indent.writeln( - 'let ${variableName}EnumVal: Int? = ${_castForceUnwrap(value, const TypeDeclaration(baseName: 'Int', isNullable: true))}'); - indent - .write('if let ${variableName}RawValue = ${variableName}EnumVal '); - indent.addScoped('{', '}', () { - indent.writeln( - '$variableName = $fieldType(rawValue: ${variableName}RawValue)!'); - }); - } else { - _writeGenericCasting( - indent: indent, - value: value, - variableName: variableName, - fieldType: fieldType, - type: type, - ); - } + '$variableName = $fieldType(rawValue: ${variableName}RawValue)!'); + }); } else { - if (type.isClass) { - indent.writeln( - 'let $variableName = $fieldType.fromList($value as! [Any?])!'); - } else { - _writeGenericCasting( - indent: indent, - value: value, - variableName: variableName, - fieldType: fieldType, - type: type, - ); - } + _writeGenericCasting( + indent: indent, + value: value, + variableName: variableName, + fieldType: fieldType, + type: type, + ); } } @@ -921,7 +896,8 @@ String _flattenTypeArguments(List args) { } String _swiftTypeForBuiltinGenericDartType(TypeDeclaration type) { - if (type.typeArguments.isEmpty) { + if (type.typeArguments.isEmpty || + (type.typeArguments.first.baseName == 'Object')) { if (type.baseName == 'List') { return '[Any?]'; } else if (type.baseName == 'Map') { diff --git a/packages/pigeon/pigeons/core_tests.dart b/packages/pigeon/pigeons/core_tests.dart index 3107bc55353..50f8d476014 100644 --- a/packages/pigeon/pigeons/core_tests.dart +++ b/packages/pigeon/pigeons/core_tests.dart @@ -23,7 +23,7 @@ class AllTypes { required this.a4ByteArray, required this.a8ByteArray, required this.aFloatArray, - this.aList = const [], + this.list = const [], this.aMap = const {}, this.anEnum = AnEnum.one, this.aString = '', @@ -38,8 +38,10 @@ class AllTypes { Int32List a4ByteArray; Int64List a8ByteArray; Float64List aFloatArray; + // This name is in a different format than the others to ensure that name + // collision with the work 'list' doesn't occur in the generated files. // ignore: always_specify_types, strict_raw_type - List aList; + List list; // ignore: always_specify_types, strict_raw_type Map aMap; AnEnum anEnum; @@ -204,7 +206,7 @@ abstract class HostIntegrationCoreApi { /// Returns the passed list, to test serialization and deserialization. @ObjCSelector('echoList:') @SwiftFunction('echo(_:)') - List echoList(List aList); + List echoList(List list); /// Returns the passed map, to test serialization and deserialization. @ObjCSelector('echoMap:') @@ -375,7 +377,7 @@ abstract class HostIntegrationCoreApi { @async @ObjCSelector('echoAsyncList:') @SwiftFunction('echoAsync(_:)') - List echoAsyncList(List aList); + List echoAsyncList(List list); /// Returns the passed map, to test asynchronous serialization and deserialization. @async @@ -462,7 +464,7 @@ abstract class HostIntegrationCoreApi { @async @ObjCSelector('echoAsyncNullableList:') @SwiftFunction('echoAsyncNullable(_:)') - List? echoAsyncNullableList(List? aList); + List? echoAsyncNullableList(List? list); /// Returns the passed map, to test asynchronous serialization and deserialization. @async @@ -543,12 +545,12 @@ abstract class HostIntegrationCoreApi { @async @ObjCSelector('callFlutterEchoUint8List:') @SwiftFunction('callFlutterEcho(_:)') - Uint8List callFlutterEchoUint8List(Uint8List aList); + Uint8List callFlutterEchoUint8List(Uint8List list); @async @ObjCSelector('callFlutterEchoList:') @SwiftFunction('callFlutterEcho(_:)') - List callFlutterEchoList(List aList); + List callFlutterEchoList(List list); @async @ObjCSelector('callFlutterEchoMap:') @@ -583,12 +585,12 @@ abstract class HostIntegrationCoreApi { @async @ObjCSelector('callFlutterEchoNullableUint8List:') @SwiftFunction('callFlutterEchoNullable(_:)') - Uint8List? callFlutterEchoNullableUint8List(Uint8List? aList); + Uint8List? callFlutterEchoNullableUint8List(Uint8List? list); @async @ObjCSelector('callFlutterEchoNullableList:') @SwiftFunction('callFlutterEchoNullable(_:)') - List? callFlutterEchoNullableList(List? aList); + List? callFlutterEchoNullableList(List? list); @async @ObjCSelector('callFlutterEchoNullableMap:') @@ -679,12 +681,12 @@ abstract class FlutterIntegrationCoreApi { /// Returns the passed byte list, to test serialization and deserialization. @ObjCSelector('echoUint8List:') @SwiftFunction('echo(_:)') - Uint8List echoUint8List(Uint8List aList); + Uint8List echoUint8List(Uint8List list); /// Returns the passed list, to test serialization and deserialization. @ObjCSelector('echoList:') @SwiftFunction('echo(_:)') - List echoList(List aList); + List echoList(List list); /// Returns the passed map, to test serialization and deserialization. @ObjCSelector('echoMap:') @@ -721,12 +723,12 @@ abstract class FlutterIntegrationCoreApi { /// Returns the passed byte list, to test serialization and deserialization. @ObjCSelector('echoNullableUint8List:') @SwiftFunction('echoNullable(_:)') - Uint8List? echoNullableUint8List(Uint8List? aList); + Uint8List? echoNullableUint8List(Uint8List? list); /// Returns the passed list, to test serialization and deserialization. @ObjCSelector('echoNullableList:') @SwiftFunction('echoNullable(_:)') - List? echoNullableList(List? aList); + List? echoNullableList(List? list); /// Returns the passed map, to test serialization and deserialization. @ObjCSelector('echoNullableMap:') diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/AlternateLanguageTestPlugin.java b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/AlternateLanguageTestPlugin.java index 04f60792293..ef8c5787338 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/AlternateLanguageTestPlugin.java +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/AlternateLanguageTestPlugin.java @@ -109,8 +109,8 @@ public void throwErrorFromVoid() { } @Override - public @NonNull List echoList(@NonNull List aList) { - return aList; + public @NonNull List echoList(@NonNull List list) { + return list; } @Override @@ -160,13 +160,11 @@ public void throwErrorFromVoid() { @Nullable Boolean aNullableBool, @Nullable Long aNullableInt, @Nullable String aNullableString) { - AllNullableTypes someThings = - new AllNullableTypes.Builder() - .setANullableBool(aNullableBool) - .setANullableInt(aNullableInt) - .setANullableString(aNullableString) - .build(); - return someThings; + return new AllNullableTypes.Builder() + .setANullableBool(aNullableBool) + .setANullableInt(aNullableInt) + .setANullableString(aNullableString) + .build(); } @Override @@ -174,13 +172,11 @@ public void throwErrorFromVoid() { @Nullable Boolean aNullableBool, @Nullable Long aNullableInt, @Nullable String aNullableString) { - AllNullableTypesWithoutRecursion someThings = - new AllNullableTypesWithoutRecursion.Builder() - .setANullableBool(aNullableBool) - .setANullableInt(aNullableInt) - .setANullableString(aNullableString) - .build(); - return someThings; + return new AllNullableTypesWithoutRecursion.Builder() + .setANullableBool(aNullableBool) + .setANullableInt(aNullableInt) + .setANullableString(aNullableString) + .build(); } @Override @@ -307,8 +303,8 @@ public void echoAsyncObject(@NonNull Object anObject, @NonNull Result re } @Override - public void echoAsyncList(@NonNull List aList, @NonNull Result> result) { - result.success(aList); + public void echoAsyncList(@NonNull List list, @NonNull Result> result) { + result.success(list); } @Override @@ -359,8 +355,8 @@ public void echoAsyncNullableObject( @Override public void echoAsyncNullableList( - @Nullable List aList, @NonNull NullableResult> result) { - result.success(aList); + @Nullable List list, @NonNull NullableResult> result) { + result.success(list); } @Override @@ -377,28 +373,33 @@ public void echoAsyncNullableEnum( @Override public void callFlutterNoop(@NonNull VoidResult result) { + assert flutterApi != null; flutterApi.noop(result); } @Override public void callFlutterThrowError(@NonNull NullableResult result) { + assert flutterApi != null; flutterApi.throwError(result); } @Override public void callFlutterThrowErrorFromVoid(@NonNull VoidResult result) { + assert flutterApi != null; flutterApi.throwErrorFromVoid(result); } @Override public void callFlutterEchoAllTypes( @NonNull AllTypes everything, @NonNull Result result) { + assert flutterApi != null; flutterApi.echoAllTypes(everything, result); } @Override public void callFlutterEchoAllNullableTypes( @Nullable AllNullableTypes everything, @NonNull NullableResult result) { + assert flutterApi != null; flutterApi.echoAllNullableTypes(everything, result); } @@ -408,6 +409,7 @@ public void callFlutterSendMultipleNullableTypes( @Nullable Long aNullableInt, @Nullable String aNullableString, @NonNull Result result) { + assert flutterApi != null; flutterApi.sendMultipleNullableTypes(aNullableBool, aNullableInt, aNullableString, result); } @@ -415,6 +417,7 @@ public void callFlutterSendMultipleNullableTypes( public void callFlutterEchoAllNullableTypesWithoutRecursion( @Nullable AllNullableTypesWithoutRecursion everything, @NonNull NullableResult result) { + assert flutterApi != null; flutterApi.echoAllNullableTypesWithoutRecursion(everything, result); } @@ -424,97 +427,114 @@ public void callFlutterSendMultipleNullableTypesWithoutRecursion( @Nullable Long aNullableInt, @Nullable String aNullableString, @NonNull Result result) { + assert flutterApi != null; flutterApi.sendMultipleNullableTypesWithoutRecursion( aNullableBool, aNullableInt, aNullableString, result); } @Override public void callFlutterEchoBool(@NonNull Boolean aBool, @NonNull Result result) { + assert flutterApi != null; flutterApi.echoBool(aBool, result); } @Override public void callFlutterEchoInt(@NonNull Long anInt, @NonNull Result result) { + assert flutterApi != null; flutterApi.echoInt(anInt, result); } @Override public void callFlutterEchoDouble(@NonNull Double aDouble, @NonNull Result result) { + assert flutterApi != null; flutterApi.echoDouble(aDouble, result); } @Override public void callFlutterEchoString(@NonNull String aString, @NonNull Result result) { + assert flutterApi != null; flutterApi.echoString(aString, result); } @Override - public void callFlutterEchoUint8List(@NonNull byte[] aList, @NonNull Result result) { - flutterApi.echoUint8List(aList, result); + public void callFlutterEchoUint8List(@NonNull byte[] list, @NonNull Result result) { + assert flutterApi != null; + flutterApi.echoUint8List(list, result); } @Override public void callFlutterEchoList( - @NonNull List aList, @NonNull Result> result) { - flutterApi.echoList(aList, result); + @NonNull List list, @NonNull Result> result) { + assert flutterApi != null; + flutterApi.echoList(list, result); } @Override public void callFlutterEchoMap( @NonNull Map aMap, @NonNull Result> result) { + assert flutterApi != null; flutterApi.echoMap(aMap, result); } @Override public void callFlutterEchoEnum(@NonNull AnEnum anEnum, @NonNull Result result) { + assert flutterApi != null; flutterApi.echoEnum(anEnum, result); } @Override public void callFlutterEchoNullableBool( @Nullable Boolean aBool, @NonNull NullableResult result) { + assert flutterApi != null; flutterApi.echoNullableBool(aBool, result); } @Override public void callFlutterEchoNullableInt( @Nullable Long anInt, @NonNull NullableResult result) { + assert flutterApi != null; flutterApi.echoNullableInt(anInt, result); } @Override public void callFlutterEchoNullableDouble( @Nullable Double aDouble, @NonNull NullableResult result) { + assert flutterApi != null; flutterApi.echoNullableDouble(aDouble, result); } @Override public void callFlutterEchoNullableString( @Nullable String aString, @NonNull NullableResult result) { + assert flutterApi != null; flutterApi.echoNullableString(aString, result); } @Override public void callFlutterEchoNullableUint8List( - @Nullable byte[] aList, @NonNull NullableResult result) { - flutterApi.echoNullableUint8List(aList, result); + @Nullable byte[] list, @NonNull NullableResult result) { + assert flutterApi != null; + flutterApi.echoNullableUint8List(list, result); } @Override public void callFlutterEchoNullableList( - @Nullable List aList, @NonNull NullableResult> result) { - flutterApi.echoNullableList(aList, result); + @Nullable List list, @NonNull NullableResult> result) { + assert flutterApi != null; + flutterApi.echoNullableList(list, result); } @Override public void callFlutterEchoNullableMap( @Nullable Map aMap, @NonNull NullableResult> result) { + assert flutterApi != null; flutterApi.echoNullableMap(aMap, result); } @Override public void callFlutterEchoNullableEnum( @Nullable AnEnum anEnum, @NonNull NullableResult result) { + assert flutterApi != null; flutterApi.echoNullableEnum(anEnum, result); } diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java index 1d5bde23a34..2c8f609bf78 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java @@ -198,17 +198,17 @@ public void setAFloatArray(@NonNull double[] setterArg) { this.aFloatArray = setterArg; } - private @NonNull List aList; + private @NonNull List list; - public @NonNull List getAList() { - return aList; + public @NonNull List getList() { + return list; } - public void setAList(@NonNull List setterArg) { + public void setList(@NonNull List setterArg) { if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"aList\" is null."); + throw new IllegalStateException("Nonnull field \"list\" is null."); } - this.aList = setterArg; + this.list = setterArg; } private @NonNull Map aMap; @@ -332,11 +332,11 @@ public static final class Builder { return this; } - private @Nullable List aList; + private @Nullable List list; @CanIgnoreReturnValue - public @NonNull Builder setAList(@NonNull List setterArg) { - this.aList = setterArg; + public @NonNull Builder setList(@NonNull List setterArg) { + this.list = setterArg; return this; } @@ -382,7 +382,7 @@ public static final class Builder { pigeonReturn.setA4ByteArray(a4ByteArray); pigeonReturn.setA8ByteArray(a8ByteArray); pigeonReturn.setAFloatArray(aFloatArray); - pigeonReturn.setAList(aList); + pigeonReturn.setList(list); pigeonReturn.setAMap(aMap); pigeonReturn.setAnEnum(anEnum); pigeonReturn.setAString(aString); @@ -402,7 +402,7 @@ ArrayList toList() { toListResult.add(a4ByteArray); toListResult.add(a8ByteArray); toListResult.add(aFloatArray); - toListResult.add(aList); + toListResult.add(list); toListResult.add(aMap); toListResult.add(anEnum == null ? null : anEnum.index); toListResult.add(aString); @@ -410,37 +410,37 @@ ArrayList toList() { return toListResult; } - static @NonNull AllTypes fromList(@NonNull ArrayList list) { + static @NonNull AllTypes fromList(@NonNull ArrayList __pigeon_list) { AllTypes pigeonResult = new AllTypes(); - Object aBool = list.get(0); + Object aBool = __pigeon_list.get(0); pigeonResult.setABool((Boolean) aBool); - Object anInt = list.get(1); + Object anInt = __pigeon_list.get(1); pigeonResult.setAnInt( (anInt == null) ? null : ((anInt instanceof Integer) ? (Integer) anInt : (Long) anInt)); - Object anInt64 = list.get(2); + Object anInt64 = __pigeon_list.get(2); pigeonResult.setAnInt64( (anInt64 == null) ? null : ((anInt64 instanceof Integer) ? (Integer) anInt64 : (Long) anInt64)); - Object aDouble = list.get(3); + Object aDouble = __pigeon_list.get(3); pigeonResult.setADouble((Double) aDouble); - Object aByteArray = list.get(4); + Object aByteArray = __pigeon_list.get(4); pigeonResult.setAByteArray((byte[]) aByteArray); - Object a4ByteArray = list.get(5); + Object a4ByteArray = __pigeon_list.get(5); pigeonResult.setA4ByteArray((int[]) a4ByteArray); - Object a8ByteArray = list.get(6); + Object a8ByteArray = __pigeon_list.get(6); pigeonResult.setA8ByteArray((long[]) a8ByteArray); - Object aFloatArray = list.get(7); + Object aFloatArray = __pigeon_list.get(7); pigeonResult.setAFloatArray((double[]) aFloatArray); - Object aList = list.get(8); - pigeonResult.setAList((List) aList); - Object aMap = list.get(9); + Object list = __pigeon_list.get(8); + pigeonResult.setList((List) list); + Object aMap = __pigeon_list.get(9); pigeonResult.setAMap((Map) aMap); - Object anEnum = list.get(10); + Object anEnum = __pigeon_list.get(10); pigeonResult.setAnEnum(AnEnum.values()[(int) anEnum]); - Object aString = list.get(11); + Object aString = __pigeon_list.get(11); pigeonResult.setAString((String) aString); - Object anObject = list.get(12); + Object anObject = __pigeon_list.get(12); pigeonResult.setAnObject(anObject); return pigeonResult; } @@ -803,58 +803,55 @@ ArrayList toList() { toListResult.add(aNullableEnum == null ? null : aNullableEnum.index); toListResult.add(aNullableString); toListResult.add(aNullableObject); - toListResult.add((allNullableTypes == null) ? null : allNullableTypes.toList()); + toListResult.add(allNullableTypes); return toListResult; } - static @NonNull AllNullableTypes fromList(@NonNull ArrayList list) { + static @NonNull AllNullableTypes fromList(@NonNull ArrayList __pigeon_list) { AllNullableTypes pigeonResult = new AllNullableTypes(); - Object aNullableBool = list.get(0); + Object aNullableBool = __pigeon_list.get(0); pigeonResult.setANullableBool((Boolean) aNullableBool); - Object aNullableInt = list.get(1); + Object aNullableInt = __pigeon_list.get(1); pigeonResult.setANullableInt( (aNullableInt == null) ? null : ((aNullableInt instanceof Integer) ? (Integer) aNullableInt : (Long) aNullableInt)); - Object aNullableInt64 = list.get(2); + Object aNullableInt64 = __pigeon_list.get(2); pigeonResult.setANullableInt64( (aNullableInt64 == null) ? null : ((aNullableInt64 instanceof Integer) ? (Integer) aNullableInt64 : (Long) aNullableInt64)); - Object aNullableDouble = list.get(3); + Object aNullableDouble = __pigeon_list.get(3); pigeonResult.setANullableDouble((Double) aNullableDouble); - Object aNullableByteArray = list.get(4); + Object aNullableByteArray = __pigeon_list.get(4); pigeonResult.setANullableByteArray((byte[]) aNullableByteArray); - Object aNullable4ByteArray = list.get(5); + Object aNullable4ByteArray = __pigeon_list.get(5); pigeonResult.setANullable4ByteArray((int[]) aNullable4ByteArray); - Object aNullable8ByteArray = list.get(6); + Object aNullable8ByteArray = __pigeon_list.get(6); pigeonResult.setANullable8ByteArray((long[]) aNullable8ByteArray); - Object aNullableFloatArray = list.get(7); + Object aNullableFloatArray = __pigeon_list.get(7); pigeonResult.setANullableFloatArray((double[]) aNullableFloatArray); - Object aNullableList = list.get(8); + Object aNullableList = __pigeon_list.get(8); pigeonResult.setANullableList((List) aNullableList); - Object aNullableMap = list.get(9); + Object aNullableMap = __pigeon_list.get(9); pigeonResult.setANullableMap((Map) aNullableMap); - Object nullableNestedList = list.get(10); + Object nullableNestedList = __pigeon_list.get(10); pigeonResult.setNullableNestedList((List>) nullableNestedList); - Object nullableMapWithAnnotations = list.get(11); + Object nullableMapWithAnnotations = __pigeon_list.get(11); pigeonResult.setNullableMapWithAnnotations((Map) nullableMapWithAnnotations); - Object nullableMapWithObject = list.get(12); + Object nullableMapWithObject = __pigeon_list.get(12); pigeonResult.setNullableMapWithObject((Map) nullableMapWithObject); - Object aNullableEnum = list.get(13); + Object aNullableEnum = __pigeon_list.get(13); pigeonResult.setANullableEnum( aNullableEnum == null ? null : AnEnum.values()[(int) aNullableEnum]); - Object aNullableString = list.get(14); + Object aNullableString = __pigeon_list.get(14); pigeonResult.setANullableString((String) aNullableString); - Object aNullableObject = list.get(15); + Object aNullableObject = __pigeon_list.get(15); pigeonResult.setANullableObject(aNullableObject); - Object allNullableTypes = list.get(16); - pigeonResult.setAllNullableTypes( - (allNullableTypes == null) - ? null - : AllNullableTypes.fromList((ArrayList) allNullableTypes)); + Object allNullableTypes = __pigeon_list.get(16); + pigeonResult.setAllNullableTypes((AllNullableTypes) allNullableTypes); return pigeonResult; } } @@ -1201,48 +1198,49 @@ ArrayList toList() { return toListResult; } - static @NonNull AllNullableTypesWithoutRecursion fromList(@NonNull ArrayList list) { + static @NonNull AllNullableTypesWithoutRecursion fromList( + @NonNull ArrayList __pigeon_list) { AllNullableTypesWithoutRecursion pigeonResult = new AllNullableTypesWithoutRecursion(); - Object aNullableBool = list.get(0); + Object aNullableBool = __pigeon_list.get(0); pigeonResult.setANullableBool((Boolean) aNullableBool); - Object aNullableInt = list.get(1); + Object aNullableInt = __pigeon_list.get(1); pigeonResult.setANullableInt( (aNullableInt == null) ? null : ((aNullableInt instanceof Integer) ? (Integer) aNullableInt : (Long) aNullableInt)); - Object aNullableInt64 = list.get(2); + Object aNullableInt64 = __pigeon_list.get(2); pigeonResult.setANullableInt64( (aNullableInt64 == null) ? null : ((aNullableInt64 instanceof Integer) ? (Integer) aNullableInt64 : (Long) aNullableInt64)); - Object aNullableDouble = list.get(3); + Object aNullableDouble = __pigeon_list.get(3); pigeonResult.setANullableDouble((Double) aNullableDouble); - Object aNullableByteArray = list.get(4); + Object aNullableByteArray = __pigeon_list.get(4); pigeonResult.setANullableByteArray((byte[]) aNullableByteArray); - Object aNullable4ByteArray = list.get(5); + Object aNullable4ByteArray = __pigeon_list.get(5); pigeonResult.setANullable4ByteArray((int[]) aNullable4ByteArray); - Object aNullable8ByteArray = list.get(6); + Object aNullable8ByteArray = __pigeon_list.get(6); pigeonResult.setANullable8ByteArray((long[]) aNullable8ByteArray); - Object aNullableFloatArray = list.get(7); + Object aNullableFloatArray = __pigeon_list.get(7); pigeonResult.setANullableFloatArray((double[]) aNullableFloatArray); - Object aNullableList = list.get(8); + Object aNullableList = __pigeon_list.get(8); pigeonResult.setANullableList((List) aNullableList); - Object aNullableMap = list.get(9); + Object aNullableMap = __pigeon_list.get(9); pigeonResult.setANullableMap((Map) aNullableMap); - Object nullableNestedList = list.get(10); + Object nullableNestedList = __pigeon_list.get(10); pigeonResult.setNullableNestedList((List>) nullableNestedList); - Object nullableMapWithAnnotations = list.get(11); + Object nullableMapWithAnnotations = __pigeon_list.get(11); pigeonResult.setNullableMapWithAnnotations((Map) nullableMapWithAnnotations); - Object nullableMapWithObject = list.get(12); + Object nullableMapWithObject = __pigeon_list.get(12); pigeonResult.setNullableMapWithObject((Map) nullableMapWithObject); - Object aNullableEnum = list.get(13); + Object aNullableEnum = __pigeon_list.get(13); pigeonResult.setANullableEnum( aNullableEnum == null ? null : AnEnum.values()[(int) aNullableEnum]); - Object aNullableString = list.get(14); + Object aNullableString = __pigeon_list.get(14); pigeonResult.setANullableString((String) aNullableString); - Object aNullableObject = list.get(15); + Object aNullableObject = __pigeon_list.get(15); pigeonResult.setANullableObject(aNullableObject); return pigeonResult; } @@ -1334,31 +1332,21 @@ public static final class Builder { @NonNull ArrayList toList() { ArrayList toListResult = new ArrayList(3); - toListResult.add((allNullableTypes == null) ? null : allNullableTypes.toList()); - toListResult.add( - (allNullableTypesWithoutRecursion == null) - ? null - : allNullableTypesWithoutRecursion.toList()); - toListResult.add((allTypes == null) ? null : allTypes.toList()); + toListResult.add(allNullableTypes); + toListResult.add(allNullableTypesWithoutRecursion); + toListResult.add(allTypes); return toListResult; } - static @NonNull AllClassesWrapper fromList(@NonNull ArrayList list) { + static @NonNull AllClassesWrapper fromList(@NonNull ArrayList __pigeon_list) { AllClassesWrapper pigeonResult = new AllClassesWrapper(); - Object allNullableTypes = list.get(0); - pigeonResult.setAllNullableTypes( - (allNullableTypes == null) - ? null - : AllNullableTypes.fromList((ArrayList) allNullableTypes)); - Object allNullableTypesWithoutRecursion = list.get(1); + Object allNullableTypes = __pigeon_list.get(0); + pigeonResult.setAllNullableTypes((AllNullableTypes) allNullableTypes); + Object allNullableTypesWithoutRecursion = __pigeon_list.get(1); pigeonResult.setAllNullableTypesWithoutRecursion( - (allNullableTypesWithoutRecursion == null) - ? null - : AllNullableTypesWithoutRecursion.fromList( - (ArrayList) allNullableTypesWithoutRecursion)); - Object allTypes = list.get(2); - pigeonResult.setAllTypes( - (allTypes == null) ? null : AllTypes.fromList((ArrayList) allTypes)); + (AllNullableTypesWithoutRecursion) allNullableTypesWithoutRecursion); + Object allTypes = __pigeon_list.get(2); + pigeonResult.setAllTypes((AllTypes) allTypes); return pigeonResult; } } @@ -1403,9 +1391,9 @@ ArrayList toList() { return toListResult; } - static @NonNull TestMessage fromList(@NonNull ArrayList list) { + static @NonNull TestMessage fromList(@NonNull ArrayList __pigeon_list) { TestMessage pigeonResult = new TestMessage(); - Object testList = list.get(0); + Object testList = __pigeon_list.get(0); pigeonResult.setTestList((List) testList); return pigeonResult; } @@ -1524,7 +1512,7 @@ public interface HostIntegrationCoreApi { Object echoObject(@NonNull Object anObject); /** Returns the passed list, to test serialization and deserialization. */ @NonNull - List echoList(@NonNull List aList); + List echoList(@NonNull List list); /** Returns the passed map, to test serialization and deserialization. */ @NonNull Map echoMap(@NonNull Map aMap); @@ -1623,7 +1611,7 @@ AllNullableTypesWithoutRecursion sendMultipleNullableTypesWithoutRecursion( /** Returns the passed in generic Object asynchronously. */ void echoAsyncObject(@NonNull Object anObject, @NonNull Result result); /** Returns the passed list, to test asynchronous serialization and deserialization. */ - void echoAsyncList(@NonNull List aList, @NonNull Result> result); + void echoAsyncList(@NonNull List list, @NonNull Result> result); /** Returns the passed map, to test asynchronous serialization and deserialization. */ void echoAsyncMap( @NonNull Map aMap, @NonNull Result> result); @@ -1659,7 +1647,7 @@ void echoAsyncNullableUint8List( void echoAsyncNullableObject(@Nullable Object anObject, @NonNull NullableResult result); /** Returns the passed list, to test asynchronous serialization and deserialization. */ void echoAsyncNullableList( - @Nullable List aList, @NonNull NullableResult> result); + @Nullable List list, @NonNull NullableResult> result); /** Returns the passed map, to test asynchronous serialization and deserialization. */ void echoAsyncNullableMap( @Nullable Map aMap, @NonNull NullableResult> result); @@ -1701,9 +1689,9 @@ void callFlutterSendMultipleNullableTypesWithoutRecursion( void callFlutterEchoString(@NonNull String aString, @NonNull Result result); - void callFlutterEchoUint8List(@NonNull byte[] aList, @NonNull Result result); + void callFlutterEchoUint8List(@NonNull byte[] list, @NonNull Result result); - void callFlutterEchoList(@NonNull List aList, @NonNull Result> result); + void callFlutterEchoList(@NonNull List list, @NonNull Result> result); void callFlutterEchoMap( @NonNull Map aMap, @NonNull Result> result); @@ -1722,10 +1710,10 @@ void callFlutterEchoNullableString( @Nullable String aString, @NonNull NullableResult result); void callFlutterEchoNullableUint8List( - @Nullable byte[] aList, @NonNull NullableResult result); + @Nullable byte[] list, @NonNull NullableResult result); void callFlutterEchoNullableList( - @Nullable List aList, @NonNull NullableResult> result); + @Nullable List list, @NonNull NullableResult> result); void callFlutterEchoNullableMap( @Nullable Map aMap, @NonNull NullableResult> result); @@ -2043,9 +2031,9 @@ static void setUp( (message, reply) -> { ArrayList wrapped = new ArrayList(); ArrayList args = (ArrayList) message; - List aListArg = (List) args.get(0); + List listArg = (List) args.get(0); try { - List output = api.echoList(aListArg); + List output = api.echoList(listArg); wrapped.add(0, output); } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); @@ -2908,7 +2896,7 @@ public void error(Throwable error) { (message, reply) -> { ArrayList wrapped = new ArrayList(); ArrayList args = (ArrayList) message; - List aListArg = (List) args.get(0); + List listArg = (List) args.get(0); Result> resultCallback = new Result>() { public void success(List result) { @@ -2922,7 +2910,7 @@ public void error(Throwable error) { } }; - api.echoAsyncList(aListArg, resultCallback); + api.echoAsyncList(listArg, resultCallback); }); } else { channel.setMessageHandler(null); @@ -3385,7 +3373,7 @@ public void error(Throwable error) { (message, reply) -> { ArrayList wrapped = new ArrayList(); ArrayList args = (ArrayList) message; - List aListArg = (List) args.get(0); + List listArg = (List) args.get(0); NullableResult> resultCallback = new NullableResult>() { public void success(List result) { @@ -3399,7 +3387,7 @@ public void error(Throwable error) { } }; - api.echoAsyncNullableList(aListArg, resultCallback); + api.echoAsyncNullableList(listArg, resultCallback); }); } else { channel.setMessageHandler(null); @@ -3873,7 +3861,7 @@ public void error(Throwable error) { (message, reply) -> { ArrayList wrapped = new ArrayList(); ArrayList args = (ArrayList) message; - byte[] aListArg = (byte[]) args.get(0); + byte[] listArg = (byte[]) args.get(0); Result resultCallback = new Result() { public void success(byte[] result) { @@ -3887,7 +3875,7 @@ public void error(Throwable error) { } }; - api.callFlutterEchoUint8List(aListArg, resultCallback); + api.callFlutterEchoUint8List(listArg, resultCallback); }); } else { channel.setMessageHandler(null); @@ -3905,7 +3893,7 @@ public void error(Throwable error) { (message, reply) -> { ArrayList wrapped = new ArrayList(); ArrayList args = (ArrayList) message; - List aListArg = (List) args.get(0); + List listArg = (List) args.get(0); Result> resultCallback = new Result>() { public void success(List result) { @@ -3919,7 +3907,7 @@ public void error(Throwable error) { } }; - api.callFlutterEchoList(aListArg, resultCallback); + api.callFlutterEchoList(listArg, resultCallback); }); } else { channel.setMessageHandler(null); @@ -4130,7 +4118,7 @@ public void error(Throwable error) { (message, reply) -> { ArrayList wrapped = new ArrayList(); ArrayList args = (ArrayList) message; - byte[] aListArg = (byte[]) args.get(0); + byte[] listArg = (byte[]) args.get(0); NullableResult resultCallback = new NullableResult() { public void success(byte[] result) { @@ -4144,7 +4132,7 @@ public void error(Throwable error) { } }; - api.callFlutterEchoNullableUint8List(aListArg, resultCallback); + api.callFlutterEchoNullableUint8List(listArg, resultCallback); }); } else { channel.setMessageHandler(null); @@ -4162,7 +4150,7 @@ public void error(Throwable error) { (message, reply) -> { ArrayList wrapped = new ArrayList(); ArrayList args = (ArrayList) message; - List aListArg = (List) args.get(0); + List listArg = (List) args.get(0); NullableResult> resultCallback = new NullableResult>() { public void success(List result) { @@ -4176,7 +4164,7 @@ public void error(Throwable error) { } }; - api.callFlutterEchoNullableList(aListArg, resultCallback); + api.callFlutterEchoNullableList(listArg, resultCallback); }); } else { channel.setMessageHandler(null); @@ -4755,14 +4743,14 @@ public void echoString(@NonNull String aStringArg, @NonNull Result resul }); } /** Returns the passed byte list, to test serialization and deserialization. */ - public void echoUint8List(@NonNull byte[] aListArg, @NonNull Result result) { + public void echoUint8List(@NonNull byte[] listArg, @NonNull Result result) { final String channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoUint8List" + messageChannelSuffix; BasicMessageChannel channel = new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( - new ArrayList(Collections.singletonList(aListArg)), + new ArrayList(Collections.singletonList(listArg)), channelReply -> { if (channelReply instanceof List) { List listReply = (List) channelReply; @@ -4789,14 +4777,14 @@ public void echoUint8List(@NonNull byte[] aListArg, @NonNull Result resu }); } /** Returns the passed list, to test serialization and deserialization. */ - public void echoList(@NonNull List aListArg, @NonNull Result> result) { + public void echoList(@NonNull List listArg, @NonNull Result> result) { final String channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoList" + messageChannelSuffix; BasicMessageChannel channel = new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( - new ArrayList(Collections.singletonList(aListArg)), + new ArrayList(Collections.singletonList(listArg)), channelReply -> { if (channelReply instanceof List) { List listReply = (List) channelReply; @@ -5009,14 +4997,14 @@ public void echoNullableString( } /** Returns the passed byte list, to test serialization and deserialization. */ public void echoNullableUint8List( - @Nullable byte[] aListArg, @NonNull NullableResult result) { + @Nullable byte[] listArg, @NonNull NullableResult result) { final String channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableUint8List" + messageChannelSuffix; BasicMessageChannel channel = new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( - new ArrayList(Collections.singletonList(aListArg)), + new ArrayList(Collections.singletonList(listArg)), channelReply -> { if (channelReply instanceof List) { List listReply = (List) channelReply; @@ -5038,14 +5026,14 @@ public void echoNullableUint8List( } /** Returns the passed list, to test serialization and deserialization. */ public void echoNullableList( - @Nullable List aListArg, @NonNull NullableResult> result) { + @Nullable List listArg, @NonNull NullableResult> result) { final String channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableList" + messageChannelSuffix; BasicMessageChannel channel = new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( - new ArrayList(Collections.singletonList(aListArg)), + new ArrayList(Collections.singletonList(listArg)), channelReply -> { if (channelReply instanceof List) { List listReply = (List) channelReply; diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/AllDatatypesTest.java b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/AllDatatypesTest.java index 6f2fdf16e90..b15c2bfa682 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/AllDatatypesTest.java +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/AllDatatypesTest.java @@ -33,7 +33,7 @@ void compareAllTypes(AllTypes firstTypes, AllTypes secondTypes) { assertArrayEquals(firstTypes.getA4ByteArray(), secondTypes.getA4ByteArray()); assertArrayEquals(firstTypes.getA8ByteArray(), secondTypes.getA8ByteArray()); assertTrue(floatArraysEqual(firstTypes.getAFloatArray(), secondTypes.getAFloatArray())); - assertArrayEquals(firstTypes.getAList().toArray(), secondTypes.getAList().toArray()); + assertArrayEquals(firstTypes.getList().toArray(), secondTypes.getList().toArray()); assertArrayEquals( firstTypes.getAMap().keySet().toArray(), secondTypes.getAMap().keySet().toArray()); assertArrayEquals( @@ -154,7 +154,7 @@ public void hasValues() { .setA4ByteArray(new int[] {1, 2, 3, 4}) .setA8ByteArray(new long[] {1, 2, 3, 4}) .setAFloatArray(new double[] {0.5, 0.25, 1.5, 1.25}) - .setAList(Arrays.asList(new int[] {1, 2, 3})) + .setList(Arrays.asList(new int[] {1, 2, 3})) .setAMap(makeMap("hello", 1234)) .setAnEnum(CoreTests.AnEnum.ONE) .setAnObject(0) diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/NullFieldsTest.java b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/NullFieldsTest.java index d581c2d8bc2..621a8a64f83 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/NullFieldsTest.java +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/test/java/com/example/alternate_language_test_plugin/NullFieldsTest.java @@ -81,20 +81,23 @@ public void requestFromMapWithNulls() { @Test public void replyFromMapWithValues() { - ArrayList requestList = new ArrayList(); - - requestList.add("hello"); - requestList.add(1L); - - ArrayList list = new ArrayList(); + NullFields.NullFieldsSearchRequest request = + new NullFields.NullFieldsSearchRequest.Builder() + .setQuery("hello") + .setIdentifier(1L) + .build(); - list.add("result"); - list.add("error"); - list.add(Arrays.asList(1L, 2L, 3L)); - list.add(requestList); - list.add(NullFields.NullFieldsSearchReplyType.SUCCESS.ordinal()); + NullFields.NullFieldsSearchReply input = + new NullFields.NullFieldsSearchReply.Builder() + .setResult("result") + .setError("error") + .setIndices(Arrays.asList(1L, 2L, 3L)) + .setRequest(request) + .setType(NullFields.NullFieldsSearchReplyType.SUCCESS) + .build(); - NullFields.NullFieldsSearchReply reply = NullFields.NullFieldsSearchReply.fromList(list); + NullFields.NullFieldsSearchReply reply = + NullFields.NullFieldsSearchReply.fromList(input.toList()); assertEquals(reply.getResult(), "result"); assertEquals(reply.getError(), "error"); assertEquals(reply.getIndices(), Arrays.asList(1L, 2L, 3L)); @@ -143,16 +146,18 @@ public void requestToMapWithNulls() { @Test public void replyToMapWithValues() { + NullFields.NullFieldsSearchRequest request = + new NullFields.NullFieldsSearchRequest.Builder() + .setQuery("hello") + .setIdentifier(1L) + .build(); + NullFields.NullFieldsSearchReply reply = new NullFields.NullFieldsSearchReply.Builder() .setResult("result") .setError("error") .setIndices(Arrays.asList(1L, 2L, 3L)) - .setRequest( - new NullFields.NullFieldsSearchRequest.Builder() - .setQuery("hello") - .setIdentifier(1L) - .build()) + .setRequest(request) .setType(NullFields.NullFieldsSearchReplyType.SUCCESS) .build(); @@ -160,7 +165,7 @@ public void replyToMapWithValues() { assertEquals(list.get(0), "result"); assertEquals(list.get(1), "error"); assertEquals(list.get(2), Arrays.asList(1L, 2L, 3L)); - assertEquals(list.get(3), reply.getRequest().toList()); + assertEquals(list.get(3), reply.getRequest()); assertEquals(list.get(4), NullFields.NullFieldsSearchReplyType.SUCCESS.ordinal()); } diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/NullFieldsTest.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/NullFieldsTest.m index e4032dc4cb5..48b48b61a68 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/NullFieldsTest.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/NullFieldsTest.m @@ -84,19 +84,18 @@ - (void)testRequestFromListWithNulls { } - (void)testReplyFromListWithValues { - NSArray *list = @[ - @"result", - @"error", - @[ @1, @2, @3 ], - @[ - @"hello", - @1, - ], - @0, - ]; - NSArray *indices = @[ @1, @2, @3 ]; - NullFieldsSearchReply *reply = [NullFieldsSearchReply fromList:list]; + NullFieldsSearchRequest *request = [NullFieldsSearchRequest makeWithQuery:@"hello" identifier:1]; + + NullFieldsSearchReplyTypeBox *typeWrapper = + [[NullFieldsSearchReplyTypeBox alloc] initWithValue:NullFieldsSearchReplyTypeSuccess]; + NullFieldsSearchReply *input = [NullFieldsSearchReply makeWithResult:@"result" + error:@"error" + indices:indices + request:request + type:typeWrapper]; + + NullFieldsSearchReply *reply = [NullFieldsSearchReply fromList:[input toList]]; XCTAssertEqualObjects(@"result", reply.result); XCTAssertEqualObjects(@"error", reply.error); XCTAssertEqualObjects(indices, reply.indices); @@ -146,7 +145,7 @@ - (void)testReplyToListWithValuess { XCTAssertEqualObjects(@"result", list[0]); XCTAssertEqualObjects(@"error", list[1]); XCTAssertEqualObjects(indices, list[2]); - XCTAssertEqualObjects(@"hello", list[3][0]); + XCTAssertEqualObjects(@"hello", ((NullFieldsSearchRequest *)list[3]).query); NSNumber *typeNumber = list[4]; NullFieldsSearchReplyTypeBox *output = [[NullFieldsSearchReplyTypeBox alloc] initWithValue:[typeNumber integerValue]]; diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/AlternateLanguageTestPlugin.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/AlternateLanguageTestPlugin.m index e3f26dcb8d7..4ea9519033c 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/AlternateLanguageTestPlugin.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/AlternateLanguageTestPlugin.m @@ -90,9 +90,9 @@ - (nullable id)echoObject:(id)anObject error:(FlutterError *_Nullable *_Nonnull) return anObject; } -- (nullable NSArray *)echoList:(NSArray *)aList +- (nullable NSArray *)echoList:(NSArray *)list error:(FlutterError *_Nullable *_Nonnull)error { - return aList; + return list; } - (nullable NSDictionary *)echoMap:(NSDictionary *)aMap @@ -293,9 +293,9 @@ - (void)echoAsyncObject:(id)anObject completion(anObject, nil); } -- (void)echoAsyncList:(NSArray *)aList +- (void)echoAsyncList:(NSArray *)list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion { - completion(aList, nil); + completion(list, nil); } - (void)echoAsyncMap:(NSDictionary *)aMap @@ -340,10 +340,10 @@ - (void)echoAsyncNullableObject:(nullable id)anObject completion(anObject, nil); } -- (void)echoAsyncNullableList:(nullable NSArray *)aList +- (void)echoAsyncNullableList:(nullable NSArray *)list completion: (void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion { - completion(aList, nil); + completion(list, nil); } - (void)echoAsyncNullableMap:(nullable NSDictionary *)aMap @@ -451,18 +451,18 @@ - (void)callFlutterEchoString:(NSString *)aString }]; } -- (void)callFlutterEchoUint8List:(FlutterStandardTypedData *)aList +- (void)callFlutterEchoUint8List:(FlutterStandardTypedData *)list completion:(void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion { - [self.flutterAPI echoUint8List:aList + [self.flutterAPI echoUint8List:list completion:^(FlutterStandardTypedData *value, FlutterError *error) { completion(value, error); }]; } -- (void)callFlutterEchoList:(NSArray *)aList +- (void)callFlutterEchoList:(NSArray *)list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion { - [self.flutterAPI echoList:aList + [self.flutterAPI echoList:list completion:^(NSArray *value, FlutterError *error) { completion(value, error); }]; @@ -544,19 +544,19 @@ - (void)callFlutterEchoNullableString:(nullable NSString *)aString }]; } -- (void)callFlutterEchoNullableUint8List:(nullable FlutterStandardTypedData *)aList +- (void)callFlutterEchoNullableUint8List:(nullable FlutterStandardTypedData *)list completion:(void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion { - [self.flutterAPI echoNullableUint8List:aList + [self.flutterAPI echoNullableUint8List:list completion:^(FlutterStandardTypedData *value, FlutterError *error) { completion(value, error); }]; } -- (void)callFlutterEchoNullableList:(nullable NSArray *)aList +- (void)callFlutterEchoNullableList:(nullable NSArray *)list completion: (void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion { - [self.flutterAPI echoNullableList:aList + [self.flutterAPI echoNullableList:list completion:^(NSArray *value, FlutterError *error) { completion(value, error); }]; diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h index 8e44380d789..ada05bf3801 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h @@ -46,7 +46,7 @@ typedef NS_ENUM(NSUInteger, FLTAnEnum) { a4ByteArray:(FlutterStandardTypedData *)a4ByteArray a8ByteArray:(FlutterStandardTypedData *)a8ByteArray aFloatArray:(FlutterStandardTypedData *)aFloatArray - aList:(NSArray *)aList + list:(NSArray *)list aMap:(NSDictionary *)aMap anEnum:(FLTAnEnum)anEnum aString:(NSString *)aString @@ -59,7 +59,7 @@ typedef NS_ENUM(NSUInteger, FLTAnEnum) { @property(nonatomic, strong) FlutterStandardTypedData *a4ByteArray; @property(nonatomic, strong) FlutterStandardTypedData *a8ByteArray; @property(nonatomic, strong) FlutterStandardTypedData *aFloatArray; -@property(nonatomic, copy) NSArray *aList; +@property(nonatomic, copy) NSArray *list; @property(nonatomic, copy) NSDictionary *aMap; @property(nonatomic, assign) FLTAnEnum anEnum; @property(nonatomic, copy) NSString *aString; @@ -219,7 +219,7 @@ NSObject *FLTHostIntegrationCoreApiGetCodec(void); /// Returns the passed list, to test serialization and deserialization. /// /// @return `nil` only when `error != nil`. -- (nullable NSArray *)echoList:(NSArray *)aList +- (nullable NSArray *)echoList:(NSArray *)list error:(FlutterError *_Nullable *_Nonnull)error; /// Returns the passed map, to test serialization and deserialization. /// @@ -342,7 +342,7 @@ NSObject *FLTHostIntegrationCoreApiGetCodec(void); - (void)echoAsyncObject:(id)anObject completion:(void (^)(id _Nullable, FlutterError *_Nullable))completion; /// Returns the passed list, to test asynchronous serialization and deserialization. -- (void)echoAsyncList:(NSArray *)aList +- (void)echoAsyncList:(NSArray *)list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion; /// Returns the passed map, to test asynchronous serialization and deserialization. - (void)echoAsyncMap:(NSDictionary *)aMap @@ -392,7 +392,7 @@ NSObject *FLTHostIntegrationCoreApiGetCodec(void); - (void)echoAsyncNullableObject:(nullable id)anObject completion:(void (^)(id _Nullable, FlutterError *_Nullable))completion; /// Returns the passed list, to test asynchronous serialization and deserialization. -- (void)echoAsyncNullableList:(nullable NSArray *)aList +- (void)echoAsyncNullableList:(nullable NSArray *)list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion; /// Returns the passed map, to test asynchronous serialization and deserialization. - (void)echoAsyncNullableMap:(nullable NSDictionary *)aMap @@ -440,10 +440,10 @@ NSObject *FLTHostIntegrationCoreApiGetCodec(void); completion:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion; - (void)callFlutterEchoString:(NSString *)aString completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion; -- (void)callFlutterEchoUint8List:(FlutterStandardTypedData *)aList +- (void)callFlutterEchoUint8List:(FlutterStandardTypedData *)list completion:(void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion; -- (void)callFlutterEchoList:(NSArray *)aList +- (void)callFlutterEchoList:(NSArray *)list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion; - (void)callFlutterEchoMap:(NSDictionary *)aMap completion:(void (^)(NSDictionary *_Nullable, @@ -462,10 +462,10 @@ NSObject *FLTHostIntegrationCoreApiGetCodec(void); - (void)callFlutterEchoNullableString:(nullable NSString *)aString completion: (void (^)(NSString *_Nullable, FlutterError *_Nullable))completion; -- (void)callFlutterEchoNullableUint8List:(nullable FlutterStandardTypedData *)aList +- (void)callFlutterEchoNullableUint8List:(nullable FlutterStandardTypedData *)list completion:(void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion; -- (void)callFlutterEchoNullableList:(nullable NSArray *)aList +- (void)callFlutterEchoNullableList:(nullable NSArray *)list completion: (void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion; - (void)callFlutterEchoNullableMap:(nullable NSDictionary *)aMap @@ -545,11 +545,11 @@ NSObject *FLTFlutterIntegrationCoreApiGetCodec(void); - (void)echoString:(NSString *)aString completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion; /// Returns the passed byte list, to test serialization and deserialization. -- (void)echoUint8List:(FlutterStandardTypedData *)aList +- (void)echoUint8List:(FlutterStandardTypedData *)list completion: (void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion; /// Returns the passed list, to test serialization and deserialization. -- (void)echoList:(NSArray *)aList +- (void)echoList:(NSArray *)list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion; /// Returns the passed map, to test serialization and deserialization. - (void)echoMap:(NSDictionary *)aMap @@ -571,11 +571,11 @@ NSObject *FLTFlutterIntegrationCoreApiGetCodec(void); - (void)echoNullableString:(nullable NSString *)aString completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion; /// Returns the passed byte list, to test serialization and deserialization. -- (void)echoNullableUint8List:(nullable FlutterStandardTypedData *)aList +- (void)echoNullableUint8List:(nullable FlutterStandardTypedData *)list completion:(void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion; /// Returns the passed list, to test serialization and deserialization. -- (void)echoNullableList:(nullable NSArray *)aList +- (void)echoNullableList:(nullable NSArray *)list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion; /// Returns the passed map, to test serialization and deserialization. - (void)echoNullableMap:(nullable NSDictionary *)aMap diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m index eecb44f2eaf..92c72d59598 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m @@ -89,7 +89,7 @@ + (instancetype)makeWithABool:(BOOL)aBool a4ByteArray:(FlutterStandardTypedData *)a4ByteArray a8ByteArray:(FlutterStandardTypedData *)a8ByteArray aFloatArray:(FlutterStandardTypedData *)aFloatArray - aList:(NSArray *)aList + list:(NSArray *)list aMap:(NSDictionary *)aMap anEnum:(FLTAnEnum)anEnum aString:(NSString *)aString @@ -103,7 +103,7 @@ + (instancetype)makeWithABool:(BOOL)aBool pigeonResult.a4ByteArray = a4ByteArray; pigeonResult.a8ByteArray = a8ByteArray; pigeonResult.aFloatArray = aFloatArray; - pigeonResult.aList = aList; + pigeonResult.list = list; pigeonResult.aMap = aMap; pigeonResult.anEnum = anEnum; pigeonResult.aString = aString; @@ -120,7 +120,7 @@ + (FLTAllTypes *)fromList:(NSArray *)list { pigeonResult.a4ByteArray = GetNullableObjectAtIndex(list, 5); pigeonResult.a8ByteArray = GetNullableObjectAtIndex(list, 6); pigeonResult.aFloatArray = GetNullableObjectAtIndex(list, 7); - pigeonResult.aList = GetNullableObjectAtIndex(list, 8); + pigeonResult.list = GetNullableObjectAtIndex(list, 8); pigeonResult.aMap = GetNullableObjectAtIndex(list, 9); pigeonResult.anEnum = [GetNullableObjectAtIndex(list, 10) integerValue]; pigeonResult.aString = GetNullableObjectAtIndex(list, 11); @@ -140,7 +140,7 @@ - (NSArray *)toList { self.a4ByteArray ?: [NSNull null], self.a8ByteArray ?: [NSNull null], self.aFloatArray ?: [NSNull null], - self.aList ?: [NSNull null], + self.list ?: [NSNull null], self.aMap ?: [NSNull null], @(self.anEnum), self.aString ?: [NSNull null], @@ -211,8 +211,7 @@ + (FLTAllNullableTypes *)fromList:(NSArray *)list { pigeonResult.aNullableEnum = aNullableEnum; pigeonResult.aNullableString = GetNullableObjectAtIndex(list, 14); pigeonResult.aNullableObject = GetNullableObjectAtIndex(list, 15); - pigeonResult.allNullableTypes = - [FLTAllNullableTypes nullableFromList:(GetNullableObjectAtIndex(list, 16))]; + pigeonResult.allNullableTypes = GetNullableObjectAtIndex(list, 16); return pigeonResult; } + (nullable FLTAllNullableTypes *)nullableFromList:(NSArray *)list { @@ -237,7 +236,7 @@ - (NSArray *)toList { : [NSNumber numberWithInteger:self.aNullableEnum.value]), self.aNullableString ?: [NSNull null], self.aNullableObject ?: [NSNull null], - (self.allNullableTypes ? [self.allNullableTypes toList] : [NSNull null]), + self.allNullableTypes ?: [NSNull null], ]; } @end @@ -345,11 +344,9 @@ + (instancetype)makeWithAllNullableTypes:(FLTAllNullableTypes *)allNullableTypes } + (FLTAllClassesWrapper *)fromList:(NSArray *)list { FLTAllClassesWrapper *pigeonResult = [[FLTAllClassesWrapper alloc] init]; - pigeonResult.allNullableTypes = - [FLTAllNullableTypes nullableFromList:(GetNullableObjectAtIndex(list, 0))]; - pigeonResult.allNullableTypesWithoutRecursion = - [FLTAllNullableTypesWithoutRecursion nullableFromList:(GetNullableObjectAtIndex(list, 1))]; - pigeonResult.allTypes = [FLTAllTypes nullableFromList:(GetNullableObjectAtIndex(list, 2))]; + pigeonResult.allNullableTypes = GetNullableObjectAtIndex(list, 0); + pigeonResult.allNullableTypesWithoutRecursion = GetNullableObjectAtIndex(list, 1); + pigeonResult.allTypes = GetNullableObjectAtIndex(list, 2); return pigeonResult; } + (nullable FLTAllClassesWrapper *)nullableFromList:(NSArray *)list { @@ -357,10 +354,9 @@ + (nullable FLTAllClassesWrapper *)nullableFromList:(NSArray *)list { } - (NSArray *)toList { return @[ - (self.allNullableTypes ? [self.allNullableTypes toList] : [NSNull null]), - (self.allNullableTypesWithoutRecursion ? [self.allNullableTypesWithoutRecursion toList] - : [NSNull null]), - (self.allTypes ? [self.allTypes toList] : [NSNull null]), + self.allNullableTypes ?: [NSNull null], + self.allNullableTypesWithoutRecursion ?: [NSNull null], + self.allTypes ?: [NSNull null], ]; } @end @@ -745,9 +741,9 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; - NSArray *arg_aList = GetNullableObjectAtIndex(args, 0); + NSArray *arg_list = GetNullableObjectAtIndex(args, 0); FlutterError *error; - NSArray *output = [api echoList:arg_aList error:&error]; + NSArray *output = [api echoList:arg_list error:&error]; callback(wrapResult(output, error)); }]; } else { @@ -1557,8 +1553,8 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; - NSArray *arg_aList = GetNullableObjectAtIndex(args, 0); - [api echoAsyncList:arg_aList + NSArray *arg_list = GetNullableObjectAtIndex(args, 0); + [api echoAsyncList:arg_list completion:^(NSArray *_Nullable output, FlutterError *_Nullable error) { callback(wrapResult(output, error)); }]; @@ -1955,8 +1951,8 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; - NSArray *arg_aList = GetNullableObjectAtIndex(args, 0); - [api echoAsyncNullableList:arg_aList + NSArray *arg_list = GetNullableObjectAtIndex(args, 0); + [api echoAsyncNullableList:arg_list completion:^(NSArray *_Nullable output, FlutterError *_Nullable error) { callback(wrapResult(output, error)); }]; @@ -2364,8 +2360,8 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; - FlutterStandardTypedData *arg_aList = GetNullableObjectAtIndex(args, 0); - [api callFlutterEchoUint8List:arg_aList + FlutterStandardTypedData *arg_list = GetNullableObjectAtIndex(args, 0); + [api callFlutterEchoUint8List:arg_list completion:^(FlutterStandardTypedData *_Nullable output, FlutterError *_Nullable error) { callback(wrapResult(output, error)); @@ -2390,8 +2386,8 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; - NSArray *arg_aList = GetNullableObjectAtIndex(args, 0); - [api callFlutterEchoList:arg_aList + NSArray *arg_list = GetNullableObjectAtIndex(args, 0); + [api callFlutterEchoList:arg_list completion:^(NSArray *_Nullable output, FlutterError *_Nullable error) { callback(wrapResult(output, error)); }]; @@ -2578,8 +2574,8 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; - FlutterStandardTypedData *arg_aList = GetNullableObjectAtIndex(args, 0); - [api callFlutterEchoNullableUint8List:arg_aList + FlutterStandardTypedData *arg_list = GetNullableObjectAtIndex(args, 0); + [api callFlutterEchoNullableUint8List:arg_list completion:^(FlutterStandardTypedData *_Nullable output, FlutterError *_Nullable error) { callback(wrapResult(output, error)); @@ -2605,8 +2601,8 @@ void SetUpFLTHostIntegrationCoreApiWithSuffix(id binaryM api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; - NSArray *arg_aList = GetNullableObjectAtIndex(args, 0); - [api callFlutterEchoNullableList:arg_aList + NSArray *arg_list = GetNullableObjectAtIndex(args, 0); + [api callFlutterEchoNullableList:arg_list completion:^(NSArray *_Nullable output, FlutterError *_Nullable error) { callback(wrapResult(output, error)); @@ -3131,7 +3127,7 @@ - (void)echoString:(NSString *)arg_aString } }]; } -- (void)echoUint8List:(FlutterStandardTypedData *)arg_aList +- (void)echoUint8List:(FlutterStandardTypedData *)arg_list completion: (void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion { NSString *channelName = [NSString @@ -3143,7 +3139,7 @@ - (void)echoUint8List:(FlutterStandardTypedData *)arg_aList [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger codec:FLTFlutterIntegrationCoreApiGetCodec()]; - [channel sendMessage:@[ arg_aList ?: [NSNull null] ] + [channel sendMessage:@[ arg_list ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { if (reply.count > 1) { @@ -3160,7 +3156,7 @@ - (void)echoUint8List:(FlutterStandardTypedData *)arg_aList } }]; } -- (void)echoList:(NSArray *)arg_aList +- (void)echoList:(NSArray *)arg_list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion { NSString *channelName = [NSString stringWithFormat: @@ -3171,7 +3167,7 @@ - (void)echoList:(NSArray *)arg_aList [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger codec:FLTFlutterIntegrationCoreApiGetCodec()]; - [channel sendMessage:@[ arg_aList ?: [NSNull null] ] + [channel sendMessage:@[ arg_list ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { if (reply.count > 1) { @@ -3354,7 +3350,7 @@ - (void)echoNullableString:(nullable NSString *)arg_aString } }]; } -- (void)echoNullableUint8List:(nullable FlutterStandardTypedData *)arg_aList +- (void)echoNullableUint8List:(nullable FlutterStandardTypedData *)arg_list completion:(void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion { NSString *channelName = @@ -3366,7 +3362,7 @@ - (void)echoNullableUint8List:(nullable FlutterStandardTypedData *)arg_aList [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger codec:FLTFlutterIntegrationCoreApiGetCodec()]; - [channel sendMessage:@[ arg_aList ?: [NSNull null] ] + [channel sendMessage:@[ arg_list ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { if (reply.count > 1) { @@ -3383,7 +3379,7 @@ - (void)echoNullableUint8List:(nullable FlutterStandardTypedData *)arg_aList } }]; } -- (void)echoNullableList:(nullable NSArray *)arg_aList +- (void)echoNullableList:(nullable NSArray *)arg_list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion { NSString *channelName = [NSString stringWithFormat: @@ -3394,7 +3390,7 @@ - (void)echoNullableList:(nullable NSArray *)arg_aList [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger codec:FLTFlutterIntegrationCoreApiGetCodec()]; - [channel sendMessage:@[ arg_aList ?: [NSNull null] ] + [channel sendMessage:@[ arg_list ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { if (reply.count > 1) { diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/AlternateLanguageTestPlugin.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/AlternateLanguageTestPlugin.m index b35ac7907ec..0cdec98b9ed 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/AlternateLanguageTestPlugin.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/AlternateLanguageTestPlugin.m @@ -88,9 +88,9 @@ - (nullable id)echoObject:(id)anObject error:(FlutterError *_Nullable *_Nonnull) return anObject; } -- (nullable NSArray *)echoList:(NSArray *)aList +- (nullable NSArray *)echoList:(NSArray *)list error:(FlutterError *_Nullable *_Nonnull)error { - return aList; + return list; } - (nullable NSDictionary *)echoMap:(NSDictionary *)aMap @@ -288,9 +288,9 @@ - (void)echoAsyncObject:(id)anObject completion(anObject, nil); } -- (void)echoAsyncList:(NSArray *)aList +- (void)echoAsyncList:(NSArray *)list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion { - completion(aList, nil); + completion(list, nil); } - (void)echoAsyncMap:(NSDictionary *)aMap @@ -335,10 +335,10 @@ - (void)echoAsyncNullableObject:(nullable id)anObject completion(anObject, nil); } -- (void)echoAsyncNullableList:(nullable NSArray *)aList +- (void)echoAsyncNullableList:(nullable NSArray *)list completion: (void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion { - completion(aList, nil); + completion(list, nil); } - (void)echoAsyncNullableMap:(nullable NSDictionary *)aMap @@ -443,18 +443,18 @@ - (void)callFlutterEchoString:(NSString *)aString }]; } -- (void)callFlutterEchoUint8List:(FlutterStandardTypedData *)aList +- (void)callFlutterEchoUint8List:(FlutterStandardTypedData *)list completion:(void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion { - [self.flutterAPI echoUint8List:aList + [self.flutterAPI echoUint8List:list completion:^(FlutterStandardTypedData *value, FlutterError *error) { completion(value, error); }]; } -- (void)callFlutterEchoList:(NSArray *)aList +- (void)callFlutterEchoList:(NSArray *)list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion { - [self.flutterAPI echoList:aList + [self.flutterAPI echoList:list completion:^(NSArray *value, FlutterError *error) { completion(value, error); }]; @@ -535,19 +535,19 @@ - (void)callFlutterEchoNullableString:(nullable NSString *)aString }]; } -- (void)callFlutterEchoNullableUint8List:(nullable FlutterStandardTypedData *)aList +- (void)callFlutterEchoNullableUint8List:(nullable FlutterStandardTypedData *)list completion:(void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion { - [self.flutterAPI echoNullableUint8List:aList + [self.flutterAPI echoNullableUint8List:list completion:^(FlutterStandardTypedData *value, FlutterError *error) { completion(value, error); }]; } -- (void)callFlutterEchoNullableList:(nullable NSArray *)aList +- (void)callFlutterEchoNullableList:(nullable NSArray *)list completion: (void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion { - [self.flutterAPI echoNullableList:aList + [self.flutterAPI echoNullableList:list completion:^(NSArray *value, FlutterError *error) { completion(value, error); }]; diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.h b/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.h index 4d6fc8de326..ee54d035eb6 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.h +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.h @@ -46,7 +46,7 @@ typedef NS_ENUM(NSUInteger, AnEnum) { a4ByteArray:(FlutterStandardTypedData *)a4ByteArray a8ByteArray:(FlutterStandardTypedData *)a8ByteArray aFloatArray:(FlutterStandardTypedData *)aFloatArray - aList:(NSArray *)aList + list:(NSArray *)list aMap:(NSDictionary *)aMap anEnum:(AnEnum)anEnum aString:(NSString *)aString @@ -59,7 +59,7 @@ typedef NS_ENUM(NSUInteger, AnEnum) { @property(nonatomic, strong) FlutterStandardTypedData *a4ByteArray; @property(nonatomic, strong) FlutterStandardTypedData *a8ByteArray; @property(nonatomic, strong) FlutterStandardTypedData *aFloatArray; -@property(nonatomic, copy) NSArray *aList; +@property(nonatomic, copy) NSArray *list; @property(nonatomic, copy) NSDictionary *aMap; @property(nonatomic, assign) AnEnum anEnum; @property(nonatomic, copy) NSString *aString; @@ -219,7 +219,7 @@ NSObject *HostIntegrationCoreApiGetCodec(void); /// Returns the passed list, to test serialization and deserialization. /// /// @return `nil` only when `error != nil`. -- (nullable NSArray *)echoList:(NSArray *)aList +- (nullable NSArray *)echoList:(NSArray *)list error:(FlutterError *_Nullable *_Nonnull)error; /// Returns the passed map, to test serialization and deserialization. /// @@ -341,7 +341,7 @@ NSObject *HostIntegrationCoreApiGetCodec(void); - (void)echoAsyncObject:(id)anObject completion:(void (^)(id _Nullable, FlutterError *_Nullable))completion; /// Returns the passed list, to test asynchronous serialization and deserialization. -- (void)echoAsyncList:(NSArray *)aList +- (void)echoAsyncList:(NSArray *)list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion; /// Returns the passed map, to test asynchronous serialization and deserialization. - (void)echoAsyncMap:(NSDictionary *)aMap @@ -391,7 +391,7 @@ NSObject *HostIntegrationCoreApiGetCodec(void); - (void)echoAsyncNullableObject:(nullable id)anObject completion:(void (^)(id _Nullable, FlutterError *_Nullable))completion; /// Returns the passed list, to test asynchronous serialization and deserialization. -- (void)echoAsyncNullableList:(nullable NSArray *)aList +- (void)echoAsyncNullableList:(nullable NSArray *)list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion; /// Returns the passed map, to test asynchronous serialization and deserialization. - (void)echoAsyncNullableMap:(nullable NSDictionary *)aMap @@ -437,10 +437,10 @@ NSObject *HostIntegrationCoreApiGetCodec(void); completion:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion; - (void)callFlutterEchoString:(NSString *)aString completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion; -- (void)callFlutterEchoUint8List:(FlutterStandardTypedData *)aList +- (void)callFlutterEchoUint8List:(FlutterStandardTypedData *)list completion:(void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion; -- (void)callFlutterEchoList:(NSArray *)aList +- (void)callFlutterEchoList:(NSArray *)list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion; - (void)callFlutterEchoMap:(NSDictionary *)aMap completion:(void (^)(NSDictionary *_Nullable, @@ -459,10 +459,10 @@ NSObject *HostIntegrationCoreApiGetCodec(void); - (void)callFlutterEchoNullableString:(nullable NSString *)aString completion: (void (^)(NSString *_Nullable, FlutterError *_Nullable))completion; -- (void)callFlutterEchoNullableUint8List:(nullable FlutterStandardTypedData *)aList +- (void)callFlutterEchoNullableUint8List:(nullable FlutterStandardTypedData *)list completion:(void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion; -- (void)callFlutterEchoNullableList:(nullable NSArray *)aList +- (void)callFlutterEchoNullableList:(nullable NSArray *)list completion: (void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion; - (void)callFlutterEchoNullableMap:(nullable NSDictionary *)aMap @@ -541,11 +541,11 @@ NSObject *FlutterIntegrationCoreApiGetCodec(void); - (void)echoString:(NSString *)aString completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion; /// Returns the passed byte list, to test serialization and deserialization. -- (void)echoUint8List:(FlutterStandardTypedData *)aList +- (void)echoUint8List:(FlutterStandardTypedData *)list completion: (void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion; /// Returns the passed list, to test serialization and deserialization. -- (void)echoList:(NSArray *)aList +- (void)echoList:(NSArray *)list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion; /// Returns the passed map, to test serialization and deserialization. - (void)echoMap:(NSDictionary *)aMap @@ -567,11 +567,11 @@ NSObject *FlutterIntegrationCoreApiGetCodec(void); - (void)echoNullableString:(nullable NSString *)aString completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion; /// Returns the passed byte list, to test serialization and deserialization. -- (void)echoNullableUint8List:(nullable FlutterStandardTypedData *)aList +- (void)echoNullableUint8List:(nullable FlutterStandardTypedData *)list completion:(void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion; /// Returns the passed list, to test serialization and deserialization. -- (void)echoNullableList:(nullable NSArray *)aList +- (void)echoNullableList:(nullable NSArray *)list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion; /// Returns the passed map, to test serialization and deserialization. - (void)echoNullableMap:(nullable NSDictionary *)aMap diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.m index 7d1fbdae824..fafcbcf7d73 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.m @@ -89,7 +89,7 @@ + (instancetype)makeWithABool:(BOOL)aBool a4ByteArray:(FlutterStandardTypedData *)a4ByteArray a8ByteArray:(FlutterStandardTypedData *)a8ByteArray aFloatArray:(FlutterStandardTypedData *)aFloatArray - aList:(NSArray *)aList + list:(NSArray *)list aMap:(NSDictionary *)aMap anEnum:(AnEnum)anEnum aString:(NSString *)aString @@ -103,7 +103,7 @@ + (instancetype)makeWithABool:(BOOL)aBool pigeonResult.a4ByteArray = a4ByteArray; pigeonResult.a8ByteArray = a8ByteArray; pigeonResult.aFloatArray = aFloatArray; - pigeonResult.aList = aList; + pigeonResult.list = list; pigeonResult.aMap = aMap; pigeonResult.anEnum = anEnum; pigeonResult.aString = aString; @@ -120,7 +120,7 @@ + (AllTypes *)fromList:(NSArray *)list { pigeonResult.a4ByteArray = GetNullableObjectAtIndex(list, 5); pigeonResult.a8ByteArray = GetNullableObjectAtIndex(list, 6); pigeonResult.aFloatArray = GetNullableObjectAtIndex(list, 7); - pigeonResult.aList = GetNullableObjectAtIndex(list, 8); + pigeonResult.list = GetNullableObjectAtIndex(list, 8); pigeonResult.aMap = GetNullableObjectAtIndex(list, 9); pigeonResult.anEnum = [GetNullableObjectAtIndex(list, 10) integerValue]; pigeonResult.aString = GetNullableObjectAtIndex(list, 11); @@ -140,7 +140,7 @@ - (NSArray *)toList { self.a4ByteArray ?: [NSNull null], self.a8ByteArray ?: [NSNull null], self.aFloatArray ?: [NSNull null], - self.aList ?: [NSNull null], + self.list ?: [NSNull null], self.aMap ?: [NSNull null], @(self.anEnum), self.aString ?: [NSNull null], @@ -211,8 +211,7 @@ + (AllNullableTypes *)fromList:(NSArray *)list { pigeonResult.aNullableEnum = aNullableEnum; pigeonResult.aNullableString = GetNullableObjectAtIndex(list, 14); pigeonResult.aNullableObject = GetNullableObjectAtIndex(list, 15); - pigeonResult.allNullableTypes = - [AllNullableTypes nullableFromList:(GetNullableObjectAtIndex(list, 16))]; + pigeonResult.allNullableTypes = GetNullableObjectAtIndex(list, 16); return pigeonResult; } + (nullable AllNullableTypes *)nullableFromList:(NSArray *)list { @@ -237,7 +236,7 @@ - (NSArray *)toList { : [NSNumber numberWithInteger:self.aNullableEnum.value]), self.aNullableString ?: [NSNull null], self.aNullableObject ?: [NSNull null], - (self.allNullableTypes ? [self.allNullableTypes toList] : [NSNull null]), + self.allNullableTypes ?: [NSNull null], ]; } @end @@ -343,11 +342,9 @@ + (instancetype)makeWithAllNullableTypes:(AllNullableTypes *)allNullableTypes } + (AllClassesWrapper *)fromList:(NSArray *)list { AllClassesWrapper *pigeonResult = [[AllClassesWrapper alloc] init]; - pigeonResult.allNullableTypes = - [AllNullableTypes nullableFromList:(GetNullableObjectAtIndex(list, 0))]; - pigeonResult.allNullableTypesWithoutRecursion = - [AllNullableTypesWithoutRecursion nullableFromList:(GetNullableObjectAtIndex(list, 1))]; - pigeonResult.allTypes = [AllTypes nullableFromList:(GetNullableObjectAtIndex(list, 2))]; + pigeonResult.allNullableTypes = GetNullableObjectAtIndex(list, 0); + pigeonResult.allNullableTypesWithoutRecursion = GetNullableObjectAtIndex(list, 1); + pigeonResult.allTypes = GetNullableObjectAtIndex(list, 2); return pigeonResult; } + (nullable AllClassesWrapper *)nullableFromList:(NSArray *)list { @@ -355,10 +352,9 @@ + (nullable AllClassesWrapper *)nullableFromList:(NSArray *)list { } - (NSArray *)toList { return @[ - (self.allNullableTypes ? [self.allNullableTypes toList] : [NSNull null]), - (self.allNullableTypesWithoutRecursion ? [self.allNullableTypesWithoutRecursion toList] - : [NSNull null]), - (self.allTypes ? [self.allTypes toList] : [NSNull null]), + self.allNullableTypes ?: [NSNull null], + self.allNullableTypesWithoutRecursion ?: [NSNull null], + self.allTypes ?: [NSNull null], ]; } @end @@ -740,9 +736,9 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; - NSArray *arg_aList = GetNullableObjectAtIndex(args, 0); + NSArray *arg_list = GetNullableObjectAtIndex(args, 0); FlutterError *error; - NSArray *output = [api echoList:arg_aList error:&error]; + NSArray *output = [api echoList:arg_list error:&error]; callback(wrapResult(output, error)); }]; } else { @@ -1552,8 +1548,8 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; - NSArray *arg_aList = GetNullableObjectAtIndex(args, 0); - [api echoAsyncList:arg_aList + NSArray *arg_list = GetNullableObjectAtIndex(args, 0); + [api echoAsyncList:arg_list completion:^(NSArray *_Nullable output, FlutterError *_Nullable error) { callback(wrapResult(output, error)); }]; @@ -1950,8 +1946,8 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; - NSArray *arg_aList = GetNullableObjectAtIndex(args, 0); - [api echoAsyncNullableList:arg_aList + NSArray *arg_list = GetNullableObjectAtIndex(args, 0); + [api echoAsyncNullableList:arg_list completion:^(NSArray *_Nullable output, FlutterError *_Nullable error) { callback(wrapResult(output, error)); }]; @@ -2358,8 +2354,8 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; - FlutterStandardTypedData *arg_aList = GetNullableObjectAtIndex(args, 0); - [api callFlutterEchoUint8List:arg_aList + FlutterStandardTypedData *arg_list = GetNullableObjectAtIndex(args, 0); + [api callFlutterEchoUint8List:arg_list completion:^(FlutterStandardTypedData *_Nullable output, FlutterError *_Nullable error) { callback(wrapResult(output, error)); @@ -2384,8 +2380,8 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; - NSArray *arg_aList = GetNullableObjectAtIndex(args, 0); - [api callFlutterEchoList:arg_aList + NSArray *arg_list = GetNullableObjectAtIndex(args, 0); + [api callFlutterEchoList:arg_list completion:^(NSArray *_Nullable output, FlutterError *_Nullable error) { callback(wrapResult(output, error)); }]; @@ -2571,8 +2567,8 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; - FlutterStandardTypedData *arg_aList = GetNullableObjectAtIndex(args, 0); - [api callFlutterEchoNullableUint8List:arg_aList + FlutterStandardTypedData *arg_list = GetNullableObjectAtIndex(args, 0); + [api callFlutterEchoNullableUint8List:arg_list completion:^(FlutterStandardTypedData *_Nullable output, FlutterError *_Nullable error) { callback(wrapResult(output, error)); @@ -2598,8 +2594,8 @@ void SetUpHostIntegrationCoreApiWithSuffix(id binaryMess api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; - NSArray *arg_aList = GetNullableObjectAtIndex(args, 0); - [api callFlutterEchoNullableList:arg_aList + NSArray *arg_list = GetNullableObjectAtIndex(args, 0); + [api callFlutterEchoNullableList:arg_list completion:^(NSArray *_Nullable output, FlutterError *_Nullable error) { callback(wrapResult(output, error)); @@ -3123,7 +3119,7 @@ - (void)echoString:(NSString *)arg_aString } }]; } -- (void)echoUint8List:(FlutterStandardTypedData *)arg_aList +- (void)echoUint8List:(FlutterStandardTypedData *)arg_list completion: (void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion { NSString *channelName = [NSString @@ -3135,7 +3131,7 @@ - (void)echoUint8List:(FlutterStandardTypedData *)arg_aList [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger codec:FlutterIntegrationCoreApiGetCodec()]; - [channel sendMessage:@[ arg_aList ?: [NSNull null] ] + [channel sendMessage:@[ arg_list ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { if (reply.count > 1) { @@ -3152,7 +3148,7 @@ - (void)echoUint8List:(FlutterStandardTypedData *)arg_aList } }]; } -- (void)echoList:(NSArray *)arg_aList +- (void)echoList:(NSArray *)arg_list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion { NSString *channelName = [NSString stringWithFormat: @@ -3163,7 +3159,7 @@ - (void)echoList:(NSArray *)arg_aList [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger codec:FlutterIntegrationCoreApiGetCodec()]; - [channel sendMessage:@[ arg_aList ?: [NSNull null] ] + [channel sendMessage:@[ arg_list ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { if (reply.count > 1) { @@ -3346,7 +3342,7 @@ - (void)echoNullableString:(nullable NSString *)arg_aString } }]; } -- (void)echoNullableUint8List:(nullable FlutterStandardTypedData *)arg_aList +- (void)echoNullableUint8List:(nullable FlutterStandardTypedData *)arg_list completion:(void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion { NSString *channelName = @@ -3358,7 +3354,7 @@ - (void)echoNullableUint8List:(nullable FlutterStandardTypedData *)arg_aList [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger codec:FlutterIntegrationCoreApiGetCodec()]; - [channel sendMessage:@[ arg_aList ?: [NSNull null] ] + [channel sendMessage:@[ arg_list ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { if (reply.count > 1) { @@ -3375,7 +3371,7 @@ - (void)echoNullableUint8List:(nullable FlutterStandardTypedData *)arg_aList } }]; } -- (void)echoNullableList:(nullable NSArray *)arg_aList +- (void)echoNullableList:(nullable NSArray *)arg_list completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion { NSString *channelName = [NSString stringWithFormat: @@ -3386,7 +3382,7 @@ - (void)echoNullableList:(nullable NSArray *)arg_aList [FlutterBasicMessageChannel messageChannelWithName:channelName binaryMessenger:self.binaryMessenger codec:FlutterIntegrationCoreApiGetCodec()]; - [channel sendMessage:@[ arg_aList ?: [NSNull null] ] + [channel sendMessage:@[ arg_list ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { if (reply.count > 1) { diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart index caa448cac36..85484362b3a 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart @@ -49,7 +49,7 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { expect(allTypesOne.a4ByteArray, allTypesTwo.a4ByteArray); expect(allTypesOne.a8ByteArray, allTypesTwo.a8ByteArray); expect(allTypesOne.aFloatArray, allTypesTwo.aFloatArray); - expect(listEquals(allTypesOne.aList, allTypesTwo.aList), true); + expect(listEquals(allTypesOne.list, allTypesTwo.list), true); expect(mapEquals(allTypesOne.aMap, allTypesTwo.aMap), true); expect(allTypesOne.anEnum, allTypesTwo.anEnum); expect(allTypesOne.anObject, allTypesTwo.anObject); @@ -190,7 +190,7 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { a4ByteArray: Int32List.fromList([4, 5, 6]), a8ByteArray: Int64List.fromList([7, 8, 9]), aFloatArray: Float64List.fromList([2.71828, _doublePi]), - aList: ['Thing 1', 2, true, 3.14, null], + list: ['Thing 1', 2, true, 3.14, null], aMap: { 'a': 1, 'b': 2.0, @@ -1863,10 +1863,10 @@ class _FlutterApiTestImplementation implements FlutterIntegrationCoreApi { String echoString(String aString) => aString; @override - Uint8List echoUint8List(Uint8List aList) => aList; + Uint8List echoUint8List(Uint8List list) => list; @override - List echoList(List aList) => aList; + List echoList(List list) => list; @override Map echoMap(Map aMap) => aMap; @@ -1884,7 +1884,7 @@ class _FlutterApiTestImplementation implements FlutterIntegrationCoreApi { int? echoNullableInt(int? anInt) => anInt; @override - List? echoNullableList(List? aList) => aList; + List? echoNullableList(List? list) => list; @override Map? echoNullableMap(Map? aMap) => aMap; @@ -1893,7 +1893,7 @@ class _FlutterApiTestImplementation implements FlutterIntegrationCoreApi { String? echoNullableString(String? aString) => aString; @override - Uint8List? echoNullableUint8List(Uint8List? aList) => aList; + Uint8List? echoNullableUint8List(Uint8List? list) => list; @override AnEnum? echoNullableEnum(AnEnum? anEnum) => anEnum; diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart index 9c164946626..2f24cdcb2ca 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart @@ -49,7 +49,7 @@ class AllTypes { required this.a4ByteArray, required this.a8ByteArray, required this.aFloatArray, - this.aList = const [], + this.list = const [], this.aMap = const {}, this.anEnum = AnEnum.one, this.aString = '', @@ -72,7 +72,7 @@ class AllTypes { Float64List aFloatArray; - List aList; + List list; Map aMap; @@ -92,7 +92,7 @@ class AllTypes { a4ByteArray, a8ByteArray, aFloatArray, - aList, + list, aMap, anEnum.index, aString, @@ -111,7 +111,7 @@ class AllTypes { a4ByteArray: result[5]! as Int32List, a8ByteArray: result[6]! as Int64List, aFloatArray: result[7]! as Float64List, - aList: result[8]! as List, + list: result[8]! as List, aMap: result[9]! as Map, anEnum: AnEnum.values[result[10]! as int], aString: result[11]! as String, @@ -194,7 +194,7 @@ class AllNullableTypes { aNullableEnum?.index, aNullableString, aNullableObject, - allNullableTypes?.encode(), + allNullableTypes, ]; } @@ -220,9 +220,7 @@ class AllNullableTypes { result[13] != null ? AnEnum.values[result[13]! as int] : null, aNullableString: result[14] as String?, aNullableObject: result[15], - allNullableTypes: result[16] != null - ? AllNullableTypes.decode(result[16]! as List) - : null, + allNullableTypes: result[16] as AllNullableTypes?, ); } } @@ -349,22 +347,19 @@ class AllClassesWrapper { Object encode() { return [ - allNullableTypes.encode(), - allNullableTypesWithoutRecursion?.encode(), - allTypes?.encode(), + allNullableTypes, + allNullableTypesWithoutRecursion, + allTypes, ]; } static AllClassesWrapper decode(Object result) { result as List; return AllClassesWrapper( - allNullableTypes: AllNullableTypes.decode(result[0]! as List), - allNullableTypesWithoutRecursion: result[1] != null - ? AllNullableTypesWithoutRecursion.decode(result[1]! as List) - : null, - allTypes: result[2] != null - ? AllTypes.decode(result[2]! as List) - : null, + allNullableTypes: result[0]! as AllNullableTypes, + allNullableTypesWithoutRecursion: + result[1] as AllNullableTypesWithoutRecursion?, + allTypes: result[2] as AllTypes?, ); } } @@ -764,7 +759,7 @@ class HostIntegrationCoreApi { } /// Returns the passed list, to test serialization and deserialization. - Future> echoList(List aList) async { + Future> echoList(List list) async { final String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoList$__pigeon_messageChannelSuffix'; final BasicMessageChannel __pigeon_channel = @@ -774,7 +769,7 @@ class HostIntegrationCoreApi { binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - await __pigeon_channel.send([aList]) as List?; + await __pigeon_channel.send([list]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -1636,7 +1631,7 @@ class HostIntegrationCoreApi { } /// Returns the passed list, to test asynchronous serialization and deserialization. - Future> echoAsyncList(List aList) async { + Future> echoAsyncList(List list) async { final String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncList$__pigeon_messageChannelSuffix'; final BasicMessageChannel __pigeon_channel = @@ -1646,7 +1641,7 @@ class HostIntegrationCoreApi { binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - await __pigeon_channel.send([aList]) as List?; + await __pigeon_channel.send([list]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -2035,7 +2030,7 @@ class HostIntegrationCoreApi { } /// Returns the passed list, to test asynchronous serialization and deserialization. - Future?> echoAsyncNullableList(List? aList) async { + Future?> echoAsyncNullableList(List? list) async { final String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncNullableList$__pigeon_messageChannelSuffix'; final BasicMessageChannel __pigeon_channel = @@ -2045,7 +2040,7 @@ class HostIntegrationCoreApi { binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - await __pigeon_channel.send([aList]) as List?; + await __pigeon_channel.send([list]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -2444,7 +2439,7 @@ class HostIntegrationCoreApi { } } - Future callFlutterEchoUint8List(Uint8List aList) async { + Future callFlutterEchoUint8List(Uint8List list) async { final String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoUint8List$__pigeon_messageChannelSuffix'; final BasicMessageChannel __pigeon_channel = @@ -2454,7 +2449,7 @@ class HostIntegrationCoreApi { binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - await __pigeon_channel.send([aList]) as List?; + await __pigeon_channel.send([list]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -2473,7 +2468,7 @@ class HostIntegrationCoreApi { } } - Future> callFlutterEchoList(List aList) async { + Future> callFlutterEchoList(List list) async { final String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoList$__pigeon_messageChannelSuffix'; final BasicMessageChannel __pigeon_channel = @@ -2483,7 +2478,7 @@ class HostIntegrationCoreApi { binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - await __pigeon_channel.send([aList]) as List?; + await __pigeon_channel.send([list]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -2658,7 +2653,7 @@ class HostIntegrationCoreApi { } } - Future callFlutterEchoNullableUint8List(Uint8List? aList) async { + Future callFlutterEchoNullableUint8List(Uint8List? list) async { final String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoNullableUint8List$__pigeon_messageChannelSuffix'; final BasicMessageChannel __pigeon_channel = @@ -2668,7 +2663,7 @@ class HostIntegrationCoreApi { binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - await __pigeon_channel.send([aList]) as List?; + await __pigeon_channel.send([list]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -2683,7 +2678,7 @@ class HostIntegrationCoreApi { } Future?> callFlutterEchoNullableList( - List? aList) async { + List? list) async { final String __pigeon_channelName = 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoNullableList$__pigeon_messageChannelSuffix'; final BasicMessageChannel __pigeon_channel = @@ -2693,7 +2688,7 @@ class HostIntegrationCoreApi { binaryMessenger: __pigeon_binaryMessenger, ); final List? __pigeon_replyList = - await __pigeon_channel.send([aList]) as List?; + await __pigeon_channel.send([list]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -2883,10 +2878,10 @@ abstract class FlutterIntegrationCoreApi { String echoString(String aString); /// Returns the passed byte list, to test serialization and deserialization. - Uint8List echoUint8List(Uint8List aList); + Uint8List echoUint8List(Uint8List list); /// Returns the passed list, to test serialization and deserialization. - List echoList(List aList); + List echoList(List list); /// Returns the passed map, to test serialization and deserialization. Map echoMap(Map aMap); @@ -2907,10 +2902,10 @@ abstract class FlutterIntegrationCoreApi { String? echoNullableString(String? aString); /// Returns the passed byte list, to test serialization and deserialization. - Uint8List? echoNullableUint8List(Uint8List? aList); + Uint8List? echoNullableUint8List(Uint8List? list); /// Returns the passed list, to test serialization and deserialization. - List? echoNullableList(List? aList); + List? echoNullableList(List? list); /// Returns the passed map, to test serialization and deserialization. Map? echoNullableMap(Map? aMap); @@ -3266,11 +3261,11 @@ abstract class FlutterIntegrationCoreApi { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoUint8List was null.'); final List args = (message as List?)!; - final Uint8List? arg_aList = (args[0] as Uint8List?); - assert(arg_aList != null, + final Uint8List? arg_list = (args[0] as Uint8List?); + assert(arg_list != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoUint8List was null, expected non-null Uint8List.'); try { - final Uint8List output = api.echoUint8List(arg_aList!); + final Uint8List output = api.echoUint8List(arg_list!); return wrapResponse(result: output); } on PlatformException catch (e) { return wrapResponse(error: e); @@ -3294,12 +3289,12 @@ abstract class FlutterIntegrationCoreApi { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoList was null.'); final List args = (message as List?)!; - final List? arg_aList = + final List? arg_list = (args[0] as List?)?.cast(); - assert(arg_aList != null, + assert(arg_list != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoList was null, expected non-null List.'); try { - final List output = api.echoList(arg_aList!); + final List output = api.echoList(arg_list!); return wrapResponse(result: output); } on PlatformException catch (e) { return wrapResponse(error: e); @@ -3485,9 +3480,9 @@ abstract class FlutterIntegrationCoreApi { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableUint8List was null.'); final List args = (message as List?)!; - final Uint8List? arg_aList = (args[0] as Uint8List?); + final Uint8List? arg_list = (args[0] as Uint8List?); try { - final Uint8List? output = api.echoNullableUint8List(arg_aList); + final Uint8List? output = api.echoNullableUint8List(arg_list); return wrapResponse(result: output); } on PlatformException catch (e) { return wrapResponse(error: e); @@ -3511,10 +3506,10 @@ abstract class FlutterIntegrationCoreApi { assert(message != null, 'Argument for dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableList was null.'); final List args = (message as List?)!; - final List? arg_aList = + final List? arg_list = (args[0] as List?)?.cast(); try { - final List? output = api.echoNullableList(arg_aList); + final List? output = api.echoNullableList(arg_list); return wrapResponse(result: output); } on PlatformException catch (e) { return wrapResponse(error: e); diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/message.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/message.gen.dart index 044b792995e..c4f744b5fb8 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/message.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/message.gen.dart @@ -130,16 +130,14 @@ class MessageNested { Object encode() { return [ - request?.encode(), + request, ]; } static MessageNested decode(Object result) { result as List; return MessageNested( - request: result[0] != null - ? MessageSearchRequest.decode(result[0]! as List) - : null, + request: result[0] as MessageSearchRequest?, ); } } diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/non_null_fields.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/non_null_fields.gen.dart index dcfe61bb0ad..8f3560363e0 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/non_null_fields.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/non_null_fields.gen.dart @@ -106,7 +106,7 @@ class NonNullFieldSearchReply { result, error, indices, - extraData.encode(), + extraData, type.index, ]; } @@ -117,7 +117,7 @@ class NonNullFieldSearchReply { result: result[0]! as String, error: result[1]! as String, indices: (result[2] as List?)!.cast(), - extraData: ExtraData.decode(result[3]! as List), + extraData: result[3]! as ExtraData, type: ReplyType.values[result[4]! as int], ); } diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/null_fields.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/null_fields.gen.dart index 940dd315b48..3af44e61683 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/null_fields.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/null_fields.gen.dart @@ -85,7 +85,7 @@ class NullFieldsSearchReply { result, error, indices, - request?.encode(), + request, type?.index, ]; } @@ -96,9 +96,7 @@ class NullFieldsSearchReply { result: result[0] as String?, error: result[1] as String?, indices: (result[2] as List?)?.cast(), - request: result[3] != null - ? NullFieldsSearchRequest.decode(result[3]! as List) - : null, + request: result[3] as NullFieldsSearchRequest?, type: result[4] != null ? NullFieldsSearchReplyType.values[result[4]! as int] : null, diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/test/null_fields_test.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/test/null_fields_test.dart index 112317a3895..aa0ecb02424 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/test/null_fields_test.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/test/null_fields_test.dart @@ -63,16 +63,17 @@ void main() { }); test('test reply decode with values', () { - final NullFieldsSearchReply reply = NullFieldsSearchReply.decode([ - 'result', - 'error', - [1, 2, 3], - [ - 'query', - 1, - ], - NullFieldsSearchReplyType.success.index, - ]); + final NullFieldsSearchReply reply = + NullFieldsSearchReply.decode(NullFieldsSearchReply( + result: 'result', + error: 'error', + indices: [1, 2, 3], + request: NullFieldsSearchRequest( + query: 'query', + identifier: 1, + ), + type: NullFieldsSearchReplyType.success, + ).encode()); expect(reply.result, 'result'); expect(reply.error, 'error'); @@ -118,11 +119,13 @@ void main() { }); test('test reply encode with values', () { + final NullFieldsSearchRequest request = + NullFieldsSearchRequest(query: 'query', identifier: 1); final NullFieldsSearchReply reply = NullFieldsSearchReply( result: 'result', error: 'error', indices: [1, 2, 3], - request: NullFieldsSearchRequest(query: 'query', identifier: 1), + request: request, type: NullFieldsSearchReplyType.success, ); @@ -130,10 +133,7 @@ void main() { 'result', 'error', [1, 2, 3], - [ - 'query', - 1, - ], + request, NullFieldsSearchReplyType.success.index, ]); }); diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt index 2d462d760cc..3668ec94738 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt @@ -4,6 +4,7 @@ // // Autogenerated from Pigeon, do not edit directly. // See also: https://pub.dev/packages/pigeon +@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass") package com.example.test_plugin @@ -20,10 +21,10 @@ private fun wrapResult(result: Any?): List { } private fun wrapError(exception: Throwable): List { - if (exception is FlutterError) { - return listOf(exception.code, exception.message, exception.details) + return if (exception is FlutterError) { + listOf(exception.code, exception.message, exception.details) } else { - return listOf( + listOf( exception.javaClass.simpleName, exception.toString(), "Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception)) @@ -63,28 +64,28 @@ data class AllTypes( val a4ByteArray: IntArray, val a8ByteArray: LongArray, val aFloatArray: DoubleArray, - val aList: List, + val list: List, val aMap: Map, val anEnum: AnEnum, val aString: String, val anObject: Any ) { companion object { - @Suppress("UNCHECKED_CAST") - fun fromList(list: List): AllTypes { - val aBool = list[0] as Boolean - val anInt = list[1].let { if (it is Int) it.toLong() else it as Long } - val anInt64 = list[2].let { if (it is Int) it.toLong() else it as Long } - val aDouble = list[3] as Double - val aByteArray = list[4] as ByteArray - val a4ByteArray = list[5] as IntArray - val a8ByteArray = list[6] as LongArray - val aFloatArray = list[7] as DoubleArray - val aList = list[8] as List - val aMap = list[9] as Map - val anEnum = AnEnum.ofRaw(list[10] as Int)!! - val aString = list[11] as String - val anObject = list[12] as Any + @Suppress("LocalVariableName") + fun fromList(__pigeon_list: List): AllTypes { + val aBool = __pigeon_list[0] as Boolean + val anInt = __pigeon_list[1].let { num -> if (num is Int) num.toLong() else num as Long } + val anInt64 = __pigeon_list[2].let { num -> if (num is Int) num.toLong() else num as Long } + val aDouble = __pigeon_list[3] as Double + val aByteArray = __pigeon_list[4] as ByteArray + val a4ByteArray = __pigeon_list[5] as IntArray + val a8ByteArray = __pigeon_list[6] as LongArray + val aFloatArray = __pigeon_list[7] as DoubleArray + val list = __pigeon_list[8] as List + val aMap = __pigeon_list[9] as Map + val anEnum = AnEnum.ofRaw(__pigeon_list[10] as Int)!! + val aString = __pigeon_list[11] as String + val anObject = __pigeon_list[12] as Any return AllTypes( aBool, anInt, @@ -94,7 +95,7 @@ data class AllTypes( a4ByteArray, a8ByteArray, aFloatArray, - aList, + list, aMap, anEnum, aString, @@ -112,7 +113,7 @@ data class AllTypes( a4ByteArray, a8ByteArray, aFloatArray, - aList, + list, aMap, anEnum.raw, aString, @@ -146,26 +147,27 @@ data class AllNullableTypes( val allNullableTypes: AllNullableTypes? = null ) { companion object { - @Suppress("UNCHECKED_CAST") - fun fromList(list: List): AllNullableTypes { - val aNullableBool = list[0] as Boolean? - val aNullableInt = list[1].let { if (it is Int) it.toLong() else it as Long? } - val aNullableInt64 = list[2].let { if (it is Int) it.toLong() else it as Long? } - val aNullableDouble = list[3] as Double? - val aNullableByteArray = list[4] as ByteArray? - val aNullable4ByteArray = list[5] as IntArray? - val aNullable8ByteArray = list[6] as LongArray? - val aNullableFloatArray = list[7] as DoubleArray? - val aNullableList = list[8] as List? - val aNullableMap = list[9] as Map? - val nullableNestedList = list[10] as List?>? - val nullableMapWithAnnotations = list[11] as Map? - val nullableMapWithObject = list[12] as Map? - val aNullableEnum: AnEnum? = (list[13] as Int?)?.let { AnEnum.ofRaw(it) } - val aNullableString = list[14] as String? - val aNullableObject = list[15] - val allNullableTypes: AllNullableTypes? = - (list[16] as List?)?.let { AllNullableTypes.fromList(it) } + @Suppress("LocalVariableName") + fun fromList(__pigeon_list: List): AllNullableTypes { + val aNullableBool = __pigeon_list[0] as Boolean? + val aNullableInt = + __pigeon_list[1].let { num -> if (num is Int) num.toLong() else num as Long? } + val aNullableInt64 = + __pigeon_list[2].let { num -> if (num is Int) num.toLong() else num as Long? } + val aNullableDouble = __pigeon_list[3] as Double? + val aNullableByteArray = __pigeon_list[4] as ByteArray? + val aNullable4ByteArray = __pigeon_list[5] as IntArray? + val aNullable8ByteArray = __pigeon_list[6] as LongArray? + val aNullableFloatArray = __pigeon_list[7] as DoubleArray? + val aNullableList = __pigeon_list[8] as List? + val aNullableMap = __pigeon_list[9] as Map? + val nullableNestedList = __pigeon_list[10] as List?>? + val nullableMapWithAnnotations = __pigeon_list[11] as Map? + val nullableMapWithObject = __pigeon_list[12] as Map? + val aNullableEnum: AnEnum? = (__pigeon_list[13] as Int?)?.let { num -> AnEnum.ofRaw(num) } + val aNullableString = __pigeon_list[14] as String? + val aNullableObject = __pigeon_list[15] + val allNullableTypes = __pigeon_list[16] as AllNullableTypes? return AllNullableTypes( aNullableBool, aNullableInt, @@ -205,7 +207,7 @@ data class AllNullableTypes( aNullableEnum?.raw, aNullableString, aNullableObject, - allNullableTypes?.toList(), + allNullableTypes, ) } } @@ -235,24 +237,26 @@ data class AllNullableTypesWithoutRecursion( val aNullableObject: Any? = null ) { companion object { - @Suppress("UNCHECKED_CAST") - fun fromList(list: List): AllNullableTypesWithoutRecursion { - val aNullableBool = list[0] as Boolean? - val aNullableInt = list[1].let { if (it is Int) it.toLong() else it as Long? } - val aNullableInt64 = list[2].let { if (it is Int) it.toLong() else it as Long? } - val aNullableDouble = list[3] as Double? - val aNullableByteArray = list[4] as ByteArray? - val aNullable4ByteArray = list[5] as IntArray? - val aNullable8ByteArray = list[6] as LongArray? - val aNullableFloatArray = list[7] as DoubleArray? - val aNullableList = list[8] as List? - val aNullableMap = list[9] as Map? - val nullableNestedList = list[10] as List?>? - val nullableMapWithAnnotations = list[11] as Map? - val nullableMapWithObject = list[12] as Map? - val aNullableEnum: AnEnum? = (list[13] as Int?)?.let { AnEnum.ofRaw(it) } - val aNullableString = list[14] as String? - val aNullableObject = list[15] + @Suppress("LocalVariableName") + fun fromList(__pigeon_list: List): AllNullableTypesWithoutRecursion { + val aNullableBool = __pigeon_list[0] as Boolean? + val aNullableInt = + __pigeon_list[1].let { num -> if (num is Int) num.toLong() else num as Long? } + val aNullableInt64 = + __pigeon_list[2].let { num -> if (num is Int) num.toLong() else num as Long? } + val aNullableDouble = __pigeon_list[3] as Double? + val aNullableByteArray = __pigeon_list[4] as ByteArray? + val aNullable4ByteArray = __pigeon_list[5] as IntArray? + val aNullable8ByteArray = __pigeon_list[6] as LongArray? + val aNullableFloatArray = __pigeon_list[7] as DoubleArray? + val aNullableList = __pigeon_list[8] as List? + val aNullableMap = __pigeon_list[9] as Map? + val nullableNestedList = __pigeon_list[10] as List?>? + val nullableMapWithAnnotations = __pigeon_list[11] as Map? + val nullableMapWithObject = __pigeon_list[12] as Map? + val aNullableEnum: AnEnum? = (__pigeon_list[13] as Int?)?.let { num -> AnEnum.ofRaw(num) } + val aNullableString = __pigeon_list[14] as String? + val aNullableObject = __pigeon_list[15] return AllNullableTypesWithoutRecursion( aNullableBool, aNullableInt, @@ -310,21 +314,20 @@ data class AllClassesWrapper( val allTypes: AllTypes? = null ) { companion object { - @Suppress("UNCHECKED_CAST") - fun fromList(list: List): AllClassesWrapper { - val allNullableTypes = AllNullableTypes.fromList(list[0] as List) - val allNullableTypesWithoutRecursion: AllNullableTypesWithoutRecursion? = - (list[1] as List?)?.let { AllNullableTypesWithoutRecursion.fromList(it) } - val allTypes: AllTypes? = (list[2] as List?)?.let { AllTypes.fromList(it) } + @Suppress("LocalVariableName") + fun fromList(__pigeon_list: List): AllClassesWrapper { + val allNullableTypes = __pigeon_list[0] as AllNullableTypes + val allNullableTypesWithoutRecursion = __pigeon_list[1] as AllNullableTypesWithoutRecursion? + val allTypes = __pigeon_list[2] as AllTypes? return AllClassesWrapper(allNullableTypes, allNullableTypesWithoutRecursion, allTypes) } } fun toList(): List { return listOf( - allNullableTypes.toList(), - allNullableTypesWithoutRecursion?.toList(), - allTypes?.toList(), + allNullableTypes, + allNullableTypesWithoutRecursion, + allTypes, ) } } @@ -337,9 +340,9 @@ data class AllClassesWrapper( data class TestMessage(val testList: List? = null) { companion object { - @Suppress("UNCHECKED_CAST") - fun fromList(list: List): TestMessage { - val testList = list[0] as List? + @Suppress("LocalVariableName") + fun fromList(__pigeon_list: List): TestMessage { + val testList = __pigeon_list[0] as List? return TestMessage(testList) } } @@ -351,7 +354,6 @@ data class TestMessage(val testList: List? = null) { } } -@Suppress("UNCHECKED_CAST") private object HostIntegrationCoreApiCodec : StandardMessageCodec() { override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { return when (type) { @@ -433,7 +435,7 @@ interface HostIntegrationCoreApi { /** Returns the passed in generic Object. */ fun echoObject(anObject: Any): Any /** Returns the passed list, to test serialization and deserialization. */ - fun echoList(aList: List): List + fun echoList(list: List): List /** Returns the passed map, to test serialization and deserialization. */ fun echoMap(aMap: Map): Map /** Returns the passed map to test nested class serialization and deserialization. */ @@ -512,7 +514,7 @@ interface HostIntegrationCoreApi { /** Returns the passed in generic Object asynchronously. */ fun echoAsyncObject(anObject: Any, callback: (Result) -> Unit) /** Returns the passed list, to test asynchronous serialization and deserialization. */ - fun echoAsyncList(aList: List, callback: (Result>) -> Unit) + fun echoAsyncList(list: List, callback: (Result>) -> Unit) /** Returns the passed map, to test asynchronous serialization and deserialization. */ fun echoAsyncMap(aMap: Map, callback: (Result>) -> Unit) /** Returns the passed enum, to test asynchronous serialization and deserialization. */ @@ -548,7 +550,7 @@ interface HostIntegrationCoreApi { /** Returns the passed in generic Object asynchronously. */ fun echoAsyncNullableObject(anObject: Any?, callback: (Result) -> Unit) /** Returns the passed list, to test asynchronous serialization and deserialization. */ - fun echoAsyncNullableList(aList: List?, callback: (Result?>) -> Unit) + fun echoAsyncNullableList(list: List?, callback: (Result?>) -> Unit) /** Returns the passed map, to test asynchronous serialization and deserialization. */ fun echoAsyncNullableMap( aMap: Map?, @@ -597,9 +599,9 @@ interface HostIntegrationCoreApi { fun callFlutterEchoString(aString: String, callback: (Result) -> Unit) - fun callFlutterEchoUint8List(aList: ByteArray, callback: (Result) -> Unit) + fun callFlutterEchoUint8List(list: ByteArray, callback: (Result) -> Unit) - fun callFlutterEchoList(aList: List, callback: (Result>) -> Unit) + fun callFlutterEchoList(list: List, callback: (Result>) -> Unit) fun callFlutterEchoMap(aMap: Map, callback: (Result>) -> Unit) @@ -613,9 +615,9 @@ interface HostIntegrationCoreApi { fun callFlutterEchoNullableString(aString: String?, callback: (Result) -> Unit) - fun callFlutterEchoNullableUint8List(aList: ByteArray?, callback: (Result) -> Unit) + fun callFlutterEchoNullableUint8List(list: ByteArray?, callback: (Result) -> Unit) - fun callFlutterEchoNullableList(aList: List?, callback: (Result?>) -> Unit) + fun callFlutterEchoNullableList(list: List?, callback: (Result?>) -> Unit) fun callFlutterEchoNullableMap( aMap: Map?, @@ -633,7 +635,6 @@ interface HostIntegrationCoreApi { * Sets up an instance of `HostIntegrationCoreApi` to handle messages through the * `binaryMessenger`. */ - @Suppress("UNCHECKED_CAST") fun setUp( binaryMessenger: BinaryMessenger, api: HostIntegrationCoreApi?, @@ -649,13 +650,13 @@ interface HostIntegrationCoreApi { codec) if (api != null) { channel.setMessageHandler { _, reply -> - var wrapped: List - try { - api.noop() - wrapped = listOf(null) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + api.noop() + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -672,12 +673,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val everythingArg = args[0] as AllTypes - var wrapped: List - try { - wrapped = listOf(api.echoAllTypes(everythingArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoAllTypes(everythingArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -692,12 +693,12 @@ interface HostIntegrationCoreApi { codec) if (api != null) { channel.setMessageHandler { _, reply -> - var wrapped: List - try { - wrapped = listOf(api.throwError()) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.throwError()) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -712,13 +713,13 @@ interface HostIntegrationCoreApi { codec) if (api != null) { channel.setMessageHandler { _, reply -> - var wrapped: List - try { - api.throwErrorFromVoid() - wrapped = listOf(null) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + api.throwErrorFromVoid() + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -733,12 +734,12 @@ interface HostIntegrationCoreApi { codec) if (api != null) { channel.setMessageHandler { _, reply -> - var wrapped: List - try { - wrapped = listOf(api.throwFlutterError()) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.throwFlutterError()) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -754,13 +755,13 @@ interface HostIntegrationCoreApi { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List - val anIntArg = args[0].let { if (it is Int) it.toLong() else it as Long } - var wrapped: List - try { - wrapped = listOf(api.echoInt(anIntArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val anIntArg = args[0].let { num -> if (num is Int) num.toLong() else num as Long } + val wrapped: List = + try { + listOf(api.echoInt(anIntArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -777,12 +778,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aDoubleArg = args[0] as Double - var wrapped: List - try { - wrapped = listOf(api.echoDouble(aDoubleArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoDouble(aDoubleArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -799,12 +800,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aBoolArg = args[0] as Boolean - var wrapped: List - try { - wrapped = listOf(api.echoBool(aBoolArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoBool(aBoolArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -821,12 +822,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aStringArg = args[0] as String - var wrapped: List - try { - wrapped = listOf(api.echoString(aStringArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoString(aStringArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -843,12 +844,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aUint8ListArg = args[0] as ByteArray - var wrapped: List - try { - wrapped = listOf(api.echoUint8List(aUint8ListArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoUint8List(aUint8ListArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -865,12 +866,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val anObjectArg = args[0] as Any - var wrapped: List - try { - wrapped = listOf(api.echoObject(anObjectArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoObject(anObjectArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -886,13 +887,13 @@ interface HostIntegrationCoreApi { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List - val aListArg = args[0] as List - var wrapped: List - try { - wrapped = listOf(api.echoList(aListArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val listArg = args[0] as List + val wrapped: List = + try { + listOf(api.echoList(listArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -909,12 +910,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aMapArg = args[0] as Map - var wrapped: List - try { - wrapped = listOf(api.echoMap(aMapArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoMap(aMapArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -931,12 +932,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val wrapperArg = args[0] as AllClassesWrapper - var wrapped: List - try { - wrapped = listOf(api.echoClassWrapper(wrapperArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoClassWrapper(wrapperArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -953,12 +954,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val anEnumArg = AnEnum.ofRaw(args[0] as Int)!! - var wrapped: List - try { - wrapped = listOf(api.echoEnum(anEnumArg).raw) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoEnum(anEnumArg).raw) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -975,12 +976,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aStringArg = args[0] as String - var wrapped: List - try { - wrapped = listOf(api.echoNamedDefaultString(aStringArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoNamedDefaultString(aStringArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -997,12 +998,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aDoubleArg = args[0] as Double - var wrapped: List - try { - wrapped = listOf(api.echoOptionalDefaultDouble(aDoubleArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoOptionalDefaultDouble(aDoubleArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1018,13 +1019,13 @@ interface HostIntegrationCoreApi { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List - val anIntArg = args[0].let { if (it is Int) it.toLong() else it as Long } - var wrapped: List - try { - wrapped = listOf(api.echoRequiredInt(anIntArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val anIntArg = args[0].let { num -> if (num is Int) num.toLong() else num as Long } + val wrapped: List = + try { + listOf(api.echoRequiredInt(anIntArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1041,12 +1042,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val everythingArg = args[0] as AllNullableTypes? - var wrapped: List - try { - wrapped = listOf(api.echoAllNullableTypes(everythingArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoAllNullableTypes(everythingArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1063,12 +1064,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val everythingArg = args[0] as AllNullableTypesWithoutRecursion? - var wrapped: List - try { - wrapped = listOf(api.echoAllNullableTypesWithoutRecursion(everythingArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoAllNullableTypesWithoutRecursion(everythingArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1085,12 +1086,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val wrapperArg = args[0] as AllClassesWrapper - var wrapped: List - try { - wrapped = listOf(api.extractNestedNullableString(wrapperArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.extractNestedNullableString(wrapperArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1107,12 +1108,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val nullableStringArg = args[0] as String? - var wrapped: List - try { - wrapped = listOf(api.createNestedNullableString(nullableStringArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.createNestedNullableString(nullableStringArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1129,17 +1130,17 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aNullableBoolArg = args[0] as Boolean? - val aNullableIntArg = args[1].let { if (it is Int) it.toLong() else it as Long? } + val aNullableIntArg = + args[1].let { num -> if (num is Int) num.toLong() else num as Long? } val aNullableStringArg = args[2] as String? - var wrapped: List - try { - wrapped = + val wrapped: List = + try { listOf( api.sendMultipleNullableTypes( aNullableBoolArg, aNullableIntArg, aNullableStringArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1156,17 +1157,17 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aNullableBoolArg = args[0] as Boolean? - val aNullableIntArg = args[1].let { if (it is Int) it.toLong() else it as Long? } + val aNullableIntArg = + args[1].let { num -> if (num is Int) num.toLong() else num as Long? } val aNullableStringArg = args[2] as String? - var wrapped: List - try { - wrapped = + val wrapped: List = + try { listOf( api.sendMultipleNullableTypesWithoutRecursion( aNullableBoolArg, aNullableIntArg, aNullableStringArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1182,13 +1183,14 @@ interface HostIntegrationCoreApi { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List - val aNullableIntArg = args[0].let { if (it is Int) it.toLong() else it as Long? } - var wrapped: List - try { - wrapped = listOf(api.echoNullableInt(aNullableIntArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val aNullableIntArg = + args[0].let { num -> if (num is Int) num.toLong() else num as Long? } + val wrapped: List = + try { + listOf(api.echoNullableInt(aNullableIntArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1205,12 +1207,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aNullableDoubleArg = args[0] as Double? - var wrapped: List - try { - wrapped = listOf(api.echoNullableDouble(aNullableDoubleArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoNullableDouble(aNullableDoubleArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1227,12 +1229,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aNullableBoolArg = args[0] as Boolean? - var wrapped: List - try { - wrapped = listOf(api.echoNullableBool(aNullableBoolArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoNullableBool(aNullableBoolArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1249,12 +1251,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aNullableStringArg = args[0] as String? - var wrapped: List - try { - wrapped = listOf(api.echoNullableString(aNullableStringArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoNullableString(aNullableStringArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1271,12 +1273,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aNullableUint8ListArg = args[0] as ByteArray? - var wrapped: List - try { - wrapped = listOf(api.echoNullableUint8List(aNullableUint8ListArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoNullableUint8List(aNullableUint8ListArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1293,12 +1295,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aNullableObjectArg = args[0] - var wrapped: List - try { - wrapped = listOf(api.echoNullableObject(aNullableObjectArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoNullableObject(aNullableObjectArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1315,12 +1317,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aNullableListArg = args[0] as List? - var wrapped: List - try { - wrapped = listOf(api.echoNullableList(aNullableListArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoNullableList(aNullableListArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1337,12 +1339,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aNullableMapArg = args[0] as Map? - var wrapped: List - try { - wrapped = listOf(api.echoNullableMap(aNullableMapArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoNullableMap(aNullableMapArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1359,12 +1361,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val anEnumArg = if (args[0] == null) null else AnEnum.ofRaw(args[0] as Int) - var wrapped: List - try { - wrapped = listOf(api.echoNullableEnum(anEnumArg)?.raw) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoNullableEnum(anEnumArg)?.raw) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1380,13 +1382,14 @@ interface HostIntegrationCoreApi { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List - val aNullableIntArg = args[0].let { if (it is Int) it.toLong() else it as Long? } - var wrapped: List - try { - wrapped = listOf(api.echoOptionalNullableInt(aNullableIntArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val aNullableIntArg = + args[0].let { num -> if (num is Int) num.toLong() else num as Long? } + val wrapped: List = + try { + listOf(api.echoOptionalNullableInt(aNullableIntArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1403,12 +1406,12 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aNullableStringArg = args[0] as String? - var wrapped: List - try { - wrapped = listOf(api.echoNamedNullableString(aNullableStringArg)) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + listOf(api.echoNamedNullableString(aNullableStringArg)) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -1445,7 +1448,7 @@ interface HostIntegrationCoreApi { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List - val anIntArg = args[0].let { if (it is Int) it.toLong() else it as Long } + val anIntArg = args[0].let { num -> if (num is Int) num.toLong() else num as Long } api.echoAsyncInt(anIntArg) { result: Result -> val error = result.exceptionOrNull() if (error != null) { @@ -1589,8 +1592,8 @@ interface HostIntegrationCoreApi { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List - val aListArg = args[0] as List - api.echoAsyncList(aListArg) { result: Result> -> + val listArg = args[0] as List + api.echoAsyncList(listArg) { result: Result> -> val error = result.exceptionOrNull() if (error != null) { reply.reply(wrapError(error)) @@ -1800,7 +1803,7 @@ interface HostIntegrationCoreApi { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List - val anIntArg = args[0].let { if (it is Int) it.toLong() else it as Long? } + val anIntArg = args[0].let { num -> if (num is Int) num.toLong() else num as Long? } api.echoAsyncNullableInt(anIntArg) { result: Result -> val error = result.exceptionOrNull() if (error != null) { @@ -1944,8 +1947,8 @@ interface HostIntegrationCoreApi { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List - val aListArg = args[0] as List? - api.echoAsyncNullableList(aListArg) { result: Result?> -> + val listArg = args[0] as List? + api.echoAsyncNullableList(listArg) { result: Result?> -> val error = result.exceptionOrNull() if (error != null) { reply.reply(wrapError(error)) @@ -2130,7 +2133,8 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aNullableBoolArg = args[0] as Boolean? - val aNullableIntArg = args[1].let { if (it is Int) it.toLong() else it as Long? } + val aNullableIntArg = + args[1].let { num -> if (num is Int) num.toLong() else num as Long? } val aNullableStringArg = args[2] as String? api.callFlutterSendMultipleNullableTypes( aNullableBoolArg, aNullableIntArg, aNullableStringArg) { @@ -2183,7 +2187,8 @@ interface HostIntegrationCoreApi { channel.setMessageHandler { message, reply -> val args = message as List val aNullableBoolArg = args[0] as Boolean? - val aNullableIntArg = args[1].let { if (it is Int) it.toLong() else it as Long? } + val aNullableIntArg = + args[1].let { num -> if (num is Int) num.toLong() else num as Long? } val aNullableStringArg = args[2] as String? api.callFlutterSendMultipleNullableTypesWithoutRecursion( aNullableBoolArg, aNullableIntArg, aNullableStringArg) { @@ -2234,7 +2239,7 @@ interface HostIntegrationCoreApi { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List - val anIntArg = args[0].let { if (it is Int) it.toLong() else it as Long } + val anIntArg = args[0].let { num -> if (num is Int) num.toLong() else num as Long } api.callFlutterEchoInt(anIntArg) { result: Result -> val error = result.exceptionOrNull() if (error != null) { @@ -2306,8 +2311,8 @@ interface HostIntegrationCoreApi { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List - val aListArg = args[0] as ByteArray - api.callFlutterEchoUint8List(aListArg) { result: Result -> + val listArg = args[0] as ByteArray + api.callFlutterEchoUint8List(listArg) { result: Result -> val error = result.exceptionOrNull() if (error != null) { reply.reply(wrapError(error)) @@ -2330,8 +2335,8 @@ interface HostIntegrationCoreApi { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List - val aListArg = args[0] as List - api.callFlutterEchoList(aListArg) { result: Result> -> + val listArg = args[0] as List + api.callFlutterEchoList(listArg) { result: Result> -> val error = result.exceptionOrNull() if (error != null) { reply.reply(wrapError(error)) @@ -2426,7 +2431,7 @@ interface HostIntegrationCoreApi { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List - val anIntArg = args[0].let { if (it is Int) it.toLong() else it as Long? } + val anIntArg = args[0].let { num -> if (num is Int) num.toLong() else num as Long? } api.callFlutterEchoNullableInt(anIntArg) { result: Result -> val error = result.exceptionOrNull() if (error != null) { @@ -2498,8 +2503,8 @@ interface HostIntegrationCoreApi { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List - val aListArg = args[0] as ByteArray? - api.callFlutterEchoNullableUint8List(aListArg) { result: Result -> + val listArg = args[0] as ByteArray? + api.callFlutterEchoNullableUint8List(listArg) { result: Result -> val error = result.exceptionOrNull() if (error != null) { reply.reply(wrapError(error)) @@ -2522,8 +2527,8 @@ interface HostIntegrationCoreApi { if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List - val aListArg = args[0] as List? - api.callFlutterEchoNullableList(aListArg) { result: Result?> -> + val listArg = args[0] as List? + api.callFlutterEchoNullableList(listArg) { result: Result?> -> val error = result.exceptionOrNull() if (error != null) { reply.reply(wrapError(error)) @@ -2613,7 +2618,6 @@ interface HostIntegrationCoreApi { } } -@Suppress("UNCHECKED_CAST") private object FlutterIntegrationCoreApiCodec : StandardMessageCodec() { override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { return when (type) { @@ -2671,7 +2675,6 @@ private object FlutterIntegrationCoreApiCodec : StandardMessageCodec() { * * Generated class from Pigeon that represents Flutter messages that can be called from Kotlin. */ -@Suppress("UNCHECKED_CAST") class FlutterIntegrationCoreApi( private val binaryMessenger: BinaryMessenger, private val messageChannelSuffix: String = "" @@ -2929,7 +2932,7 @@ class FlutterIntegrationCoreApi( "Flutter api returned null value for non-null return value.", ""))) } else { - val output = it[0].let { if (it is Int) it.toLong() else it as Long } + val output = it[0].let { num -> if (num is Int) num.toLong() else num as Long } callback(Result.success(output)) } } else { @@ -2992,13 +2995,13 @@ class FlutterIntegrationCoreApi( } } /** Returns the passed byte list, to test serialization and deserialization. */ - fun echoUint8List(aListArg: ByteArray, callback: (Result) -> Unit) { + fun echoUint8List(listArg: ByteArray, callback: (Result) -> Unit) { val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoUint8List$separatedMessageChannelSuffix" val channel = BasicMessageChannel(binaryMessenger, channelName, codec) - channel.send(listOf(aListArg)) { + channel.send(listOf(listArg)) { if (it is List<*>) { if (it.size > 1) { callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) @@ -3019,13 +3022,13 @@ class FlutterIntegrationCoreApi( } } /** Returns the passed list, to test serialization and deserialization. */ - fun echoList(aListArg: List, callback: (Result>) -> Unit) { + fun echoList(listArg: List, callback: (Result>) -> Unit) { val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoList$separatedMessageChannelSuffix" val channel = BasicMessageChannel(binaryMessenger, channelName, codec) - channel.send(listOf(aListArg)) { + channel.send(listOf(listArg)) { if (it is List<*>) { if (it.size > 1) { callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) @@ -3131,7 +3134,7 @@ class FlutterIntegrationCoreApi( if (it.size > 1) { callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) } else { - val output = it[0].let { if (it is Int) it.toLong() else it as Long? } + val output = it[0].let { num -> if (num is Int) num.toLong() else num as Long? } callback(Result.success(output)) } } else { @@ -3180,13 +3183,13 @@ class FlutterIntegrationCoreApi( } } /** Returns the passed byte list, to test serialization and deserialization. */ - fun echoNullableUint8List(aListArg: ByteArray?, callback: (Result) -> Unit) { + fun echoNullableUint8List(listArg: ByteArray?, callback: (Result) -> Unit) { val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableUint8List$separatedMessageChannelSuffix" val channel = BasicMessageChannel(binaryMessenger, channelName, codec) - channel.send(listOf(aListArg)) { + channel.send(listOf(listArg)) { if (it is List<*>) { if (it.size > 1) { callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) @@ -3200,13 +3203,13 @@ class FlutterIntegrationCoreApi( } } /** Returns the passed list, to test serialization and deserialization. */ - fun echoNullableList(aListArg: List?, callback: (Result?>) -> Unit) { + fun echoNullableList(listArg: List?, callback: (Result?>) -> Unit) { val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableList$separatedMessageChannelSuffix" val channel = BasicMessageChannel(binaryMessenger, channelName, codec) - channel.send(listOf(aListArg)) { + channel.send(listOf(listArg)) { if (it is List<*>) { if (it.size > 1) { callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) @@ -3254,7 +3257,7 @@ class FlutterIntegrationCoreApi( if (it.size > 1) { callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) } else { - val output = (it[0] as Int?)?.let { AnEnum.ofRaw(it) } + val output = (it[0] as Int?)?.let { num -> AnEnum.ofRaw(num) } callback(Result.success(output)) } } else { @@ -3324,7 +3327,6 @@ interface HostTrivialApi { /** The codec used by HostTrivialApi. */ val codec: MessageCodec by lazy { StandardMessageCodec() } /** Sets up an instance of `HostTrivialApi` to handle messages through the `binaryMessenger`. */ - @Suppress("UNCHECKED_CAST") fun setUp( binaryMessenger: BinaryMessenger, api: HostTrivialApi?, @@ -3340,13 +3342,13 @@ interface HostTrivialApi { codec) if (api != null) { channel.setMessageHandler { _, reply -> - var wrapped: List - try { - api.noop() - wrapped = listOf(null) - } catch (exception: Throwable) { - wrapped = wrapError(exception) - } + val wrapped: List = + try { + api.noop() + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } reply.reply(wrapped) } } else { @@ -3370,7 +3372,6 @@ interface HostSmallApi { /** The codec used by HostSmallApi. */ val codec: MessageCodec by lazy { StandardMessageCodec() } /** Sets up an instance of `HostSmallApi` to handle messages through the `binaryMessenger`. */ - @Suppress("UNCHECKED_CAST") fun setUp( binaryMessenger: BinaryMessenger, api: HostSmallApi?, @@ -3427,7 +3428,6 @@ interface HostSmallApi { } } -@Suppress("UNCHECKED_CAST") private object FlutterSmallApiCodec : StandardMessageCodec() { override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { return when (type) { @@ -3454,7 +3454,6 @@ private object FlutterSmallApiCodec : StandardMessageCodec() { * * Generated class from Pigeon that represents Flutter messages that can be called from Kotlin. */ -@Suppress("UNCHECKED_CAST") class FlutterSmallApi( private val binaryMessenger: BinaryMessenger, private val messageChannelSuffix: String = "" diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/TestPlugin.kt b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/TestPlugin.kt index 8453a1cae2c..97236e316bb 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/TestPlugin.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/TestPlugin.kt @@ -80,8 +80,8 @@ class TestPlugin : FlutterPlugin, HostIntegrationCoreApi { return anObject } - override fun echoList(aList: List): List { - return aList + override fun echoList(list: List): List { + return list } override fun echoMap(aMap: Map): Map { @@ -240,8 +240,8 @@ class TestPlugin : FlutterPlugin, HostIntegrationCoreApi { callback(Result.success(anObject)) } - override fun echoAsyncList(aList: List, callback: (Result>) -> Unit) { - callback(Result.success(aList)) + override fun echoAsyncList(list: List, callback: (Result>) -> Unit) { + callback(Result.success(list)) } override fun echoAsyncMap( @@ -282,8 +282,8 @@ class TestPlugin : FlutterPlugin, HostIntegrationCoreApi { callback(Result.success(anObject)) } - override fun echoAsyncNullableList(aList: List?, callback: (Result?>) -> Unit) { - callback(Result.success(aList)) + override fun echoAsyncNullableList(list: List?, callback: (Result?>) -> Unit) { + callback(Result.success(list)) } override fun echoAsyncNullableMap( @@ -359,12 +359,12 @@ class TestPlugin : FlutterPlugin, HostIntegrationCoreApi { flutterApi!!.echoString(aString) { echo -> callback(echo) } } - override fun callFlutterEchoUint8List(aList: ByteArray, callback: (Result) -> Unit) { - flutterApi!!.echoUint8List(aList) { echo -> callback(echo) } + override fun callFlutterEchoUint8List(list: ByteArray, callback: (Result) -> Unit) { + flutterApi!!.echoUint8List(list) { echo -> callback(echo) } } - override fun callFlutterEchoList(aList: List, callback: (Result>) -> Unit) { - flutterApi!!.echoList(aList) { echo -> callback(echo) } + override fun callFlutterEchoList(list: List, callback: (Result>) -> Unit) { + flutterApi!!.echoList(list) { echo -> callback(echo) } } override fun callFlutterEchoMap( @@ -408,17 +408,17 @@ class TestPlugin : FlutterPlugin, HostIntegrationCoreApi { } override fun callFlutterEchoNullableUint8List( - aList: ByteArray?, + list: ByteArray?, callback: (Result) -> Unit ) { - flutterApi!!.echoNullableUint8List(aList) { echo -> callback(echo) } + flutterApi!!.echoNullableUint8List(list) { echo -> callback(echo) } } override fun callFlutterEchoNullableList( - aList: List?, + list: List?, callback: (Result?>) -> Unit ) { - flutterApi!!.echoNullableList(aList) { echo -> callback(echo) } + flutterApi!!.echoNullableList(list) { echo -> callback(echo) } } override fun callFlutterEchoNullableMap( diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AllDatatypesTest.kt b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AllDatatypesTest.kt index 81207b03f58..2560efb65b2 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AllDatatypesTest.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AllDatatypesTest.kt @@ -27,7 +27,7 @@ internal class AllDatatypesTest : TestCase() { assertTrue(firstTypes.a4ByteArray.contentEquals(secondTypes.a4ByteArray)) assertTrue(firstTypes.a8ByteArray.contentEquals(secondTypes.a8ByteArray)) assertTrue(firstTypes.aFloatArray.contentEquals(secondTypes.aFloatArray)) - assertEquals(firstTypes.aList, secondTypes.aList) + assertEquals(firstTypes.list, secondTypes.list) assertEquals(firstTypes.aMap, secondTypes.aMap) assertEquals(firstTypes.anEnum, secondTypes.anEnum) assertEquals(firstTypes.anObject, secondTypes.anObject) 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 f02daf70167..717985e7a4b 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 @@ -69,26 +69,29 @@ struct AllTypes { var a4ByteArray: FlutterStandardTypedData var a8ByteArray: FlutterStandardTypedData var aFloatArray: FlutterStandardTypedData - var aList: [Any?] + var list: [Any?] var aMap: [AnyHashable: Any?] var anEnum: AnEnum var aString: String var anObject: Any - static func fromList(_ list: [Any?]) -> AllTypes? { - let aBool = list[0] as! Bool - let anInt = list[1] is Int64 ? list[1] as! Int64 : Int64(list[1] as! Int32) - let anInt64 = list[2] is Int64 ? list[2] as! Int64 : Int64(list[2] as! Int32) - let aDouble = list[3] as! Double - let aByteArray = list[4] as! FlutterStandardTypedData - let a4ByteArray = list[5] as! FlutterStandardTypedData - let a8ByteArray = list[6] as! FlutterStandardTypedData - let aFloatArray = list[7] as! FlutterStandardTypedData - let aList = list[8] as! [Any?] - let aMap = list[9] as! [AnyHashable: Any?] - let anEnum = AnEnum(rawValue: list[10] as! Int)! - let aString = list[11] as! String - let anObject = list[12]! + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ __pigeon_list: [Any?]) -> AllTypes? { + let aBool = __pigeon_list[0] as! Bool + let anInt = + __pigeon_list[1] is Int64 ? __pigeon_list[1] as! Int64 : Int64(__pigeon_list[1] as! Int32) + let anInt64 = + __pigeon_list[2] is Int64 ? __pigeon_list[2] as! Int64 : Int64(__pigeon_list[2] as! Int32) + let aDouble = __pigeon_list[3] as! Double + let aByteArray = __pigeon_list[4] as! FlutterStandardTypedData + let a4ByteArray = __pigeon_list[5] as! FlutterStandardTypedData + let a8ByteArray = __pigeon_list[6] as! FlutterStandardTypedData + let aFloatArray = __pigeon_list[7] as! FlutterStandardTypedData + let list = __pigeon_list[8] as! [Any?] + let aMap = __pigeon_list[9] as! [AnyHashable: Any?] + let anEnum = AnEnum(rawValue: __pigeon_list[10] as! Int)! + let aString = __pigeon_list[11] as! String + let anObject = __pigeon_list[12]! return AllTypes( aBool: aBool, @@ -99,7 +102,7 @@ struct AllTypes { a4ByteArray: a4ByteArray, a8ByteArray: a8ByteArray, aFloatArray: aFloatArray, - aList: aList, + list: list, aMap: aMap, anEnum: anEnum, aString: aString, @@ -116,7 +119,7 @@ struct AllTypes { a4ByteArray, a8ByteArray, aFloatArray, - aList, + list, aMap, anEnum.rawValue, aString, @@ -184,33 +187,37 @@ class AllNullableTypes { var aNullableObject: Any? var allNullableTypes: AllNullableTypes? - static func fromList(_ list: [Any?]) -> AllNullableTypes? { - let aNullableBool: Bool? = nilOrValue(list[0]) + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ __pigeon_list: [Any?]) -> AllNullableTypes? { + let aNullableBool: Bool? = nilOrValue(__pigeon_list[0]) let aNullableInt: Int64? = - isNullish(list[1]) ? nil : (list[1] is Int64? ? list[1] as! Int64? : Int64(list[1] as! Int32)) + isNullish(__pigeon_list[1]) + ? nil + : (__pigeon_list[1] is Int64? + ? __pigeon_list[1] as! Int64? : Int64(__pigeon_list[1] as! Int32)) let aNullableInt64: Int64? = - isNullish(list[2]) ? nil : (list[2] is Int64? ? list[2] as! Int64? : Int64(list[2] as! Int32)) - let aNullableDouble: Double? = nilOrValue(list[3]) - let aNullableByteArray: FlutterStandardTypedData? = nilOrValue(list[4]) - let aNullable4ByteArray: FlutterStandardTypedData? = nilOrValue(list[5]) - let aNullable8ByteArray: FlutterStandardTypedData? = nilOrValue(list[6]) - let aNullableFloatArray: FlutterStandardTypedData? = nilOrValue(list[7]) - let aNullableList: [Any?]? = nilOrValue(list[8]) - let aNullableMap: [AnyHashable: Any?]? = nilOrValue(list[9]) - let nullableNestedList: [[Bool?]?]? = nilOrValue(list[10]) - let nullableMapWithAnnotations: [String?: String?]? = nilOrValue(list[11]) - let nullableMapWithObject: [String?: Any?]? = nilOrValue(list[12]) + isNullish(__pigeon_list[2]) + ? nil + : (__pigeon_list[2] is Int64? + ? __pigeon_list[2] as! Int64? : Int64(__pigeon_list[2] as! Int32)) + let aNullableDouble: Double? = nilOrValue(__pigeon_list[3]) + let aNullableByteArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[4]) + let aNullable4ByteArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[5]) + let aNullable8ByteArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[6]) + let aNullableFloatArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[7]) + let aNullableList: [Any?]? = nilOrValue(__pigeon_list[8]) + let aNullableMap: [AnyHashable: Any?]? = nilOrValue(__pigeon_list[9]) + let nullableNestedList: [[Bool?]?]? = nilOrValue(__pigeon_list[10]) + let nullableMapWithAnnotations: [String?: String?]? = nilOrValue(__pigeon_list[11]) + let nullableMapWithObject: [String?: Any?]? = nilOrValue(__pigeon_list[12]) var aNullableEnum: AnEnum? = nil - let aNullableEnumEnumVal: Int? = nilOrValue(list[13]) + let aNullableEnumEnumVal: Int? = nilOrValue(__pigeon_list[13]) if let aNullableEnumRawValue = aNullableEnumEnumVal { aNullableEnum = AnEnum(rawValue: aNullableEnumRawValue)! } - let aNullableString: String? = nilOrValue(list[14]) - let aNullableObject: Any? = list[15] - var allNullableTypes: AllNullableTypes? = nil - if let allNullableTypesList: [Any?] = nilOrValue(list[16]) { - allNullableTypes = AllNullableTypes.fromList(allNullableTypesList) - } + let aNullableString: String? = nilOrValue(__pigeon_list[14]) + let aNullableObject: Any? = __pigeon_list[15] + let allNullableTypes: AllNullableTypes? = nilOrValue(__pigeon_list[16]) return AllNullableTypes( aNullableBool: aNullableBool, @@ -250,7 +257,7 @@ class AllNullableTypes { aNullableEnum?.rawValue, aNullableString, aNullableObject, - allNullableTypes?.toList(), + allNullableTypes, ] } } @@ -278,29 +285,36 @@ struct AllNullableTypesWithoutRecursion { var aNullableString: String? = nil var aNullableObject: Any? = nil - static func fromList(_ list: [Any?]) -> AllNullableTypesWithoutRecursion? { - let aNullableBool: Bool? = nilOrValue(list[0]) + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ __pigeon_list: [Any?]) -> AllNullableTypesWithoutRecursion? { + let aNullableBool: Bool? = nilOrValue(__pigeon_list[0]) let aNullableInt: Int64? = - isNullish(list[1]) ? nil : (list[1] is Int64? ? list[1] as! Int64? : Int64(list[1] as! Int32)) + isNullish(__pigeon_list[1]) + ? nil + : (__pigeon_list[1] is Int64? + ? __pigeon_list[1] as! Int64? : Int64(__pigeon_list[1] as! Int32)) let aNullableInt64: Int64? = - isNullish(list[2]) ? nil : (list[2] is Int64? ? list[2] as! Int64? : Int64(list[2] as! Int32)) - let aNullableDouble: Double? = nilOrValue(list[3]) - let aNullableByteArray: FlutterStandardTypedData? = nilOrValue(list[4]) - let aNullable4ByteArray: FlutterStandardTypedData? = nilOrValue(list[5]) - let aNullable8ByteArray: FlutterStandardTypedData? = nilOrValue(list[6]) - let aNullableFloatArray: FlutterStandardTypedData? = nilOrValue(list[7]) - let aNullableList: [Any?]? = nilOrValue(list[8]) - let aNullableMap: [AnyHashable: Any?]? = nilOrValue(list[9]) - let nullableNestedList: [[Bool?]?]? = nilOrValue(list[10]) - let nullableMapWithAnnotations: [String?: String?]? = nilOrValue(list[11]) - let nullableMapWithObject: [String?: Any?]? = nilOrValue(list[12]) + isNullish(__pigeon_list[2]) + ? nil + : (__pigeon_list[2] is Int64? + ? __pigeon_list[2] as! Int64? : Int64(__pigeon_list[2] as! Int32)) + let aNullableDouble: Double? = nilOrValue(__pigeon_list[3]) + let aNullableByteArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[4]) + let aNullable4ByteArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[5]) + let aNullable8ByteArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[6]) + let aNullableFloatArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[7]) + let aNullableList: [Any?]? = nilOrValue(__pigeon_list[8]) + let aNullableMap: [AnyHashable: Any?]? = nilOrValue(__pigeon_list[9]) + let nullableNestedList: [[Bool?]?]? = nilOrValue(__pigeon_list[10]) + let nullableMapWithAnnotations: [String?: String?]? = nilOrValue(__pigeon_list[11]) + let nullableMapWithObject: [String?: Any?]? = nilOrValue(__pigeon_list[12]) var aNullableEnum: AnEnum? = nil - let aNullableEnumEnumVal: Int? = nilOrValue(list[13]) + let aNullableEnumEnumVal: Int? = nilOrValue(__pigeon_list[13]) if let aNullableEnumRawValue = aNullableEnumEnumVal { aNullableEnum = AnEnum(rawValue: aNullableEnumRawValue)! } - let aNullableString: String? = nilOrValue(list[14]) - let aNullableObject: Any? = list[15] + let aNullableString: String? = nilOrValue(__pigeon_list[14]) + let aNullableObject: Any? = __pigeon_list[15] return AllNullableTypesWithoutRecursion( aNullableBool: aNullableBool, @@ -355,17 +369,12 @@ struct AllClassesWrapper { var allNullableTypesWithoutRecursion: AllNullableTypesWithoutRecursion? = nil var allTypes: AllTypes? = nil - static func fromList(_ list: [Any?]) -> AllClassesWrapper? { - let allNullableTypes = AllNullableTypes.fromList(list[0] as! [Any?])! - var allNullableTypesWithoutRecursion: AllNullableTypesWithoutRecursion? = nil - if let allNullableTypesWithoutRecursionList: [Any?] = nilOrValue(list[1]) { - allNullableTypesWithoutRecursion = AllNullableTypesWithoutRecursion.fromList( - allNullableTypesWithoutRecursionList) - } - var allTypes: AllTypes? = nil - if let allTypesList: [Any?] = nilOrValue(list[2]) { - allTypes = AllTypes.fromList(allTypesList) - } + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ __pigeon_list: [Any?]) -> AllClassesWrapper? { + let allNullableTypes = __pigeon_list[0] as! AllNullableTypes + let allNullableTypesWithoutRecursion: AllNullableTypesWithoutRecursion? = nilOrValue( + __pigeon_list[1]) + let allTypes: AllTypes? = nilOrValue(__pigeon_list[2]) return AllClassesWrapper( allNullableTypes: allNullableTypes, @@ -375,9 +384,9 @@ struct AllClassesWrapper { } func toList() -> [Any?] { return [ - allNullableTypes.toList(), - allNullableTypesWithoutRecursion?.toList(), - allTypes?.toList(), + allNullableTypes, + allNullableTypesWithoutRecursion, + allTypes, ] } } @@ -388,8 +397,9 @@ struct AllClassesWrapper { struct TestMessage { var testList: [Any?]? = nil - static func fromList(_ list: [Any?]) -> TestMessage? { - let testList: [Any?]? = nilOrValue(list[0]) + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ __pigeon_list: [Any?]) -> TestMessage? { + let testList: [Any?]? = nilOrValue(__pigeon_list[0]) return TestMessage( testList: testList @@ -488,7 +498,7 @@ protocol HostIntegrationCoreApi { /// Returns the passed in generic Object. func echo(_ anObject: Any) throws -> Any /// Returns the passed list, to test serialization and deserialization. - func echo(_ aList: [Any?]) throws -> [Any?] + func echo(_ list: [Any?]) throws -> [Any?] /// Returns the passed map, to test serialization and deserialization. func echo(_ aMap: [String?: Any?]) throws -> [String?: Any?] /// Returns the passed map to test nested class serialization and deserialization. @@ -559,7 +569,7 @@ protocol HostIntegrationCoreApi { /// Returns the passed in generic Object asynchronously. func echoAsync(_ anObject: Any, completion: @escaping (Result) -> Void) /// Returns the passed list, to test asynchronous serialization and deserialization. - func echoAsync(_ aList: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) + func echoAsync(_ list: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) /// Returns the passed map, to test asynchronous serialization and deserialization. func echoAsync( _ aMap: [String?: Any?], completion: @escaping (Result<[String?: Any?], Error>) -> Void) @@ -596,7 +606,7 @@ protocol HostIntegrationCoreApi { /// Returns the passed in generic Object asynchronously. func echoAsyncNullable(_ anObject: Any?, completion: @escaping (Result) -> Void) /// Returns the passed list, to test asynchronous serialization and deserialization. - func echoAsyncNullable(_ aList: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) + func echoAsyncNullable(_ list: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) /// Returns the passed map, to test asynchronous serialization and deserialization. func echoAsyncNullable( _ aMap: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, Error>) -> Void) @@ -624,9 +634,9 @@ protocol HostIntegrationCoreApi { func callFlutterEcho(_ aDouble: Double, completion: @escaping (Result) -> Void) func callFlutterEcho(_ aString: String, completion: @escaping (Result) -> Void) func callFlutterEcho( - _ aList: FlutterStandardTypedData, + _ list: FlutterStandardTypedData, completion: @escaping (Result) -> Void) - func callFlutterEcho(_ aList: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) + func callFlutterEcho(_ list: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) func callFlutterEcho( _ aMap: [String?: Any?], completion: @escaping (Result<[String?: Any?], Error>) -> Void) func callFlutterEcho(_ anEnum: AnEnum, completion: @escaping (Result) -> Void) @@ -638,10 +648,10 @@ protocol HostIntegrationCoreApi { func callFlutterEchoNullable( _ aString: String?, completion: @escaping (Result) -> Void) func callFlutterEchoNullable( - _ aList: FlutterStandardTypedData?, + _ list: FlutterStandardTypedData?, completion: @escaping (Result) -> Void) func callFlutterEchoNullable( - _ aList: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) + _ list: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) func callFlutterEchoNullable( _ aMap: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, Error>) -> Void) func callFlutterNullableEcho( @@ -870,9 +880,9 @@ class HostIntegrationCoreApiSetup { if let api = api { echoListChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let aListArg = args[0] as! [Any?] + let listArg = args[0] as! [Any?] do { - let result = try api.echo(aListArg) + let result = try api.echo(listArg) reply(wrapResult(result)) } catch { reply(wrapError(error)) @@ -1487,8 +1497,8 @@ class HostIntegrationCoreApiSetup { if let api = api { echoAsyncListChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let aListArg = args[0] as! [Any?] - api.echoAsync(aListArg) { result in + let listArg = args[0] as! [Any?] + api.echoAsync(listArg) { result in switch result { case .success(let res): reply(wrapResult(res)) @@ -1798,8 +1808,8 @@ class HostIntegrationCoreApiSetup { if let api = api { echoAsyncNullableListChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let aListArg: [Any?]? = nilOrValue(args[0]) - api.echoAsyncNullable(aListArg) { result in + let listArg: [Any?]? = nilOrValue(args[0]) + api.echoAsyncNullable(listArg) { result in switch result { case .success(let res): reply(wrapResult(res)) @@ -2107,8 +2117,8 @@ class HostIntegrationCoreApiSetup { if let api = api { callFlutterEchoUint8ListChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let aListArg = args[0] as! FlutterStandardTypedData - api.callFlutterEcho(aListArg) { result in + let listArg = args[0] as! FlutterStandardTypedData + api.callFlutterEcho(listArg) { result in switch result { case .success(let res): reply(wrapResult(res)) @@ -2127,8 +2137,8 @@ class HostIntegrationCoreApiSetup { if let api = api { callFlutterEchoListChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let aListArg = args[0] as! [Any?] - api.callFlutterEcho(aListArg) { result in + let listArg = args[0] as! [Any?] + api.callFlutterEcho(listArg) { result in switch result { case .success(let res): reply(wrapResult(res)) @@ -2269,8 +2279,8 @@ class HostIntegrationCoreApiSetup { if let api = api { callFlutterEchoNullableUint8ListChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let aListArg: FlutterStandardTypedData? = nilOrValue(args[0]) - api.callFlutterEchoNullable(aListArg) { result in + let listArg: FlutterStandardTypedData? = nilOrValue(args[0]) + api.callFlutterEchoNullable(listArg) { result in switch result { case .success(let res): reply(wrapResult(res)) @@ -2289,8 +2299,8 @@ class HostIntegrationCoreApiSetup { if let api = api { callFlutterEchoNullableListChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let aListArg: [Any?]? = nilOrValue(args[0]) - api.callFlutterEchoNullable(aListArg) { result in + let listArg: [Any?]? = nilOrValue(args[0]) + api.callFlutterEchoNullable(listArg) { result in switch result { case .success(let res): reply(wrapResult(res)) @@ -2468,10 +2478,10 @@ protocol FlutterIntegrationCoreApiProtocol { func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) /// Returns the passed byte list, to test serialization and deserialization. func echo( - _ aListArg: FlutterStandardTypedData, + _ listArg: 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(_ listArg: [Any?], completion: @escaping (Result<[Any?], FlutterError>) -> Void) /// Returns the passed map, to test serialization and deserialization. func echo( _ aMapArg: [String?: Any?], @@ -2491,11 +2501,11 @@ protocol FlutterIntegrationCoreApiProtocol { _ aStringArg: String?, completion: @escaping (Result) -> Void) /// Returns the passed byte list, to test serialization and deserialization. func echoNullable( - _ aListArg: FlutterStandardTypedData?, + _ listArg: FlutterStandardTypedData?, completion: @escaping (Result) -> Void) /// Returns the passed list, to test serialization and deserialization. func echoNullable( - _ aListArg: [Any?]?, completion: @escaping (Result<[Any?]?, FlutterError>) -> Void) + _ listArg: [Any?]?, completion: @escaping (Result<[Any?]?, FlutterError>) -> Void) /// Returns the passed map, to test serialization and deserialization. func echoNullable( _ aMapArg: [String?: Any?]?, @@ -2849,14 +2859,14 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } /// Returns the passed byte list, to test serialization and deserialization. func echo( - _ aListArg: FlutterStandardTypedData, + _ listArg: FlutterStandardTypedData, completion: @escaping (Result) -> Void ) { let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoUint8List\(messageChannelSuffix)" let channel = FlutterBasicMessageChannel( name: channelName, binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage([aListArg] as [Any?]) { response in + channel.sendMessage([listArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { completion(.failure(createConnectionError(withChannelName: channelName))) return @@ -2879,12 +2889,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed list, to test serialization and deserialization. - func echo(_ aListArg: [Any?], completion: @escaping (Result<[Any?], FlutterError>) -> Void) { + func echo(_ listArg: [Any?], completion: @escaping (Result<[Any?], FlutterError>) -> Void) { let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoList\(messageChannelSuffix)" let channel = FlutterBasicMessageChannel( name: channelName, binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage([aListArg] as [Any?]) { response in + channel.sendMessage([listArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { completion(.failure(createConnectionError(withChannelName: channelName))) return @@ -3066,14 +3076,14 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } /// Returns the passed byte list, to test serialization and deserialization. func echoNullable( - _ aListArg: FlutterStandardTypedData?, + _ listArg: FlutterStandardTypedData?, completion: @escaping (Result) -> Void ) { let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableUint8List\(messageChannelSuffix)" let channel = FlutterBasicMessageChannel( name: channelName, binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage([aListArg] as [Any?]) { response in + channel.sendMessage([listArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { completion(.failure(createConnectionError(withChannelName: channelName))) return @@ -3091,13 +3101,13 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } /// Returns the passed list, to test serialization and deserialization. func echoNullable( - _ aListArg: [Any?]?, completion: @escaping (Result<[Any?]?, FlutterError>) -> Void + _ listArg: [Any?]?, completion: @escaping (Result<[Any?]?, FlutterError>) -> Void ) { let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableList\(messageChannelSuffix)" let channel = FlutterBasicMessageChannel( name: channelName, binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage([aListArg] as [Any?]) { response in + channel.sendMessage([listArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { completion(.failure(createConnectionError(withChannelName: channelName))) return diff --git a/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift b/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift index dd88abb5a2a..a00affe7040 100644 --- a/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift +++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift @@ -85,8 +85,8 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { return anObject } - func echo(_ aList: [Any?]) throws -> [Any?] { - return aList + func echo(_ list: [Any?]) throws -> [Any?] { + return list } func echo(_ aMap: [String?: Any?]) throws -> [String?: Any?] { @@ -242,8 +242,8 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { completion(.success(anObject)) } - func echoAsync(_ aList: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) { - completion(.success(aList)) + func echoAsync(_ list: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) { + completion(.success(list)) } func echoAsync( @@ -285,8 +285,8 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { completion(.success(anObject)) } - func echoAsyncNullable(_ aList: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) { - completion(.success(aList)) + func echoAsyncNullable(_ list: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) { + completion(.success(list)) } func echoAsyncNullable( @@ -457,10 +457,10 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { } func callFlutterEcho( - _ aList: FlutterStandardTypedData, + _ list: FlutterStandardTypedData, completion: @escaping (Result) -> Void ) { - flutterAPI.echo(aList) { response in + flutterAPI.echo(list) { response in switch response { case .success(let res): completion(.success(res)) @@ -470,8 +470,8 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { } } - func callFlutterEcho(_ aList: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) { - flutterAPI.echo(aList) { response in + func callFlutterEcho(_ list: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) { + flutterAPI.echo(list) { response in switch response { case .success(let res): completion(.success(res)) @@ -557,10 +557,10 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { } func callFlutterEchoNullable( - _ aList: FlutterStandardTypedData?, + _ list: FlutterStandardTypedData?, completion: @escaping (Result) -> Void ) { - flutterAPI.echoNullable(aList) { response in + flutterAPI.echoNullable(list) { response in switch response { case .success(let res): completion(.success(res)) @@ -571,9 +571,9 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { } func callFlutterEchoNullable( - _ aList: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void + _ list: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void ) { - flutterAPI.echoNullable(aList) { response in + flutterAPI.echoNullable(list) { response in switch response { case .success(let res): completion(.success(res)) 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 f02daf70167..717985e7a4b 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 @@ -69,26 +69,29 @@ struct AllTypes { var a4ByteArray: FlutterStandardTypedData var a8ByteArray: FlutterStandardTypedData var aFloatArray: FlutterStandardTypedData - var aList: [Any?] + var list: [Any?] var aMap: [AnyHashable: Any?] var anEnum: AnEnum var aString: String var anObject: Any - static func fromList(_ list: [Any?]) -> AllTypes? { - let aBool = list[0] as! Bool - let anInt = list[1] is Int64 ? list[1] as! Int64 : Int64(list[1] as! Int32) - let anInt64 = list[2] is Int64 ? list[2] as! Int64 : Int64(list[2] as! Int32) - let aDouble = list[3] as! Double - let aByteArray = list[4] as! FlutterStandardTypedData - let a4ByteArray = list[5] as! FlutterStandardTypedData - let a8ByteArray = list[6] as! FlutterStandardTypedData - let aFloatArray = list[7] as! FlutterStandardTypedData - let aList = list[8] as! [Any?] - let aMap = list[9] as! [AnyHashable: Any?] - let anEnum = AnEnum(rawValue: list[10] as! Int)! - let aString = list[11] as! String - let anObject = list[12]! + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ __pigeon_list: [Any?]) -> AllTypes? { + let aBool = __pigeon_list[0] as! Bool + let anInt = + __pigeon_list[1] is Int64 ? __pigeon_list[1] as! Int64 : Int64(__pigeon_list[1] as! Int32) + let anInt64 = + __pigeon_list[2] is Int64 ? __pigeon_list[2] as! Int64 : Int64(__pigeon_list[2] as! Int32) + let aDouble = __pigeon_list[3] as! Double + let aByteArray = __pigeon_list[4] as! FlutterStandardTypedData + let a4ByteArray = __pigeon_list[5] as! FlutterStandardTypedData + let a8ByteArray = __pigeon_list[6] as! FlutterStandardTypedData + let aFloatArray = __pigeon_list[7] as! FlutterStandardTypedData + let list = __pigeon_list[8] as! [Any?] + let aMap = __pigeon_list[9] as! [AnyHashable: Any?] + let anEnum = AnEnum(rawValue: __pigeon_list[10] as! Int)! + let aString = __pigeon_list[11] as! String + let anObject = __pigeon_list[12]! return AllTypes( aBool: aBool, @@ -99,7 +102,7 @@ struct AllTypes { a4ByteArray: a4ByteArray, a8ByteArray: a8ByteArray, aFloatArray: aFloatArray, - aList: aList, + list: list, aMap: aMap, anEnum: anEnum, aString: aString, @@ -116,7 +119,7 @@ struct AllTypes { a4ByteArray, a8ByteArray, aFloatArray, - aList, + list, aMap, anEnum.rawValue, aString, @@ -184,33 +187,37 @@ class AllNullableTypes { var aNullableObject: Any? var allNullableTypes: AllNullableTypes? - static func fromList(_ list: [Any?]) -> AllNullableTypes? { - let aNullableBool: Bool? = nilOrValue(list[0]) + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ __pigeon_list: [Any?]) -> AllNullableTypes? { + let aNullableBool: Bool? = nilOrValue(__pigeon_list[0]) let aNullableInt: Int64? = - isNullish(list[1]) ? nil : (list[1] is Int64? ? list[1] as! Int64? : Int64(list[1] as! Int32)) + isNullish(__pigeon_list[1]) + ? nil + : (__pigeon_list[1] is Int64? + ? __pigeon_list[1] as! Int64? : Int64(__pigeon_list[1] as! Int32)) let aNullableInt64: Int64? = - isNullish(list[2]) ? nil : (list[2] is Int64? ? list[2] as! Int64? : Int64(list[2] as! Int32)) - let aNullableDouble: Double? = nilOrValue(list[3]) - let aNullableByteArray: FlutterStandardTypedData? = nilOrValue(list[4]) - let aNullable4ByteArray: FlutterStandardTypedData? = nilOrValue(list[5]) - let aNullable8ByteArray: FlutterStandardTypedData? = nilOrValue(list[6]) - let aNullableFloatArray: FlutterStandardTypedData? = nilOrValue(list[7]) - let aNullableList: [Any?]? = nilOrValue(list[8]) - let aNullableMap: [AnyHashable: Any?]? = nilOrValue(list[9]) - let nullableNestedList: [[Bool?]?]? = nilOrValue(list[10]) - let nullableMapWithAnnotations: [String?: String?]? = nilOrValue(list[11]) - let nullableMapWithObject: [String?: Any?]? = nilOrValue(list[12]) + isNullish(__pigeon_list[2]) + ? nil + : (__pigeon_list[2] is Int64? + ? __pigeon_list[2] as! Int64? : Int64(__pigeon_list[2] as! Int32)) + let aNullableDouble: Double? = nilOrValue(__pigeon_list[3]) + let aNullableByteArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[4]) + let aNullable4ByteArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[5]) + let aNullable8ByteArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[6]) + let aNullableFloatArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[7]) + let aNullableList: [Any?]? = nilOrValue(__pigeon_list[8]) + let aNullableMap: [AnyHashable: Any?]? = nilOrValue(__pigeon_list[9]) + let nullableNestedList: [[Bool?]?]? = nilOrValue(__pigeon_list[10]) + let nullableMapWithAnnotations: [String?: String?]? = nilOrValue(__pigeon_list[11]) + let nullableMapWithObject: [String?: Any?]? = nilOrValue(__pigeon_list[12]) var aNullableEnum: AnEnum? = nil - let aNullableEnumEnumVal: Int? = nilOrValue(list[13]) + let aNullableEnumEnumVal: Int? = nilOrValue(__pigeon_list[13]) if let aNullableEnumRawValue = aNullableEnumEnumVal { aNullableEnum = AnEnum(rawValue: aNullableEnumRawValue)! } - let aNullableString: String? = nilOrValue(list[14]) - let aNullableObject: Any? = list[15] - var allNullableTypes: AllNullableTypes? = nil - if let allNullableTypesList: [Any?] = nilOrValue(list[16]) { - allNullableTypes = AllNullableTypes.fromList(allNullableTypesList) - } + let aNullableString: String? = nilOrValue(__pigeon_list[14]) + let aNullableObject: Any? = __pigeon_list[15] + let allNullableTypes: AllNullableTypes? = nilOrValue(__pigeon_list[16]) return AllNullableTypes( aNullableBool: aNullableBool, @@ -250,7 +257,7 @@ class AllNullableTypes { aNullableEnum?.rawValue, aNullableString, aNullableObject, - allNullableTypes?.toList(), + allNullableTypes, ] } } @@ -278,29 +285,36 @@ struct AllNullableTypesWithoutRecursion { var aNullableString: String? = nil var aNullableObject: Any? = nil - static func fromList(_ list: [Any?]) -> AllNullableTypesWithoutRecursion? { - let aNullableBool: Bool? = nilOrValue(list[0]) + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ __pigeon_list: [Any?]) -> AllNullableTypesWithoutRecursion? { + let aNullableBool: Bool? = nilOrValue(__pigeon_list[0]) let aNullableInt: Int64? = - isNullish(list[1]) ? nil : (list[1] is Int64? ? list[1] as! Int64? : Int64(list[1] as! Int32)) + isNullish(__pigeon_list[1]) + ? nil + : (__pigeon_list[1] is Int64? + ? __pigeon_list[1] as! Int64? : Int64(__pigeon_list[1] as! Int32)) let aNullableInt64: Int64? = - isNullish(list[2]) ? nil : (list[2] is Int64? ? list[2] as! Int64? : Int64(list[2] as! Int32)) - let aNullableDouble: Double? = nilOrValue(list[3]) - let aNullableByteArray: FlutterStandardTypedData? = nilOrValue(list[4]) - let aNullable4ByteArray: FlutterStandardTypedData? = nilOrValue(list[5]) - let aNullable8ByteArray: FlutterStandardTypedData? = nilOrValue(list[6]) - let aNullableFloatArray: FlutterStandardTypedData? = nilOrValue(list[7]) - let aNullableList: [Any?]? = nilOrValue(list[8]) - let aNullableMap: [AnyHashable: Any?]? = nilOrValue(list[9]) - let nullableNestedList: [[Bool?]?]? = nilOrValue(list[10]) - let nullableMapWithAnnotations: [String?: String?]? = nilOrValue(list[11]) - let nullableMapWithObject: [String?: Any?]? = nilOrValue(list[12]) + isNullish(__pigeon_list[2]) + ? nil + : (__pigeon_list[2] is Int64? + ? __pigeon_list[2] as! Int64? : Int64(__pigeon_list[2] as! Int32)) + let aNullableDouble: Double? = nilOrValue(__pigeon_list[3]) + let aNullableByteArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[4]) + let aNullable4ByteArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[5]) + let aNullable8ByteArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[6]) + let aNullableFloatArray: FlutterStandardTypedData? = nilOrValue(__pigeon_list[7]) + let aNullableList: [Any?]? = nilOrValue(__pigeon_list[8]) + let aNullableMap: [AnyHashable: Any?]? = nilOrValue(__pigeon_list[9]) + let nullableNestedList: [[Bool?]?]? = nilOrValue(__pigeon_list[10]) + let nullableMapWithAnnotations: [String?: String?]? = nilOrValue(__pigeon_list[11]) + let nullableMapWithObject: [String?: Any?]? = nilOrValue(__pigeon_list[12]) var aNullableEnum: AnEnum? = nil - let aNullableEnumEnumVal: Int? = nilOrValue(list[13]) + let aNullableEnumEnumVal: Int? = nilOrValue(__pigeon_list[13]) if let aNullableEnumRawValue = aNullableEnumEnumVal { aNullableEnum = AnEnum(rawValue: aNullableEnumRawValue)! } - let aNullableString: String? = nilOrValue(list[14]) - let aNullableObject: Any? = list[15] + let aNullableString: String? = nilOrValue(__pigeon_list[14]) + let aNullableObject: Any? = __pigeon_list[15] return AllNullableTypesWithoutRecursion( aNullableBool: aNullableBool, @@ -355,17 +369,12 @@ struct AllClassesWrapper { var allNullableTypesWithoutRecursion: AllNullableTypesWithoutRecursion? = nil var allTypes: AllTypes? = nil - static func fromList(_ list: [Any?]) -> AllClassesWrapper? { - let allNullableTypes = AllNullableTypes.fromList(list[0] as! [Any?])! - var allNullableTypesWithoutRecursion: AllNullableTypesWithoutRecursion? = nil - if let allNullableTypesWithoutRecursionList: [Any?] = nilOrValue(list[1]) { - allNullableTypesWithoutRecursion = AllNullableTypesWithoutRecursion.fromList( - allNullableTypesWithoutRecursionList) - } - var allTypes: AllTypes? = nil - if let allTypesList: [Any?] = nilOrValue(list[2]) { - allTypes = AllTypes.fromList(allTypesList) - } + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ __pigeon_list: [Any?]) -> AllClassesWrapper? { + let allNullableTypes = __pigeon_list[0] as! AllNullableTypes + let allNullableTypesWithoutRecursion: AllNullableTypesWithoutRecursion? = nilOrValue( + __pigeon_list[1]) + let allTypes: AllTypes? = nilOrValue(__pigeon_list[2]) return AllClassesWrapper( allNullableTypes: allNullableTypes, @@ -375,9 +384,9 @@ struct AllClassesWrapper { } func toList() -> [Any?] { return [ - allNullableTypes.toList(), - allNullableTypesWithoutRecursion?.toList(), - allTypes?.toList(), + allNullableTypes, + allNullableTypesWithoutRecursion, + allTypes, ] } } @@ -388,8 +397,9 @@ struct AllClassesWrapper { struct TestMessage { var testList: [Any?]? = nil - static func fromList(_ list: [Any?]) -> TestMessage? { - let testList: [Any?]? = nilOrValue(list[0]) + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ __pigeon_list: [Any?]) -> TestMessage? { + let testList: [Any?]? = nilOrValue(__pigeon_list[0]) return TestMessage( testList: testList @@ -488,7 +498,7 @@ protocol HostIntegrationCoreApi { /// Returns the passed in generic Object. func echo(_ anObject: Any) throws -> Any /// Returns the passed list, to test serialization and deserialization. - func echo(_ aList: [Any?]) throws -> [Any?] + func echo(_ list: [Any?]) throws -> [Any?] /// Returns the passed map, to test serialization and deserialization. func echo(_ aMap: [String?: Any?]) throws -> [String?: Any?] /// Returns the passed map to test nested class serialization and deserialization. @@ -559,7 +569,7 @@ protocol HostIntegrationCoreApi { /// Returns the passed in generic Object asynchronously. func echoAsync(_ anObject: Any, completion: @escaping (Result) -> Void) /// Returns the passed list, to test asynchronous serialization and deserialization. - func echoAsync(_ aList: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) + func echoAsync(_ list: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) /// Returns the passed map, to test asynchronous serialization and deserialization. func echoAsync( _ aMap: [String?: Any?], completion: @escaping (Result<[String?: Any?], Error>) -> Void) @@ -596,7 +606,7 @@ protocol HostIntegrationCoreApi { /// Returns the passed in generic Object asynchronously. func echoAsyncNullable(_ anObject: Any?, completion: @escaping (Result) -> Void) /// Returns the passed list, to test asynchronous serialization and deserialization. - func echoAsyncNullable(_ aList: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) + func echoAsyncNullable(_ list: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) /// Returns the passed map, to test asynchronous serialization and deserialization. func echoAsyncNullable( _ aMap: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, Error>) -> Void) @@ -624,9 +634,9 @@ protocol HostIntegrationCoreApi { func callFlutterEcho(_ aDouble: Double, completion: @escaping (Result) -> Void) func callFlutterEcho(_ aString: String, completion: @escaping (Result) -> Void) func callFlutterEcho( - _ aList: FlutterStandardTypedData, + _ list: FlutterStandardTypedData, completion: @escaping (Result) -> Void) - func callFlutterEcho(_ aList: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) + func callFlutterEcho(_ list: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) func callFlutterEcho( _ aMap: [String?: Any?], completion: @escaping (Result<[String?: Any?], Error>) -> Void) func callFlutterEcho(_ anEnum: AnEnum, completion: @escaping (Result) -> Void) @@ -638,10 +648,10 @@ protocol HostIntegrationCoreApi { func callFlutterEchoNullable( _ aString: String?, completion: @escaping (Result) -> Void) func callFlutterEchoNullable( - _ aList: FlutterStandardTypedData?, + _ list: FlutterStandardTypedData?, completion: @escaping (Result) -> Void) func callFlutterEchoNullable( - _ aList: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) + _ list: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) func callFlutterEchoNullable( _ aMap: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, Error>) -> Void) func callFlutterNullableEcho( @@ -870,9 +880,9 @@ class HostIntegrationCoreApiSetup { if let api = api { echoListChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let aListArg = args[0] as! [Any?] + let listArg = args[0] as! [Any?] do { - let result = try api.echo(aListArg) + let result = try api.echo(listArg) reply(wrapResult(result)) } catch { reply(wrapError(error)) @@ -1487,8 +1497,8 @@ class HostIntegrationCoreApiSetup { if let api = api { echoAsyncListChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let aListArg = args[0] as! [Any?] - api.echoAsync(aListArg) { result in + let listArg = args[0] as! [Any?] + api.echoAsync(listArg) { result in switch result { case .success(let res): reply(wrapResult(res)) @@ -1798,8 +1808,8 @@ class HostIntegrationCoreApiSetup { if let api = api { echoAsyncNullableListChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let aListArg: [Any?]? = nilOrValue(args[0]) - api.echoAsyncNullable(aListArg) { result in + let listArg: [Any?]? = nilOrValue(args[0]) + api.echoAsyncNullable(listArg) { result in switch result { case .success(let res): reply(wrapResult(res)) @@ -2107,8 +2117,8 @@ class HostIntegrationCoreApiSetup { if let api = api { callFlutterEchoUint8ListChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let aListArg = args[0] as! FlutterStandardTypedData - api.callFlutterEcho(aListArg) { result in + let listArg = args[0] as! FlutterStandardTypedData + api.callFlutterEcho(listArg) { result in switch result { case .success(let res): reply(wrapResult(res)) @@ -2127,8 +2137,8 @@ class HostIntegrationCoreApiSetup { if let api = api { callFlutterEchoListChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let aListArg = args[0] as! [Any?] - api.callFlutterEcho(aListArg) { result in + let listArg = args[0] as! [Any?] + api.callFlutterEcho(listArg) { result in switch result { case .success(let res): reply(wrapResult(res)) @@ -2269,8 +2279,8 @@ class HostIntegrationCoreApiSetup { if let api = api { callFlutterEchoNullableUint8ListChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let aListArg: FlutterStandardTypedData? = nilOrValue(args[0]) - api.callFlutterEchoNullable(aListArg) { result in + let listArg: FlutterStandardTypedData? = nilOrValue(args[0]) + api.callFlutterEchoNullable(listArg) { result in switch result { case .success(let res): reply(wrapResult(res)) @@ -2289,8 +2299,8 @@ class HostIntegrationCoreApiSetup { if let api = api { callFlutterEchoNullableListChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let aListArg: [Any?]? = nilOrValue(args[0]) - api.callFlutterEchoNullable(aListArg) { result in + let listArg: [Any?]? = nilOrValue(args[0]) + api.callFlutterEchoNullable(listArg) { result in switch result { case .success(let res): reply(wrapResult(res)) @@ -2468,10 +2478,10 @@ protocol FlutterIntegrationCoreApiProtocol { func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) /// Returns the passed byte list, to test serialization and deserialization. func echo( - _ aListArg: FlutterStandardTypedData, + _ listArg: 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(_ listArg: [Any?], completion: @escaping (Result<[Any?], FlutterError>) -> Void) /// Returns the passed map, to test serialization and deserialization. func echo( _ aMapArg: [String?: Any?], @@ -2491,11 +2501,11 @@ protocol FlutterIntegrationCoreApiProtocol { _ aStringArg: String?, completion: @escaping (Result) -> Void) /// Returns the passed byte list, to test serialization and deserialization. func echoNullable( - _ aListArg: FlutterStandardTypedData?, + _ listArg: FlutterStandardTypedData?, completion: @escaping (Result) -> Void) /// Returns the passed list, to test serialization and deserialization. func echoNullable( - _ aListArg: [Any?]?, completion: @escaping (Result<[Any?]?, FlutterError>) -> Void) + _ listArg: [Any?]?, completion: @escaping (Result<[Any?]?, FlutterError>) -> Void) /// Returns the passed map, to test serialization and deserialization. func echoNullable( _ aMapArg: [String?: Any?]?, @@ -2849,14 +2859,14 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } /// Returns the passed byte list, to test serialization and deserialization. func echo( - _ aListArg: FlutterStandardTypedData, + _ listArg: FlutterStandardTypedData, completion: @escaping (Result) -> Void ) { let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoUint8List\(messageChannelSuffix)" let channel = FlutterBasicMessageChannel( name: channelName, binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage([aListArg] as [Any?]) { response in + channel.sendMessage([listArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { completion(.failure(createConnectionError(withChannelName: channelName))) return @@ -2879,12 +2889,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed list, to test serialization and deserialization. - func echo(_ aListArg: [Any?], completion: @escaping (Result<[Any?], FlutterError>) -> Void) { + func echo(_ listArg: [Any?], completion: @escaping (Result<[Any?], FlutterError>) -> Void) { let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoList\(messageChannelSuffix)" let channel = FlutterBasicMessageChannel( name: channelName, binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage([aListArg] as [Any?]) { response in + channel.sendMessage([listArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { completion(.failure(createConnectionError(withChannelName: channelName))) return @@ -3066,14 +3076,14 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } /// Returns the passed byte list, to test serialization and deserialization. func echoNullable( - _ aListArg: FlutterStandardTypedData?, + _ listArg: FlutterStandardTypedData?, completion: @escaping (Result) -> Void ) { let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableUint8List\(messageChannelSuffix)" let channel = FlutterBasicMessageChannel( name: channelName, binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage([aListArg] as [Any?]) { response in + channel.sendMessage([listArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { completion(.failure(createConnectionError(withChannelName: channelName))) return @@ -3091,13 +3101,13 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } /// Returns the passed list, to test serialization and deserialization. func echoNullable( - _ aListArg: [Any?]?, completion: @escaping (Result<[Any?]?, FlutterError>) -> Void + _ listArg: [Any?]?, completion: @escaping (Result<[Any?]?, FlutterError>) -> Void ) { let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableList\(messageChannelSuffix)" let channel = FlutterBasicMessageChannel( name: channelName, binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage([aListArg] as [Any?]) { response in + channel.sendMessage([listArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { completion(.failure(createConnectionError(withChannelName: channelName))) return diff --git a/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift b/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift index 759b4ac21ac..2c415135bcc 100644 --- a/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift +++ b/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift @@ -84,8 +84,8 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { return anObject } - func echo(_ aList: [Any?]) throws -> [Any?] { - return aList + func echo(_ list: [Any?]) throws -> [Any?] { + return list } func echo(_ aMap: [String?: Any?]) throws -> [String?: Any?] { @@ -241,8 +241,8 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { completion(.success(anObject)) } - func echoAsync(_ aList: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) { - completion(.success(aList)) + func echoAsync(_ list: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) { + completion(.success(list)) } func echoAsync( @@ -284,8 +284,8 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { completion(.success(anObject)) } - func echoAsyncNullable(_ aList: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) { - completion(.success(aList)) + func echoAsyncNullable(_ list: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) { + completion(.success(list)) } func echoAsyncNullable( @@ -456,10 +456,10 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { } func callFlutterEcho( - _ aList: FlutterStandardTypedData, + _ list: FlutterStandardTypedData, completion: @escaping (Result) -> Void ) { - flutterAPI.echo(aList) { response in + flutterAPI.echo(list) { response in switch response { case .success(let res): completion(.success(res)) @@ -469,8 +469,8 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { } } - func callFlutterEcho(_ aList: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) { - flutterAPI.echo(aList) { response in + func callFlutterEcho(_ list: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) { + flutterAPI.echo(list) { response in switch response { case .success(let res): completion(.success(res)) @@ -556,10 +556,10 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { } func callFlutterEchoNullable( - _ aList: FlutterStandardTypedData?, + _ list: FlutterStandardTypedData?, completion: @escaping (Result) -> Void ) { - flutterAPI.echoNullable(aList) { response in + flutterAPI.echoNullable(list) { response in switch response { case .success(let res): completion(.success(res)) @@ -570,9 +570,9 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { } func callFlutterEchoNullable( - _ aList: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void + _ list: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void ) { - flutterAPI.echoNullable(aList) { response in + flutterAPI.echoNullable(list) { response in switch response { case .success(let res): completion(.success(res)) diff --git a/packages/pigeon/platform_tests/test_plugin/windows/CMakeLists.txt b/packages/pigeon/platform_tests/test_plugin/windows/CMakeLists.txt index 30e26d2bb1b..e69e6bc7513 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/CMakeLists.txt +++ b/packages/pigeon/platform_tests/test_plugin/windows/CMakeLists.txt @@ -62,6 +62,10 @@ target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL) target_include_directories(${PLUGIN_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include") target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin) +# Override apply_standard_settings for exceptions due to +# https://developercommunity.visualstudio.com/t/stdany-doesnt-link-when-exceptions-are-disabled/376072 +# TODO(stuartmorgan): Remove this once CI is using VS 2022 or later. +target_compile_definitions(${PLUGIN_NAME} PRIVATE "_HAS_EXCEPTIONS=1") # List of absolute paths to libraries that should be bundled with the plugin. # This list could contain prebuilt libraries, or libraries created by an @@ -118,6 +122,10 @@ add_custom_command(TARGET ${TEST_RUNNER} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${FLUTTER_LIBRARY}" $ ) +# Override apply_standard_settings for exceptions due to +# https://developercommunity.visualstudio.com/t/stdany-doesnt-link-when-exceptions-are-disabled/376072 +# TODO(stuartmorgan): Remove this once CI is using VS 2022 or later. +target_compile_definitions(${TEST_RUNNER} PRIVATE "_HAS_EXCEPTIONS=1") include(GoogleTest) gtest_discover_tests(${TEST_RUNNER}) diff --git a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp index a1cff580e06..c4e74f45119 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp +++ b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp @@ -39,7 +39,7 @@ AllTypes::AllTypes(bool a_bool, int64_t an_int, int64_t an_int64, const std::vector& a4_byte_array, const std::vector& a8_byte_array, const std::vector& a_float_array, - const EncodableList& a_list, const EncodableMap& a_map, + const EncodableList& list, const EncodableMap& a_map, const AnEnum& an_enum, const std::string& a_string, const EncodableValue& an_object) : a_bool_(a_bool), @@ -50,7 +50,7 @@ AllTypes::AllTypes(bool a_bool, int64_t an_int, int64_t an_int64, a4_byte_array_(a4_byte_array), a8_byte_array_(a8_byte_array), a_float_array_(a_float_array), - a_list_(a_list), + list_(list), a_map_(a_map), an_enum_(an_enum), a_string_(a_string), @@ -104,11 +104,9 @@ void AllTypes::set_a_float_array(const std::vector& value_arg) { a_float_array_ = value_arg; } -const EncodableList& AllTypes::a_list() const { return a_list_; } +const EncodableList& AllTypes::list() const { return list_; } -void AllTypes::set_a_list(const EncodableList& value_arg) { - a_list_ = value_arg; -} +void AllTypes::set_list(const EncodableList& value_arg) { list_ = value_arg; } const EncodableMap& AllTypes::a_map() const { return a_map_; } @@ -141,7 +139,7 @@ EncodableList AllTypes::ToEncodableList() const { list.push_back(EncodableValue(a4_byte_array_)); list.push_back(EncodableValue(a8_byte_array_)); list.push_back(EncodableValue(a_float_array_)); - list.push_back(EncodableValue(a_list_)); + list.push_back(EncodableValue(list_)); list.push_back(EncodableValue(a_map_)); list.push_back(EncodableValue((int)an_enum_)); list.push_back(EncodableValue(a_string_)); @@ -605,7 +603,7 @@ EncodableList AllNullableTypes::ToEncodableList() const { : EncodableValue()); list.push_back(a_nullable_object_ ? *a_nullable_object_ : EncodableValue()); list.push_back(all_nullable_types_ - ? EncodableValue(all_nullable_types_->ToEncodableList()) + ? CustomEncodableValue(*all_nullable_types_) : EncodableValue()); return list; } @@ -691,8 +689,8 @@ AllNullableTypes AllNullableTypes::FromEncodableList( } auto& encodable_all_nullable_types = list[16]; if (!encodable_all_nullable_types.IsNull()) { - decoded.set_all_nullable_types(AllNullableTypes::FromEncodableList( - std::get(encodable_all_nullable_types))); + decoded.set_all_nullable_types(std::any_cast( + std::get(encodable_all_nullable_types))); } return decoded; } @@ -1226,32 +1224,31 @@ void AllClassesWrapper::set_all_types(const AllTypes& value_arg) { EncodableList AllClassesWrapper::ToEncodableList() const { EncodableList list; list.reserve(3); - list.push_back(EncodableValue(all_nullable_types_->ToEncodableList())); + list.push_back(CustomEncodableValue(*all_nullable_types_)); list.push_back( all_nullable_types_without_recursion_ - ? EncodableValue( - all_nullable_types_without_recursion_->ToEncodableList()) + ? CustomEncodableValue(*all_nullable_types_without_recursion_) : EncodableValue()); - list.push_back(all_types_ ? EncodableValue(all_types_->ToEncodableList()) + list.push_back(all_types_ ? CustomEncodableValue(*all_types_) : EncodableValue()); return list; } AllClassesWrapper AllClassesWrapper::FromEncodableList( const EncodableList& list) { - AllClassesWrapper decoded( - AllNullableTypes::FromEncodableList(std::get(list[0]))); + AllClassesWrapper decoded(std::any_cast( + std::get(list[0]))); auto& encodable_all_nullable_types_without_recursion = list[1]; if (!encodable_all_nullable_types_without_recursion.IsNull()) { decoded.set_all_nullable_types_without_recursion( - AllNullableTypesWithoutRecursion::FromEncodableList( - std::get( + std::any_cast( + std::get( encodable_all_nullable_types_without_recursion))); } auto& encodable_all_types = list[2]; if (!encodable_all_types.IsNull()) { - decoded.set_all_types(AllTypes::FromEncodableList( - std::get(encodable_all_types))); + decoded.set_all_types(std::any_cast( + std::get(encodable_all_types))); } return decoded; } @@ -1763,14 +1760,14 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, const flutter::MessageReply& reply) { try { const auto& args = std::get(message); - const auto& encodable_a_list_arg = args.at(0); - if (encodable_a_list_arg.IsNull()) { - reply(WrapError("a_list_arg unexpectedly null.")); + const auto& encodable_list_arg = args.at(0); + if (encodable_list_arg.IsNull()) { + reply(WrapError("list_arg unexpectedly null.")); return; } - const auto& a_list_arg = - std::get(encodable_a_list_arg); - ErrorOr output = api->EchoList(a_list_arg); + const auto& list_arg = + std::get(encodable_list_arg); + ErrorOr output = api->EchoList(list_arg); if (output.has_error()) { reply(WrapError(output.error())); return; @@ -2961,15 +2958,15 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, const flutter::MessageReply& reply) { try { const auto& args = std::get(message); - const auto& encodable_a_list_arg = args.at(0); - if (encodable_a_list_arg.IsNull()) { - reply(WrapError("a_list_arg unexpectedly null.")); + const auto& encodable_list_arg = args.at(0); + if (encodable_list_arg.IsNull()) { + reply(WrapError("list_arg unexpectedly null.")); return; } - const auto& a_list_arg = - std::get(encodable_a_list_arg); + const auto& list_arg = + std::get(encodable_list_arg); api->EchoAsyncList( - a_list_arg, [reply](ErrorOr&& output) { + list_arg, [reply](ErrorOr&& output) { if (output.has_error()) { reply(WrapError(output.error())); return; @@ -3551,11 +3548,11 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, const flutter::MessageReply& reply) { try { const auto& args = std::get(message); - const auto& encodable_a_list_arg = args.at(0); - const auto* a_list_arg = - std::get_if(&encodable_a_list_arg); + const auto& encodable_list_arg = args.at(0); + const auto* list_arg = + std::get_if(&encodable_list_arg); api->EchoAsyncNullableList( - a_list_arg, + list_arg, [reply](ErrorOr>&& output) { if (output.has_error()) { reply(WrapError(output.error())); @@ -4153,15 +4150,15 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, const flutter::MessageReply& reply) { try { const auto& args = std::get(message); - const auto& encodable_a_list_arg = args.at(0); - if (encodable_a_list_arg.IsNull()) { - reply(WrapError("a_list_arg unexpectedly null.")); + const auto& encodable_list_arg = args.at(0); + if (encodable_list_arg.IsNull()) { + reply(WrapError("list_arg unexpectedly null.")); return; } - const auto& a_list_arg = - std::get>(encodable_a_list_arg); + const auto& list_arg = + std::get>(encodable_list_arg); api->CallFlutterEchoUint8List( - a_list_arg, [reply](ErrorOr>&& output) { + list_arg, [reply](ErrorOr>&& output) { if (output.has_error()) { reply(WrapError(output.error())); return; @@ -4191,15 +4188,15 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, const flutter::MessageReply& reply) { try { const auto& args = std::get(message); - const auto& encodable_a_list_arg = args.at(0); - if (encodable_a_list_arg.IsNull()) { - reply(WrapError("a_list_arg unexpectedly null.")); + const auto& encodable_list_arg = args.at(0); + if (encodable_list_arg.IsNull()) { + reply(WrapError("list_arg unexpectedly null.")); return; } - const auto& a_list_arg = - std::get(encodable_a_list_arg); + const auto& list_arg = + std::get(encodable_list_arg); api->CallFlutterEchoList( - a_list_arg, [reply](ErrorOr&& output) { + list_arg, [reply](ErrorOr&& output) { if (output.has_error()) { reply(WrapError(output.error())); return; @@ -4472,11 +4469,11 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, const flutter::MessageReply& reply) { try { const auto& args = std::get(message); - const auto& encodable_a_list_arg = args.at(0); - const auto* a_list_arg = - std::get_if>(&encodable_a_list_arg); + const auto& encodable_list_arg = args.at(0); + const auto* list_arg = + std::get_if>(&encodable_list_arg); api->CallFlutterEchoNullableUint8List( - a_list_arg, + list_arg, [reply]( ErrorOr>>&& output) { if (output.has_error()) { @@ -4514,11 +4511,11 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, const flutter::MessageReply& reply) { try { const auto& args = std::get(message); - const auto& encodable_a_list_arg = args.at(0); - const auto* a_list_arg = - std::get_if(&encodable_a_list_arg); + const auto& encodable_list_arg = args.at(0); + const auto* list_arg = + std::get_if(&encodable_list_arg); api->CallFlutterEchoNullableList( - a_list_arg, + list_arg, [reply](ErrorOr>&& output) { if (output.has_error()) { reply(WrapError(output.error())); @@ -5228,7 +5225,7 @@ void FlutterIntegrationCoreApi::EchoString( } void FlutterIntegrationCoreApi::EchoUint8List( - const std::vector& a_list_arg, + const std::vector& list_arg, std::function&)>&& on_success, std::function&& on_error) { const std::string channel_name = @@ -5237,7 +5234,7 @@ void FlutterIntegrationCoreApi::EchoUint8List( message_channel_suffix_; BasicMessageChannel<> channel(binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(EncodableList{ - EncodableValue(a_list_arg), + EncodableValue(list_arg), }); channel.Send( encoded_api_arguments, [channel_name, on_success = std::move(on_success), @@ -5266,7 +5263,7 @@ void FlutterIntegrationCoreApi::EchoUint8List( } void FlutterIntegrationCoreApi::EchoList( - const EncodableList& a_list_arg, + const EncodableList& list_arg, std::function&& on_success, std::function&& on_error) { const std::string channel_name = @@ -5275,7 +5272,7 @@ void FlutterIntegrationCoreApi::EchoList( message_channel_suffix_; BasicMessageChannel<> channel(binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(EncodableList{ - EncodableValue(a_list_arg), + EncodableValue(list_arg), }); channel.Send( encoded_api_arguments, [channel_name, on_success = std::move(on_success), @@ -5531,7 +5528,7 @@ void FlutterIntegrationCoreApi::EchoNullableString( } void FlutterIntegrationCoreApi::EchoNullableUint8List( - const std::vector* a_list_arg, + const std::vector* list_arg, std::function*)>&& on_success, std::function&& on_error) { const std::string channel_name = @@ -5540,7 +5537,7 @@ void FlutterIntegrationCoreApi::EchoNullableUint8List( message_channel_suffix_; BasicMessageChannel<> channel(binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(EncodableList{ - a_list_arg ? EncodableValue(*a_list_arg) : EncodableValue(), + list_arg ? EncodableValue(*list_arg) : EncodableValue(), }); channel.Send( encoded_api_arguments, [channel_name, on_success = std::move(on_success), @@ -5569,7 +5566,7 @@ void FlutterIntegrationCoreApi::EchoNullableUint8List( } void FlutterIntegrationCoreApi::EchoNullableList( - const EncodableList* a_list_arg, + const EncodableList* list_arg, std::function&& on_success, std::function&& on_error) { const std::string channel_name = @@ -5578,7 +5575,7 @@ void FlutterIntegrationCoreApi::EchoNullableList( message_channel_suffix_; BasicMessageChannel<> channel(binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(EncodableList{ - a_list_arg ? EncodableValue(*a_list_arg) : EncodableValue(), + list_arg ? EncodableValue(*list_arg) : EncodableValue(), }); channel.Send( encoded_api_arguments, [channel_name, on_success = std::move(on_success), diff --git a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h index 15a98bf6bba..7ee94453826 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h +++ b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h @@ -84,7 +84,7 @@ class AllTypes { const std::vector& a4_byte_array, const std::vector& a8_byte_array, const std::vector& a_float_array, - const flutter::EncodableList& a_list, + const flutter::EncodableList& list, const flutter::EncodableMap& a_map, const AnEnum& an_enum, const std::string& a_string, const flutter::EncodableValue& an_object); @@ -113,8 +113,8 @@ class AllTypes { const std::vector& a_float_array() const; void set_a_float_array(const std::vector& value_arg); - const flutter::EncodableList& a_list() const; - void set_a_list(const flutter::EncodableList& value_arg); + const flutter::EncodableList& list() const; + void set_list(const flutter::EncodableList& value_arg); const flutter::EncodableMap& a_map() const; void set_a_map(const flutter::EncodableMap& value_arg); @@ -151,7 +151,7 @@ class AllTypes { std::vector a4_byte_array_; std::vector a8_byte_array_; std::vector a_float_array_; - flutter::EncodableList a_list_; + flutter::EncodableList list_; flutter::EncodableMap a_map_; AnEnum an_enum_; std::string a_string_; @@ -563,7 +563,7 @@ class HostIntegrationCoreApi { const flutter::EncodableValue& an_object) = 0; // Returns the passed list, to test serialization and deserialization. virtual ErrorOr EchoList( - const flutter::EncodableList& a_list) = 0; + const flutter::EncodableList& list) = 0; // Returns the passed map, to test serialization and deserialization. virtual ErrorOr EchoMap( const flutter::EncodableMap& a_map) = 0; @@ -664,7 +664,7 @@ class HostIntegrationCoreApi { // Returns the passed list, to test asynchronous serialization and // deserialization. virtual void EchoAsyncList( - const flutter::EncodableList& a_list, + const flutter::EncodableList& list, std::function reply)> result) = 0; // Returns the passed map, to test asynchronous serialization and // deserialization. @@ -732,7 +732,7 @@ class HostIntegrationCoreApi { // Returns the passed list, to test asynchronous serialization and // deserialization. virtual void EchoAsyncNullableList( - const flutter::EncodableList* a_list, + const flutter::EncodableList* list, std::function> reply)> result) = 0; // Returns the passed map, to test asynchronous serialization and @@ -784,10 +784,10 @@ class HostIntegrationCoreApi { const std::string& a_string, std::function reply)> result) = 0; virtual void CallFlutterEchoUint8List( - const std::vector& a_list, + const std::vector& list, std::function> reply)> result) = 0; virtual void CallFlutterEchoList( - const flutter::EncodableList& a_list, + const flutter::EncodableList& list, std::function reply)> result) = 0; virtual void CallFlutterEchoMap( const flutter::EncodableMap& a_map, @@ -809,11 +809,11 @@ class HostIntegrationCoreApi { std::function> reply)> result) = 0; virtual void CallFlutterEchoNullableUint8List( - const std::vector* a_list, + const std::vector* list, std::function>> reply)> result) = 0; virtual void CallFlutterEchoNullableList( - const flutter::EncodableList* a_list, + const flutter::EncodableList* list, std::function> reply)> result) = 0; virtual void CallFlutterEchoNullableMap( @@ -926,11 +926,11 @@ class FlutterIntegrationCoreApi { std::function&& on_error); // Returns the passed byte list, to test serialization and deserialization. void EchoUint8List( - const std::vector& a_list, + const std::vector& list, std::function&)>&& on_success, std::function&& on_error); // Returns the passed list, to test serialization and deserialization. - void EchoList(const flutter::EncodableList& a_list, + void EchoList(const flutter::EncodableList& list, std::function&& on_success, std::function&& on_error); // Returns the passed map, to test serialization and deserialization. @@ -959,12 +959,12 @@ class FlutterIntegrationCoreApi { std::function&& on_error); // Returns the passed byte list, to test serialization and deserialization. void EchoNullableUint8List( - const std::vector* a_list, + const std::vector* list, std::function*)>&& on_success, std::function&& on_error); // Returns the passed list, to test serialization and deserialization. void EchoNullableList( - const flutter::EncodableList* a_list, + const flutter::EncodableList* list, std::function&& on_success, std::function&& on_error); // Returns the passed map, to test serialization and deserialization. diff --git a/packages/pigeon/platform_tests/test_plugin/windows/test/null_fields_test.cpp b/packages/pigeon/platform_tests/test_plugin/windows/test/null_fields_test.cpp index fa21a9619ac..d0c04561882 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/test/null_fields_test.cpp +++ b/packages/pigeon/platform_tests/test_plugin/windows/test/null_fields_test.cpp @@ -11,6 +11,7 @@ namespace null_fields_pigeontest { namespace { +using flutter::CustomEncodableValue; using flutter::EncodableList; using flutter::EncodableMap; using flutter::EncodableValue; @@ -113,6 +114,8 @@ TEST_F(NullFieldsTest, RequestFromListWithNulls) { } TEST_F(NullFieldsTest, ReplyFromListWithValues) { + NullFieldsSearchRequest request(1); + request.set_query("hello"); EncodableList list{ EncodableValue("result"), EncodableValue("error"), @@ -121,10 +124,7 @@ TEST_F(NullFieldsTest, ReplyFromListWithValues) { EncodableValue(2), EncodableValue(3), }), - EncodableValue(EncodableList{ - EncodableValue("hello"), - EncodableValue(1), - }), + CustomEncodableValue(request), EncodableValue(0), }; NullFieldsSearchReply reply = ReplyFromList(list); @@ -194,10 +194,11 @@ TEST_F(NullFieldsTest, ReplyToMapWithValues) { EXPECT_EQ(indices[0].LongValue(), 1L); EXPECT_EQ(indices[1].LongValue(), 2L); EXPECT_EQ(indices[2].LongValue(), 3L); - const EncodableList& request_list = - *ExpectAndGetIndex(list, 3); - EXPECT_EQ(*ExpectAndGetIndex(request_list, 0), "hello"); - EXPECT_EQ(*ExpectAndGetIndex(request_list, 1), 1); + const NullFieldsSearchRequest& request_from_list = + std::any_cast( + *ExpectAndGetIndex(list, 3)); + EXPECT_EQ(*request_from_list.query(), "hello"); + EXPECT_EQ(request_from_list.identifier(), 1); } TEST_F(NullFieldsTest, ReplyToListWithNulls) { diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index f368b97536a..ab80e97230d 100644 --- a/packages/pigeon/pubspec.yaml +++ b/packages/pigeon/pubspec.yaml @@ -2,7 +2,7 @@ name: pigeon description: Code generator tool to make communication between Flutter and the host platform type-safe and easier. repository: https://github.com/flutter/packages/tree/main/packages/pigeon issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+pigeon%22 -version: 18.0.0 # This must match the version in lib/generator_tools.dart +version: 18.0.1 # This must match the version in lib/generator_tools.dart environment: sdk: ^3.1.0 diff --git a/packages/pigeon/test/cpp_generator_test.dart b/packages/pigeon/test/cpp_generator_test.dart index c2fdcd68f68..8695ae45e96 100644 --- a/packages/pigeon/test/cpp_generator_test.dart +++ b/packages/pigeon/test/cpp_generator_test.dart @@ -651,8 +651,7 @@ void main() { expect( code, contains( - 'nullable_nested_ ? EncodableValue(nullable_nested_->ToEncodableList()) ' - ': EncodableValue()')); + 'nullable_nested_ ? CustomEncodableValue(*nullable_nested_) : EncodableValue())')); // Serialization should use push_back, not initializer lists, to avoid // copies. @@ -805,13 +804,15 @@ void main() { 'non_nullable_nested_ = std::make_unique(value_arg);')); // Serialization uses the value directly. expect(code, contains('EncodableValue(non_nullable_bool_)')); - expect(code, contains('non_nullable_nested_->ToEncodableList()')); + expect(code, contains('CustomEncodableValue(*non_nullable_nested_)')); // Serialization should use push_back, not initializer lists, to avoid // copies. expect(code, contains('list.reserve(4)')); expect( - code, contains('list.push_back(EncodableValue(non_nullable_bool_))')); + code, + contains( + 'list.push_back(CustomEncodableValue(*non_nullable_nested_))')); } }); @@ -1637,13 +1638,13 @@ void main() { dartPackageName: DEFAULT_PACKAGE_NAME, ); final String code = sink.toString(); - // Standard types are wrapped an EncodableValues. + // Standard types are wrapped in EncodableValues. expect(code, contains('EncodableValue(a_bool_arg)')); expect(code, contains('EncodableValue(an_int_arg)')); expect(code, contains('EncodableValue(a_string_arg)')); expect(code, contains('EncodableValue(a_list_arg)')); expect(code, contains('EncodableValue(a_map_arg)')); - // Class types use ToEncodableList. + // Class types are wrapped in CustomEncodableValues. expect(code, contains('CustomEncodableValue(an_object_arg)')); } }); diff --git a/packages/pigeon/test/dart_generator_test.dart b/packages/pigeon/test/dart_generator_test.dart index bdb8ece598f..a1470427c7f 100644 --- a/packages/pigeon/test/dart_generator_test.dart +++ b/packages/pigeon/test/dart_generator_test.dart @@ -246,13 +246,13 @@ void main() { expect( code, contains( - 'nested?.encode(),', + 'nested,', ), ); expect( - code.replaceAll('\n', ' ').replaceAll(' ', ''), + code, contains( - 'nested: result[0] != null ? Input.decode(result[0]! as List) : null', + 'nested: result[0] as Input?', ), ); }); @@ -295,13 +295,13 @@ void main() { expect( code, contains( - 'nested.encode(),', + 'nested,', ), ); expect( - code.replaceAll('\n', ' ').replaceAll(' ', ''), + code, contains( - 'nested: Input.decode(result[0]! as List)', + 'nested: result[0]! as Input', ), ); }); diff --git a/packages/pigeon/test/java_generator_test.dart b/packages/pigeon/test/java_generator_test.dart index d620ee6c182..c3bb560279d 100644 --- a/packages/pigeon/test/java_generator_test.dart +++ b/packages/pigeon/test/java_generator_test.dart @@ -575,11 +575,7 @@ void main() { expect(code, contains('public static final class Outer')); expect(code, contains('public static final class Nested')); expect(code, contains('private @Nullable Nested nested;')); - expect( - code, - contains( - '(nested == null) ? null : Nested.fromList((ArrayList) nested)')); - expect(code, contains('add((nested == null) ? null : nested.toList());')); + expect(code, contains('add(nested);')); }); test('gen one async Host Api', () { diff --git a/packages/pigeon/test/kotlin_generator_test.dart b/packages/pigeon/test/kotlin_generator_test.dart index d0fcb1e3bc5..2051e4a12a5 100644 --- a/packages/pigeon/test/kotlin_generator_test.dart +++ b/packages/pigeon/test/kotlin_generator_test.dart @@ -51,7 +51,7 @@ void main() { final String code = sink.toString(); expect(code, contains('data class Foobar (')); expect(code, contains('val field1: Long? = null')); - expect(code, contains('fun fromList(list: List): Foobar')); + expect(code, contains('fun fromList(__pigeon_list: List): Foobar')); expect(code, contains('fun toList(): List')); }); @@ -132,9 +132,10 @@ void main() { expect(code, contains('data class Bar (')); expect(code, contains('val field1: Foo,')); expect(code, contains('val field2: String')); - expect(code, contains('fun fromList(list: List): Bar')); - expect(code, contains('val field1 = Foo.ofRaw(list[0] as Int)!!\n')); - expect(code, contains('val field2 = list[1] as String\n')); + expect(code, contains('fun fromList(__pigeon_list: List): Bar')); + expect( + code, contains('val field1 = Foo.ofRaw(__pigeon_list[0] as Int)!!\n')); + expect(code, contains('val field2 = __pigeon_list[1] as String\n')); expect(code, contains('fun toList(): List')); }); @@ -236,11 +237,10 @@ void main() { channel.setMessageHandler { message, reply -> val args = message as List val inputArg = args[0] as Input - var wrapped: List - try { - wrapped = listOf(api.doSomething(inputArg)) + val wrapped: List = try { + listOf(api.doSomething(inputArg)) } catch (exception: Throwable) { - wrapped = wrapError(exception) + wrapError(exception) } reply.reply(wrapped) } @@ -390,7 +390,7 @@ void main() { expect( code, contains( - 'val aInt = list[1].let { if (it is Int) it.toLong() else it as Long }')); + 'val aInt = __pigeon_list[1].let { num -> if (num is Int) num.toLong() else num as Long }')); expect(code, contains('val aNullableBool: Boolean? = null')); expect(code, contains('val aNullableInt: Long? = null')); expect(code, contains('val aNullableDouble: Double? = null')); @@ -402,7 +402,7 @@ void main() { expect( code, contains( - 'val aNullableInt = list[9].let { if (it is Int) it.toLong() else it as Long? }')); + 'val aNullableInt = __pigeon_list[9].let { num -> if (num is Int) num.toLong() else num as Long? }')); }); test('gen one flutter api', () { @@ -591,8 +591,8 @@ void main() { ); final String code = sink.toString(); expect(code, contains('fun doSomething(): Output')); - expect(code, contains('wrapped = listOf(api.doSomething())')); - expect(code, contains('wrapped = wrapError(exception)')); + expect(code, contains('listOf(api.doSomething())')); + expect(code, contains('wrapError(exception)')); expect(code, contains('reply(wrapped)')); }); @@ -732,10 +732,8 @@ void main() { expect(code, contains('data class Outer')); expect(code, contains('data class Nested')); expect(code, contains('val nested: Nested? = null')); - expect(code, contains('fun fromList(list: List): Outer')); - expect( - code, contains('val nested: Nested? = (list[0] as List?)?.let')); - expect(code, contains('Nested.fromList(it)')); + expect(code, contains('fun fromList(__pigeon_list: List): Outer')); + expect(code, contains('val nested = __pigeon_list[0] as Nested?')); expect(code, contains('fun toList(): List')); }); @@ -1091,7 +1089,7 @@ void main() { ); final String code = sink.toString(); expect(code, contains('fun doit(): List')); - expect(code, contains('wrapped = listOf(api.doit())')); + expect(code, contains('listOf(api.doit())')); expect(code, contains('reply.reply(wrapped)')); }); @@ -1164,12 +1162,12 @@ void main() { expect( code, contains( - 'val xArg = args[0].let { if (it is Int) it.toLong() else it as Long }')); + 'val xArg = args[0].let { num -> if (num is Int) num.toLong() else num as Long }')); expect( code, contains( - 'val yArg = args[1].let { if (it is Int) it.toLong() else it as Long }')); - expect(code, contains('wrapped = listOf(api.add(xArg, yArg))')); + 'val yArg = args[1].let { num -> if (num is Int) num.toLong() else num as Long }')); + expect(code, contains('listOf(api.add(xArg, yArg))')); expect(code, contains('reply.reply(wrapped)')); }); @@ -1207,7 +1205,7 @@ void main() { expect( code, contains( - 'val output = it[0].let { if (it is Int) it.toLong() else it as Long }'), + 'val output = it[0].let { num -> if (num is Int) num.toLong() else num as Long }'), ); expect(code, contains('callback(Result.success(output))')); expect( @@ -1312,7 +1310,7 @@ void main() { expect( code, contains( - 'val fooArg = args[0].let { if (it is Int) it.toLong() else it as Long? }')); + 'val fooArg = args[0].let { num -> if (num is Int) num.toLong() else num as Long? }')); }); test('nullable argument flutter', () { diff --git a/packages/pigeon/test/objc_generator_test.dart b/packages/pigeon/test/objc_generator_test.dart index 7717f0ca877..49ab94b78bc 100644 --- a/packages/pigeon/test/objc_generator_test.dart +++ b/packages/pigeon/test/objc_generator_test.dart @@ -600,12 +600,8 @@ void main() { dartPackageName: DEFAULT_PACKAGE_NAME, ); final String code = sink.toString(); - expect( - code, - contains( - 'pigeonResult.nested = [Input nullableFromList:(GetNullableObjectAtIndex(list, 0))];')); - expect( - code, contains('self.nested ? [self.nested toList] : [NSNull null]')); + expect(code, + contains('pigeonResult.nested = GetNullableObjectAtIndex(list, 0);')); }); test('prefix class header', () { diff --git a/packages/pigeon/test/swift_generator_test.dart b/packages/pigeon/test/swift_generator_test.dart index a4eb67427b9..8fb544bbedb 100644 --- a/packages/pigeon/test/swift_generator_test.dart +++ b/packages/pigeon/test/swift_generator_test.dart @@ -50,7 +50,8 @@ void main() { final String code = sink.toString(); expect(code, contains('struct Foobar')); expect(code, contains('var field1: Int64? = nil')); - expect(code, contains('static func fromList(_ list: [Any?]) -> Foobar?')); + expect(code, + contains('static func fromList(_ __pigeon_list: [Any?]) -> Foobar?')); expect(code, contains('func toList() -> [Any?]')); expect(code, isNot(contains('if ('))); }); @@ -575,8 +576,10 @@ void main() { expect(code, contains('struct Outer')); expect(code, contains('struct Nested')); expect(code, contains('var nested: Nested? = nil')); - expect(code, contains('static func fromList(_ list: [Any?]) -> Outer?')); - expect(code, contains('nested = Nested.fromList(nestedList)')); + expect(code, + contains('static func fromList(_ __pigeon_list: [Any?]) -> Outer?')); + expect( + code, contains('let nested: Nested? = nilOrValue(__pigeon_list[0])')); expect(code, contains('func toList() -> [Any?]')); expect(code, isNot(contains('if ('))); // Single-element list serializations should not have a trailing comma. diff --git a/packages/video_player/video_player_avfoundation/CHANGELOG.md b/packages/video_player/video_player_avfoundation/CHANGELOG.md index 80078f24cc4..2b2f32ac44a 100644 --- a/packages/video_player/video_player_avfoundation/CHANGELOG.md +++ b/packages/video_player/video_player_avfoundation/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.5.8 + +* Adds Swift Package Manager compatibility. + ## 2.5.7 * Adds frame availability checks on iOS. diff --git a/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation.podspec b/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation.podspec index 50b4b2b5baf..81e8d2f8e4e 100644 --- a/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation.podspec +++ b/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation.podspec @@ -14,14 +14,14 @@ Downloaded by pub (not CocoaPods). s.author = { 'Flutter Dev Team' => 'flutter-dev@googlegroups.com' } s.source = { :http => 'https://github.com/flutter/packages/tree/main/packages/video_player/video_player_avfoundation' } s.documentation_url = 'https://pub.dev/packages/video_player' - s.source_files = 'Classes/*' - s.ios.source_files = 'Classes/ios/*' - s.osx.source_files = 'Classes/macos/*' - s.public_header_files = 'Classes/**/*.h' + s.source_files = 'video_player_avfoundation/Sources/video_player_avfoundation/**/*.{h,m}' + s.ios.source_files = 'video_player_avfoundation/Sources/video_player_avfoundation_ios/*' + s.osx.source_files = 'video_player_avfoundation/Sources/video_player_avfoundation_macos/*' + s.public_header_files = 'video_player_avfoundation/Sources/video_player_avfoundation/include/**/*.h' s.ios.dependency 'Flutter' s.osx.dependency 'FlutterMacOS' s.ios.deployment_target = '12.0' s.osx.deployment_target = '10.14' s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' } - s.resource_bundles = {'video_player_avfoundation_privacy' => ['Resources/PrivacyInfo.xcprivacy']} + s.resource_bundles = {'video_player_avfoundation_privacy' => ['video_player_avfoundation/Sources/video_player_avfoundation/Resources/PrivacyInfo.xcprivacy']} end diff --git a/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Package.swift b/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Package.swift new file mode 100644 index 00000000000..32bd171e33e --- /dev/null +++ b/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Package.swift @@ -0,0 +1,46 @@ +// swift-tools-version: 5.9 + +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import PackageDescription + +let package = Package( + name: "video_player_avfoundation", + platforms: [ + .iOS("12.0"), + .macOS("10.14"), + ], + products: [ + .library(name: "video-player-avfoundation", targets: ["video_player_avfoundation"]) + ], + dependencies: [], + targets: [ + .target( + name: "video_player_avfoundation", + dependencies: [ + .target(name: "video_player_avfoundation_ios", condition: .when(platforms: [.iOS])), + .target(name: "video_player_avfoundation_macos", condition: .when(platforms: [.macOS])), + ], + resources: [ + .process("Resources") + ], + cSettings: [ + .headerSearchPath("include/video_player_avfoundation") + ] + ), + .target( + name: "video_player_avfoundation_ios", + cSettings: [ + .headerSearchPath("../video_player_avfoundation/include/video_player_avfoundation") + ] + ), + .target( + name: "video_player_avfoundation_macos", + cSettings: [ + .headerSearchPath("../video_player_avfoundation/include/video_player_avfoundation") + ] + ), + ] +) diff --git a/packages/video_player/video_player_avfoundation/darwin/Classes/AVAssetTrackUtils.m b/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/AVAssetTrackUtils.m similarity index 100% rename from packages/video_player/video_player_avfoundation/darwin/Classes/AVAssetTrackUtils.m rename to packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/AVAssetTrackUtils.m diff --git a/packages/video_player/video_player_avfoundation/darwin/Classes/FVPVideoPlayerPlugin.m b/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/FVPVideoPlayerPlugin.m similarity index 99% rename from packages/video_player/video_player_avfoundation/darwin/Classes/FVPVideoPlayerPlugin.m rename to packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/FVPVideoPlayerPlugin.m index 8c76cb15879..14ee7ccefde 100644 --- a/packages/video_player/video_player_avfoundation/darwin/Classes/FVPVideoPlayerPlugin.m +++ b/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/FVPVideoPlayerPlugin.m @@ -8,9 +8,9 @@ #import #import -#import "AVAssetTrackUtils.h" -#import "FVPDisplayLink.h" -#import "messages.g.h" +#import "./include/video_player_avfoundation/AVAssetTrackUtils.h" +#import "./include/video_player_avfoundation/FVPDisplayLink.h" +#import "./include/video_player_avfoundation/messages.g.h" #if !__has_feature(objc_arc) #error Code Requires ARC. diff --git a/packages/video_player/video_player_avfoundation/darwin/Resources/PrivacyInfo.xcprivacy b/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/Resources/PrivacyInfo.xcprivacy similarity index 100% rename from packages/video_player/video_player_avfoundation/darwin/Resources/PrivacyInfo.xcprivacy rename to packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/Resources/PrivacyInfo.xcprivacy diff --git a/packages/video_player/video_player_avfoundation/darwin/Classes/AVAssetTrackUtils.h b/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/include/video_player_avfoundation/AVAssetTrackUtils.h similarity index 100% rename from packages/video_player/video_player_avfoundation/darwin/Classes/AVAssetTrackUtils.h rename to packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/include/video_player_avfoundation/AVAssetTrackUtils.h diff --git a/packages/video_player/video_player_avfoundation/darwin/Classes/FVPDisplayLink.h b/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/include/video_player_avfoundation/FVPDisplayLink.h similarity index 100% rename from packages/video_player/video_player_avfoundation/darwin/Classes/FVPDisplayLink.h rename to packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/include/video_player_avfoundation/FVPDisplayLink.h diff --git a/packages/video_player/video_player_avfoundation/darwin/Classes/FVPVideoPlayerPlugin.h b/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/include/video_player_avfoundation/FVPVideoPlayerPlugin.h similarity index 100% rename from packages/video_player/video_player_avfoundation/darwin/Classes/FVPVideoPlayerPlugin.h rename to packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/include/video_player_avfoundation/FVPVideoPlayerPlugin.h diff --git a/packages/video_player/video_player_avfoundation/darwin/Classes/FVPVideoPlayerPlugin_Test.h b/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/include/video_player_avfoundation/FVPVideoPlayerPlugin_Test.h similarity index 100% rename from packages/video_player/video_player_avfoundation/darwin/Classes/FVPVideoPlayerPlugin_Test.h rename to packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/include/video_player_avfoundation/FVPVideoPlayerPlugin_Test.h diff --git a/packages/video_player/video_player_avfoundation/darwin/Classes/messages.g.h b/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/include/video_player_avfoundation/messages.g.h similarity index 100% rename from packages/video_player/video_player_avfoundation/darwin/Classes/messages.g.h rename to packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/include/video_player_avfoundation/messages.g.h diff --git a/packages/video_player/video_player_avfoundation/darwin/Classes/messages.g.m b/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/messages.g.m similarity index 99% rename from packages/video_player/video_player_avfoundation/darwin/Classes/messages.g.m rename to packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/messages.g.m index 97b408b53be..1e2354d8828 100644 --- a/packages/video_player/video_player_avfoundation/darwin/Classes/messages.g.m +++ b/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/messages.g.m @@ -4,7 +4,7 @@ // Autogenerated from Pigeon (v18.0.0), do not edit directly. // See also: https://pub.dev/packages/pigeon -#import "messages.g.h" +#import "./include/video_player_avfoundation/messages.g.h" #if TARGET_OS_OSX #import diff --git a/packages/video_player/video_player_avfoundation/darwin/Classes/ios/FVPDisplayLink.m b/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation_ios/FVPDisplayLink.m similarity index 95% rename from packages/video_player/video_player_avfoundation/darwin/Classes/ios/FVPDisplayLink.m rename to packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation_ios/FVPDisplayLink.m index 505001bc223..9bdb321ae16 100644 --- a/packages/video_player/video_player_avfoundation/darwin/Classes/ios/FVPDisplayLink.m +++ b/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation_ios/FVPDisplayLink.m @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#import "../FVPDisplayLink.h" +#import "../video_player_avfoundation/include/video_player_avfoundation/FVPDisplayLink.h" #import #import diff --git a/packages/video_player/video_player_avfoundation/darwin/Assets/.gitkeep b/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation_ios/include/.gitkeep similarity index 100% rename from packages/video_player/video_player_avfoundation/darwin/Assets/.gitkeep rename to packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation_ios/include/.gitkeep diff --git a/packages/video_player/video_player_avfoundation/darwin/Classes/macos/FVPDisplayLink.m b/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation_macos/FVPDisplayLink.m similarity index 97% rename from packages/video_player/video_player_avfoundation/darwin/Classes/macos/FVPDisplayLink.m rename to packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation_macos/FVPDisplayLink.m index 3904c8a288a..cd5670fa5a3 100644 --- a/packages/video_player/video_player_avfoundation/darwin/Classes/macos/FVPDisplayLink.m +++ b/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation_macos/FVPDisplayLink.m @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#import "../FVPDisplayLink.h" +#import "../video_player_avfoundation/include/video_player_avfoundation/FVPDisplayLink.h" #import #import diff --git a/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation_macos/include/.gitkeep b/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation_macos/include/.gitkeep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/video_player/video_player_avfoundation/example/ios/Podfile b/packages/video_player/video_player_avfoundation/example/ios/Podfile index 3278285d9d7..c9339a034eb 100644 --- a/packages/video_player/video_player_avfoundation/example/ios/Podfile +++ b/packages/video_player/video_player_avfoundation/example/ios/Podfile @@ -31,7 +31,6 @@ target 'Runner' do flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) target 'RunnerTests' do inherit! :search_paths - pod 'OCMock', '3.9.1' end end diff --git a/packages/video_player/video_player_avfoundation/example/ios/Runner.xcodeproj/project.pbxproj b/packages/video_player/video_player_avfoundation/example/ios/Runner.xcodeproj/project.pbxproj index feb1ba462cc..0f6dd7a79da 100644 --- a/packages/video_player/video_player_avfoundation/example/ios/Runner.xcodeproj/project.pbxproj +++ b/packages/video_player/video_player_avfoundation/example/ios/Runner.xcodeproj/project.pbxproj @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; + 78CF8D742BC5CEA80051231B /* OCMock in Frameworks */ = {isa = PBXBuildFile; productRef = 78CF8D732BC5CEA80051231B /* OCMock */; }; 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; }; 97C146F31CF9000F007C117D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 97C146F21CF9000F007C117D /* main.m */; }; 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; @@ -99,6 +100,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 78CF8D742BC5CEA80051231B /* OCMock in Frameworks */, D182ECB59C06DBC7E2D5D913 /* libPods-RunnerTests.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -260,6 +262,9 @@ F7151F4026603ECA0028CB91 /* PBXTargetDependency */, ); name = RunnerTests; + packageProductDependencies = ( + 78CF8D732BC5CEA80051231B /* OCMock */, + ); productName = RunnerTests; productReference = F7151F3A26603ECA0028CB91 /* RunnerTests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; @@ -297,6 +302,9 @@ Base, ); mainGroup = 97C146E51CF9000F007C117D; + packageReferences = ( + 78CF8D722BC5CEA80051231B /* XCRemoteSwiftPackageReference "ocmock" */, + ); productRefGroup = 97C146EF1CF9000F007C117D /* Products */; projectDirPath = ""; projectRoot = ""; @@ -758,6 +766,25 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ + +/* Begin XCRemoteSwiftPackageReference section */ + 78CF8D722BC5CEA80051231B /* XCRemoteSwiftPackageReference "ocmock" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/erikdoe/ocmock"; + requirement = { + kind = revision; + revision = ef21a2ece3ee092f8ed175417718bdd9b8eb7c9a; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + 78CF8D732BC5CEA80051231B /* OCMock */ = { + isa = XCSwiftPackageProductDependency; + package = 78CF8D722BC5CEA80051231B /* XCRemoteSwiftPackageReference "ocmock" */; + productName = OCMock; + }; +/* End XCSwiftPackageProductDependency section */ }; rootObject = 97C146E61CF9000F007C117D /* Project object */; } diff --git a/packages/video_player/video_player_avfoundation/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/packages/video_player/video_player_avfoundation/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved new file mode 100644 index 00000000000..69f8d7acc40 --- /dev/null +++ b/packages/video_player/video_player_avfoundation/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -0,0 +1,13 @@ +{ + "pins" : [ + { + "identity" : "ocmock", + "kind" : "remoteSourceControl", + "location" : "https://github.com/erikdoe/ocmock", + "state" : { + "revision" : "ef21a2ece3ee092f8ed175417718bdd9b8eb7c9a" + } + } + ], + "version" : 2 +} diff --git a/packages/video_player/video_player_avfoundation/example/ios/Runner.xcworkspace/xcshareddata/swiftpm/Package.resolved b/packages/video_player/video_player_avfoundation/example/ios/Runner.xcworkspace/xcshareddata/swiftpm/Package.resolved new file mode 100644 index 00000000000..69f8d7acc40 --- /dev/null +++ b/packages/video_player/video_player_avfoundation/example/ios/Runner.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -0,0 +1,13 @@ +{ + "pins" : [ + { + "identity" : "ocmock", + "kind" : "remoteSourceControl", + "location" : "https://github.com/erikdoe/ocmock", + "state" : { + "revision" : "ef21a2ece3ee092f8ed175417718bdd9b8eb7c9a" + } + } + ], + "version" : 2 +} diff --git a/packages/video_player/video_player_avfoundation/example/macos/Podfile b/packages/video_player/video_player_avfoundation/example/macos/Podfile index c0f5d7877b9..c795730db8e 100644 --- a/packages/video_player/video_player_avfoundation/example/macos/Podfile +++ b/packages/video_player/video_player_avfoundation/example/macos/Podfile @@ -33,7 +33,6 @@ target 'Runner' do flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__)) target 'RunnerTests' do inherit! :search_paths - pod 'OCMock', '3.9.1' end end diff --git a/packages/video_player/video_player_avfoundation/example/macos/Runner.xcodeproj/project.pbxproj b/packages/video_player/video_player_avfoundation/example/macos/Runner.xcodeproj/project.pbxproj index 5159838815f..dc593db1307 100644 --- a/packages/video_player/video_player_avfoundation/example/macos/Runner.xcodeproj/project.pbxproj +++ b/packages/video_player/video_player_avfoundation/example/macos/Runner.xcodeproj/project.pbxproj @@ -28,6 +28,7 @@ 33CC10F32044A3C60003C045 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F22044A3C60003C045 /* Assets.xcassets */; }; 33CC10F62044A3C60003C045 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F42044A3C60003C045 /* MainMenu.xib */; }; 33CC11132044BFA00003C045 /* MainFlutterWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */; }; + 78CF8D772BC5D0140051231B /* OCMock in Frameworks */ = {isa = PBXBuildFile; productRef = 78CF8D762BC5D0140051231B /* OCMock */; }; C000184E56E3386C22EF683A /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CC60543320154AF9A465D416 /* Pods_Runner.framework */; }; /* End PBXBuildFile section */ @@ -95,6 +96,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 78CF8D772BC5D0140051231B /* OCMock in Frameworks */, 18AD5E2A5B24DAFCF3749529 /* Pods_RunnerTests.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -226,6 +228,9 @@ 331C80DA294CF71000263BE5 /* PBXTargetDependency */, ); name = RunnerTests; + packageProductDependencies = ( + 78CF8D762BC5D0140051231B /* OCMock */, + ); productName = RunnerTests; productReference = 331C80D5294CF71000263BE5 /* RunnerTests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; @@ -292,6 +297,9 @@ Base, ); mainGroup = 33CC10E42044A3C60003C045; + packageReferences = ( + 78CF8D752BC5D0140051231B /* XCRemoteSwiftPackageReference "ocmock" */, + ); productRefGroup = 33CC10EE2044A3C60003C045 /* Products */; projectDirPath = ""; projectRoot = ""; @@ -808,6 +816,25 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ + +/* Begin XCRemoteSwiftPackageReference section */ + 78CF8D752BC5D0140051231B /* XCRemoteSwiftPackageReference "ocmock" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/erikdoe/ocmock"; + requirement = { + kind = revision; + revision = ef21a2ece3ee092f8ed175417718bdd9b8eb7c9a; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + 78CF8D762BC5D0140051231B /* OCMock */ = { + isa = XCSwiftPackageProductDependency; + package = 78CF8D752BC5D0140051231B /* XCRemoteSwiftPackageReference "ocmock" */; + productName = OCMock; + }; +/* End XCSwiftPackageProductDependency section */ }; rootObject = 33CC10E52044A3C60003C045 /* Project object */; } diff --git a/packages/video_player/video_player_avfoundation/example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/packages/video_player/video_player_avfoundation/example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved new file mode 100644 index 00000000000..69f8d7acc40 --- /dev/null +++ b/packages/video_player/video_player_avfoundation/example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -0,0 +1,13 @@ +{ + "pins" : [ + { + "identity" : "ocmock", + "kind" : "remoteSourceControl", + "location" : "https://github.com/erikdoe/ocmock", + "state" : { + "revision" : "ef21a2ece3ee092f8ed175417718bdd9b8eb7c9a" + } + } + ], + "version" : 2 +} diff --git a/packages/video_player/video_player_avfoundation/example/macos/Runner.xcworkspace/xcshareddata/swiftpm/Package.resolved b/packages/video_player/video_player_avfoundation/example/macos/Runner.xcworkspace/xcshareddata/swiftpm/Package.resolved new file mode 100644 index 00000000000..69f8d7acc40 --- /dev/null +++ b/packages/video_player/video_player_avfoundation/example/macos/Runner.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -0,0 +1,13 @@ +{ + "pins" : [ + { + "identity" : "ocmock", + "kind" : "remoteSourceControl", + "location" : "https://github.com/erikdoe/ocmock", + "state" : { + "revision" : "ef21a2ece3ee092f8ed175417718bdd9b8eb7c9a" + } + } + ], + "version" : 2 +} diff --git a/packages/video_player/video_player_avfoundation/example/macos/Runner/AppDelegate.swift b/packages/video_player/video_player_avfoundation/example/macos/Runner/AppDelegate.swift index 5cec4c48f62..689c0ecd525 100644 --- a/packages/video_player/video_player_avfoundation/example/macos/Runner/AppDelegate.swift +++ b/packages/video_player/video_player_avfoundation/example/macos/Runner/AppDelegate.swift @@ -5,7 +5,7 @@ import Cocoa import FlutterMacOS -@NSApplicationMain +@main class AppDelegate: FlutterAppDelegate { override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { return true diff --git a/packages/video_player/video_player_avfoundation/pigeons/messages.dart b/packages/video_player/video_player_avfoundation/pigeons/messages.dart index 1f9795360c3..8dbda80bd55 100644 --- a/packages/video_player/video_player_avfoundation/pigeons/messages.dart +++ b/packages/video_player/video_player_avfoundation/pigeons/messages.dart @@ -7,10 +7,13 @@ import 'package:pigeon/pigeon.dart'; @ConfigurePigeon(PigeonOptions( dartOut: 'lib/src/messages.g.dart', dartTestOut: 'test/test_api.g.dart', - objcHeaderOut: 'darwin/Classes/messages.g.h', - objcSourceOut: 'darwin/Classes/messages.g.m', + objcHeaderOut: + 'darwin/video_player_avfoundation/Sources/video_player_avfoundation/include/video_player_avfoundation/messages.g.h', + objcSourceOut: + 'darwin/video_player_avfoundation/Sources/video_player_avfoundation/messages.g.m', objcOptions: ObjcOptions( prefix: 'FVP', + headerIncludePath: './include/video_player_avfoundation/messages.g.h', ), copyrightHeader: 'pigeons/copyright.txt', )) diff --git a/packages/video_player/video_player_avfoundation/pubspec.yaml b/packages/video_player/video_player_avfoundation/pubspec.yaml index 121d3a7a1aa..ca031a14772 100644 --- a/packages/video_player/video_player_avfoundation/pubspec.yaml +++ b/packages/video_player/video_player_avfoundation/pubspec.yaml @@ -2,7 +2,7 @@ name: video_player_avfoundation description: iOS and macOS implementation of the video_player plugin. repository: https://github.com/flutter/packages/tree/main/packages/video_player/video_player_avfoundation issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22 -version: 2.5.7 +version: 2.5.8 environment: sdk: ^3.2.3