diff --git a/packages/file_selector/file_selector_ios/CHANGELOG.md b/packages/file_selector/file_selector_ios/CHANGELOG.md index 360fe7782ea0..ea488f88a0b0 100644 --- a/packages/file_selector/file_selector_ios/CHANGELOG.md +++ b/packages/file_selector/file_selector_ios/CHANGELOG.md @@ -1,5 +1,6 @@ -## NEXT +## 0.5.3+1 +* Updates Pigeon for non-nullable collection type support. * Updates minimum supported SDK version to Flutter 3.19/Dart 3.3. ## 0.5.3 diff --git a/packages/file_selector/file_selector_ios/ios/file_selector_ios/Sources/file_selector_ios/FileSelectorPlugin.swift b/packages/file_selector/file_selector_ios/ios/file_selector_ios/Sources/file_selector_ios/FileSelectorPlugin.swift index f1f72cc2e281..35135ddc824e 100644 --- a/packages/file_selector/file_selector_ios/ios/file_selector_ios/Sources/file_selector_ios/FileSelectorPlugin.swift +++ b/packages/file_selector/file_selector_ios/ios/file_selector_ios/Sources/file_selector_ios/FileSelectorPlugin.swift @@ -59,8 +59,7 @@ public class FileSelectorPlugin: NSObject, FlutterPlugin, FileSelectorApi { let documentPicker = documentPickerViewControllerOverride ?? UIDocumentPickerViewController( - // See comment in messages.dart for why this is safe. - documentTypes: config.utis as! [String], + documentTypes: config.utis, in: .import) documentPicker.allowsMultipleSelection = config.allowMultiSelection documentPicker.delegate = completionBridge diff --git a/packages/file_selector/file_selector_ios/ios/file_selector_ios/Sources/file_selector_ios/messages.g.swift b/packages/file_selector/file_selector_ios/ios/file_selector_ios/Sources/file_selector_ios/messages.g.swift index 43f1bffeac8c..3d20e5a697b2 100644 --- a/packages/file_selector/file_selector_ios/ios/file_selector_ios/Sources/file_selector_ios/messages.g.swift +++ b/packages/file_selector/file_selector_ios/ios/file_selector_ios/Sources/file_selector_ios/messages.g.swift @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v19.0.0), do not edit directly. +// Autogenerated from Pigeon (v22.4.1), do not edit directly. // See also: https://pub.dev/packages/pigeon import Foundation @@ -69,13 +69,13 @@ private func nilOrValue(_ value: Any?) -> T? { /// Generated class from Pigeon that represents data sent in messages. struct FileSelectorConfig { - var utis: [String?] + var utis: [String] var allowMultiSelection: Bool // swift-format-ignore: AlwaysUseLowerCamelCase - static func fromList(_ __pigeon_list: [Any?]) -> FileSelectorConfig? { - let utis = __pigeon_list[0] as! [String?] - let allowMultiSelection = __pigeon_list[1] as! Bool + static func fromList(_ pigeonVar_list: [Any?]) -> FileSelectorConfig? { + let utis = pigeonVar_list[0] as! [String] + let allowMultiSelection = pigeonVar_list[1] as! Bool return FileSelectorConfig( utis: utis, @@ -90,10 +90,10 @@ struct FileSelectorConfig { } } -private class FileSelectorApiCodecReader: FlutterStandardReader { +private class messagesPigeonCodecReader: FlutterStandardReader { override func readValue(ofType type: UInt8) -> Any? { switch type { - case 128: + case 129: return FileSelectorConfig.fromList(self.readValue() as! [Any?]) default: return super.readValue(ofType: type) @@ -101,10 +101,10 @@ private class FileSelectorApiCodecReader: FlutterStandardReader { } } -private class FileSelectorApiCodecWriter: FlutterStandardWriter { +private class messagesPigeonCodecWriter: FlutterStandardWriter { override func writeValue(_ value: Any) { if let value = value as? FileSelectorConfig { - super.writeByte(128) + super.writeByte(129) super.writeValue(value.toList()) } else { super.writeValue(value) @@ -112,18 +112,18 @@ private class FileSelectorApiCodecWriter: FlutterStandardWriter { } } -private class FileSelectorApiCodecReaderWriter: FlutterStandardReaderWriter { +private class messagesPigeonCodecReaderWriter: FlutterStandardReaderWriter { override func reader(with data: Data) -> FlutterStandardReader { - return FileSelectorApiCodecReader(data: data) + return messagesPigeonCodecReader(data: data) } override func writer(with data: NSMutableData) -> FlutterStandardWriter { - return FileSelectorApiCodecWriter(data: data) + return messagesPigeonCodecWriter(data: data) } } -class FileSelectorApiCodec: FlutterStandardMessageCodec { - static let shared = FileSelectorApiCodec(readerWriter: FileSelectorApiCodecReaderWriter()) +class messagesPigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable { + static let shared = messagesPigeonCodec(readerWriter: messagesPigeonCodecReaderWriter()) } /// Generated protocol from Pigeon that represents a handler of messages from Flutter. @@ -133,8 +133,7 @@ protocol FileSelectorApi { /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. class FileSelectorApiSetup { - /// The codec used by FileSelectorApi. - static var codec: FlutterStandardMessageCodec { FileSelectorApiCodec.shared } + static var codec: FlutterStandardMessageCodec { messagesPigeonCodec.shared } /// Sets up an instance of `FileSelectorApi` to handle messages through the `binaryMessenger`. static func setUp( binaryMessenger: FlutterBinaryMessenger, api: FileSelectorApi?, diff --git a/packages/file_selector/file_selector_ios/lib/file_selector_ios.dart b/packages/file_selector/file_selector_ios/lib/file_selector_ios.dart index d0eb22762bc9..a1ee201937ad 100644 --- a/packages/file_selector/file_selector_ios/lib/file_selector_ios.dart +++ b/packages/file_selector/file_selector_ios/lib/file_selector_ios.dart @@ -21,9 +21,8 @@ class FileSelectorIOS extends FileSelectorPlatform { String? initialDirectory, String? confirmButtonText, }) async { - final List path = (await _hostApi.openFile(FileSelectorConfig( - utis: _allowedUtiListFromTypeGroups(acceptedTypeGroups)))) - .cast(); + final List path = await _hostApi.openFile(FileSelectorConfig( + utis: _allowedUtiListFromTypeGroups(acceptedTypeGroups))); return path.isEmpty ? null : XFile(path.first); } @@ -33,10 +32,9 @@ class FileSelectorIOS extends FileSelectorPlatform { String? initialDirectory, String? confirmButtonText, }) async { - final List pathList = (await _hostApi.openFile(FileSelectorConfig( - utis: _allowedUtiListFromTypeGroups(acceptedTypeGroups), - allowMultiSelection: true))) - .cast(); + final List pathList = await _hostApi.openFile(FileSelectorConfig( + utis: _allowedUtiListFromTypeGroups(acceptedTypeGroups), + allowMultiSelection: true)); return pathList.map((String path) => XFile(path)).toList(); } diff --git a/packages/file_selector/file_selector_ios/lib/src/messages.g.dart b/packages/file_selector/file_selector_ios/lib/src/messages.g.dart index e86dd9c90572..c9c8d6cdbc4d 100644 --- a/packages/file_selector/file_selector_ios/lib/src/messages.g.dart +++ b/packages/file_selector/file_selector_ios/lib/src/messages.g.dart @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v19.0.0), do not edit directly. +// Autogenerated from Pigeon (v22.4.1), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers @@ -31,11 +31,11 @@ List wrapResponse( class FileSelectorConfig { FileSelectorConfig({ - this.utis = const [], + this.utis = const [], this.allowMultiSelection = false, }); - List utis; + List utis; bool allowMultiSelection; @@ -49,18 +49,21 @@ class FileSelectorConfig { static FileSelectorConfig decode(Object result) { result as List; return FileSelectorConfig( - utis: (result[0] as List?)!.cast(), + utis: (result[0] as List?)!.cast(), allowMultiSelection: result[1]! as bool, ); } } -class _FileSelectorApiCodec extends StandardMessageCodec { - const _FileSelectorApiCodec(); +class _PigeonCodec extends StandardMessageCodec { + const _PigeonCodec(); @override void writeValue(WriteBuffer buffer, Object? value) { - if (value is FileSelectorConfig) { - buffer.putUint8(128); + if (value is int) { + buffer.putUint8(4); + buffer.putInt64(value); + } else if (value is FileSelectorConfig) { + buffer.putUint8(129); writeValue(buffer, value.encode()); } else { super.writeValue(buffer, value); @@ -70,7 +73,7 @@ class _FileSelectorApiCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: + case 129: return FileSelectorConfig.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); @@ -84,42 +87,41 @@ class FileSelectorApi { /// BinaryMessenger will be used which routes to the host platform. FileSelectorApi( {BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) - : __pigeon_binaryMessenger = binaryMessenger, - __pigeon_messageChannelSuffix = + : pigeonVar_binaryMessenger = binaryMessenger, + pigeonVar_messageChannelSuffix = messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; - final BinaryMessenger? __pigeon_binaryMessenger; + final BinaryMessenger? pigeonVar_binaryMessenger; - static const MessageCodec pigeonChannelCodec = - _FileSelectorApiCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); - final String __pigeon_messageChannelSuffix; + final String pigeonVar_messageChannelSuffix; - Future> openFile(FileSelectorConfig config) async { - final String __pigeon_channelName = - 'dev.flutter.pigeon.file_selector_ios.FileSelectorApi.openFile$__pigeon_messageChannelSuffix'; - final BasicMessageChannel __pigeon_channel = + Future> openFile(FileSelectorConfig config) async { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.file_selector_ios.FileSelectorApi.openFile$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([config]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = + await pigeonVar_channel.send([config]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); - } else if (__pigeon_replyList[0] == null) { + } else if (pigeonVar_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (__pigeon_replyList[0] as List?)!.cast(); + return (pigeonVar_replyList[0] as List?)!.cast(); } } } diff --git a/packages/file_selector/file_selector_ios/pigeons/messages.dart b/packages/file_selector/file_selector_ios/pigeons/messages.dart index a793a2af5a98..ade4b17835c4 100644 --- a/packages/file_selector/file_selector_ios/pigeons/messages.dart +++ b/packages/file_selector/file_selector_ios/pigeons/messages.dart @@ -12,11 +12,8 @@ import 'package:pigeon/pigeon.dart'; )) class FileSelectorConfig { FileSelectorConfig( - {this.utis = const [], this.allowMultiSelection = false}); - // TODO(stuartmorgan): Declare these as non-nullable generics once - // https://github.com/flutter/flutter/issues/97848 is fixed. In practice, - // the values will never be null, and the native implementation assumes that. - List utis; + {this.utis = const [], this.allowMultiSelection = false}); + List utis; bool allowMultiSelection; } diff --git a/packages/file_selector/file_selector_ios/pubspec.yaml b/packages/file_selector/file_selector_ios/pubspec.yaml index 61fd67adb64b..d86a09d9d7fd 100644 --- a/packages/file_selector/file_selector_ios/pubspec.yaml +++ b/packages/file_selector/file_selector_ios/pubspec.yaml @@ -2,7 +2,7 @@ name: file_selector_ios description: iOS implementation of the file_selector plugin. repository: https://github.com/flutter/packages/tree/main/packages/file_selector/file_selector_ios issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+file_selector%22 -version: 0.5.3 +version: 0.5.3+1 environment: sdk: ^3.3.0 @@ -26,7 +26,7 @@ dev_dependencies: flutter_test: sdk: flutter mockito: ^5.4.4 - pigeon: ^19.0.0 + pigeon: ^22.4.1 topics: - files diff --git a/packages/file_selector/file_selector_ios/test/file_selector_ios_test.mocks.dart b/packages/file_selector/file_selector_ios/test/file_selector_ios_test.mocks.dart index f39e0ff4b618..713bd3f29ba5 100644 --- a/packages/file_selector/file_selector_ios/test/file_selector_ios_test.mocks.dart +++ b/packages/file_selector/file_selector_ios/test/file_selector_ios_test.mocks.dart @@ -33,12 +33,12 @@ class MockTestFileSelectorApi extends _i1.Mock } @override - _i3.Future> openFile(_i4.FileSelectorConfig? config) => + _i3.Future> openFile(_i4.FileSelectorConfig? config) => (super.noSuchMethod( Invocation.method( #openFile, [config], ), - returnValue: _i3.Future>.value([]), - ) as _i3.Future>); + returnValue: _i3.Future>.value([]), + ) as _i3.Future>); } diff --git a/packages/file_selector/file_selector_ios/test/test_api.g.dart b/packages/file_selector/file_selector_ios/test/test_api.g.dart index db24932f71a3..fbe4e1acd920 100644 --- a/packages/file_selector/file_selector_ios/test/test_api.g.dart +++ b/packages/file_selector/file_selector_ios/test/test_api.g.dart @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v19.0.0), do not edit directly. +// Autogenerated from Pigeon (v22.4.1), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import, no_leading_underscores_for_local_identifiers // ignore_for_file: avoid_relative_lib_imports @@ -13,12 +13,15 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:file_selector_ios/src/messages.g.dart'; -class _TestFileSelectorApiCodec extends StandardMessageCodec { - const _TestFileSelectorApiCodec(); +class _PigeonCodec extends StandardMessageCodec { + const _PigeonCodec(); @override void writeValue(WriteBuffer buffer, Object? value) { - if (value is FileSelectorConfig) { - buffer.putUint8(128); + if (value is int) { + buffer.putUint8(4); + buffer.putInt64(value); + } else if (value is FileSelectorConfig) { + buffer.putUint8(129); writeValue(buffer, value.encode()); } else { super.writeValue(buffer, value); @@ -28,7 +31,7 @@ class _TestFileSelectorApiCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: + case 129: return FileSelectorConfig.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); @@ -39,10 +42,9 @@ class _TestFileSelectorApiCodec extends StandardMessageCodec { abstract class TestFileSelectorApi { static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec pigeonChannelCodec = - _TestFileSelectorApiCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); - Future> openFile(FileSelectorConfig config); + Future> openFile(FileSelectorConfig config); static void setUp( TestFileSelectorApi? api, { @@ -52,17 +54,18 @@ abstract class TestFileSelectorApi { messageChannelSuffix = messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< Object?>( 'dev.flutter.pigeon.file_selector_ios.FileSelectorApi.openFile$messageChannelSuffix', pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); + .setMockDecodedMessageHandler(pigeonVar_channel, null); } else { _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, + .setMockDecodedMessageHandler(pigeonVar_channel, (Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.file_selector_ios.FileSelectorApi.openFile was null.'); @@ -72,7 +75,7 @@ abstract class TestFileSelectorApi { assert(arg_config != null, 'Argument for dev.flutter.pigeon.file_selector_ios.FileSelectorApi.openFile was null, expected non-null FileSelectorConfig.'); try { - final List output = await api.openFile(arg_config!); + final List output = await api.openFile(arg_config!); return [output]; } on PlatformException catch (e) { return wrapResponse(error: e); diff --git a/packages/file_selector/file_selector_macos/CHANGELOG.md b/packages/file_selector/file_selector_macos/CHANGELOG.md index 77d143386343..c2c48c5f8485 100644 --- a/packages/file_selector/file_selector_macos/CHANGELOG.md +++ b/packages/file_selector/file_selector_macos/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.9.4+2 + +* Updates Pigeon for non-nullable collection type support. + ## 0.9.4+1 * Adds privacy manifest. diff --git a/packages/file_selector/file_selector_macos/lib/src/messages.g.dart b/packages/file_selector/file_selector_macos/lib/src/messages.g.dart index cbf8dd10007a..d1d45a2777e5 100644 --- a/packages/file_selector/file_selector_macos/lib/src/messages.g.dart +++ b/packages/file_selector/file_selector_macos/lib/src/messages.g.dart @@ -1,9 +1,9 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v10.1.3), do not edit directly. +// Autogenerated from Pigeon (v22.4.1), do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; @@ -11,19 +11,37 @@ import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; +PlatformException _createConnectionError(String channelName) { + return PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel: "$channelName".', + ); +} + +List wrapResponse( + {Object? result, PlatformException? error, bool empty = false}) { + if (empty) { + return []; + } + if (error == null) { + return [result]; + } + return [error.code, error.message, error.details]; +} + /// A Pigeon representation of the macOS portion of an `XTypeGroup`. class AllowedTypes { AllowedTypes({ - required this.extensions, - required this.mimeTypes, - required this.utis, + this.extensions = const [], + this.mimeTypes = const [], + this.utis = const [], }); - List extensions; + List extensions; - List mimeTypes; + List mimeTypes; - List utis; + List utis; Object encode() { return [ @@ -36,9 +54,9 @@ class AllowedTypes { static AllowedTypes decode(Object result) { result as List; return AllowedTypes( - extensions: (result[0] as List?)!.cast(), - mimeTypes: (result[1] as List?)!.cast(), - utis: (result[2] as List?)!.cast(), + extensions: (result[0] as List?)!.cast(), + mimeTypes: (result[1] as List?)!.cast(), + utis: (result[2] as List?)!.cast(), ); } } @@ -65,7 +83,7 @@ class SavePanelOptions { Object encode() { return [ - allowedFileTypes?.encode(), + allowedFileTypes, directoryPath, nameFieldStringValue, prompt, @@ -75,9 +93,7 @@ class SavePanelOptions { static SavePanelOptions decode(Object result) { result as List; return SavePanelOptions( - allowedFileTypes: result[0] != null - ? AllowedTypes.decode(result[0]! as List) - : null, + allowedFileTypes: result[0] as AllowedTypes?, directoryPath: result[1] as String?, nameFieldStringValue: result[2] as String?, prompt: result[3] as String?, @@ -109,7 +125,7 @@ class OpenPanelOptions { allowsMultipleSelection, canChooseDirectories, canChooseFiles, - baseOptions.encode(), + baseOptions, ]; } @@ -119,24 +135,27 @@ class OpenPanelOptions { allowsMultipleSelection: result[0]! as bool, canChooseDirectories: result[1]! as bool, canChooseFiles: result[2]! as bool, - baseOptions: SavePanelOptions.decode(result[3]! as List), + baseOptions: result[3]! as SavePanelOptions, ); } } -class _FileSelectorApiCodec extends StandardMessageCodec { - const _FileSelectorApiCodec(); +class _PigeonCodec extends StandardMessageCodec { + const _PigeonCodec(); @override void writeValue(WriteBuffer buffer, Object? value) { - if (value is AllowedTypes) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else if (value is OpenPanelOptions) { + if (value is int) { + buffer.putUint8(4); + buffer.putInt64(value); + } else if (value is AllowedTypes) { buffer.putUint8(129); writeValue(buffer, value.encode()); } else if (value is SavePanelOptions) { buffer.putUint8(130); writeValue(buffer, value.encode()); + } else if (value is OpenPanelOptions) { + buffer.putUint8(131); + writeValue(buffer, value.encode()); } else { super.writeValue(buffer, value); } @@ -145,12 +164,12 @@ class _FileSelectorApiCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: - return AllowedTypes.decode(readValue(buffer)!); case 129: - return OpenPanelOptions.decode(readValue(buffer)!); + return AllowedTypes.decode(readValue(buffer)!); case 130: return SavePanelOptions.decode(readValue(buffer)!); + case 131: + return OpenPanelOptions.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); } @@ -161,65 +180,74 @@ class FileSelectorApi { /// Constructor for [FileSelectorApi]. 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. - FileSelectorApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; + FileSelectorApi( + {BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) + : pigeonVar_binaryMessenger = binaryMessenger, + pigeonVar_messageChannelSuffix = + messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; + final BinaryMessenger? pigeonVar_binaryMessenger; - static const MessageCodec codec = _FileSelectorApiCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); + + final String pigeonVar_messageChannelSuffix; /// Shows an open panel with the given [options], returning the list of /// selected paths. /// /// An empty list corresponds to a cancelled selection. - Future> displayOpenPanel(OpenPanelOptions arg_options) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.FileSelectorApi.displayOpenPanel', codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_options]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + Future> displayOpenPanel(OpenPanelOptions options) async { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.file_selector_macos.FileSelectorApi.displayOpenPanel$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([options]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); - } else if (replyList[0] == null) { + } else if (pigeonVar_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as List?)!.cast(); + return (pigeonVar_replyList[0] as List?)!.cast(); } } /// Shows a save panel with the given [options], returning the selected path. /// /// A null return corresponds to a cancelled save. - Future displaySavePanel(SavePanelOptions arg_options) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.FileSelectorApi.displaySavePanel', codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_options]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + Future displaySavePanel(SavePanelOptions options) async { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.file_selector_macos.FileSelectorApi.displaySavePanel$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([options]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { - return (replyList[0] as String?); + return (pigeonVar_replyList[0] as String?); } } } diff --git a/packages/file_selector/file_selector_macos/macos/file_selector_macos/Sources/file_selector_macos/FileSelectorPlugin.swift b/packages/file_selector/file_selector_macos/macos/file_selector_macos/Sources/file_selector_macos/FileSelectorPlugin.swift index c90d69d4609c..e54e91203975 100644 --- a/packages/file_selector/file_selector_macos/macos/file_selector_macos/Sources/file_selector_macos/FileSelectorPlugin.swift +++ b/packages/file_selector/file_selector_macos/macos/file_selector_macos/Sources/file_selector_macos/FileSelectorPlugin.swift @@ -64,7 +64,7 @@ public class FileSelectorPlugin: NSObject, FlutterPlugin, FileSelectorApi { } func displayOpenPanel( - options: OpenPanelOptions, completion: @escaping (Result<[String?], Error>) -> Void + options: OpenPanelOptions, completion: @escaping (Result<[String], Error>) -> Void ) { let panel = NSOpenPanel() configure(openPanel: panel, with: options) @@ -101,26 +101,22 @@ public class FileSelectorPlugin: NSObject, FlutterPlugin, FileSelectorApi { if let acceptedTypes = options.allowedFileTypes { if #available(macOS 11, *), !forceLegacyTypes { var allowedTypes: [UTType] = [] - // The array values are non-null by convention even though Pigeon can't currently express - // that via the types; see messages.dart and https://github.com/flutter/flutter/issues/97848 - allowedTypes.append(contentsOf: acceptedTypes.utis.compactMap({ UTType($0!) })) + allowedTypes.append(contentsOf: acceptedTypes.utis.compactMap({ UTType($0) })) allowedTypes.append( contentsOf: acceptedTypes.extensions.compactMap({ - UTType.init(filenameExtension: $0!) + UTType.init(filenameExtension: $0) })) allowedTypes.append( contentsOf: acceptedTypes.mimeTypes.compactMap({ - UTType.init(mimeType: $0!) + UTType.init(mimeType: $0) })) if !allowedTypes.isEmpty { panel.allowedContentTypes = allowedTypes } } else { var allowedTypes: [String] = [] - // The array values are non-null by convention even though Pigeon can't currently express - // that via the types; see messages.dart and https://github.com/flutter/flutter/issues/97848 - allowedTypes.append(contentsOf: acceptedTypes.extensions.map({ $0! })) - allowedTypes.append(contentsOf: acceptedTypes.utis.map({ $0! })) + allowedTypes.append(contentsOf: acceptedTypes.extensions.map({ $0 })) + allowedTypes.append(contentsOf: acceptedTypes.utis.map({ $0 })) if !allowedTypes.isEmpty { panel.allowedFileTypes = allowedTypes } diff --git a/packages/file_selector/file_selector_macos/macos/file_selector_macos/Sources/file_selector_macos/messages.g.swift b/packages/file_selector/file_selector_macos/macos/file_selector_macos/Sources/file_selector_macos/messages.g.swift index 7cff0d721df8..62590d1a46e2 100644 --- a/packages/file_selector/file_selector_macos/macos/file_selector_macos/Sources/file_selector_macos/messages.g.swift +++ b/packages/file_selector/file_selector_macos/macos/file_selector_macos/Sources/file_selector_macos/messages.g.swift @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v10.1.3), do not edit directly. +// Autogenerated from Pigeon (v22.4.1), do not edit directly. // See also: https://pub.dev/packages/pigeon import Foundation @@ -14,11 +14,36 @@ import Foundation #error("Unsupported platform.") #endif +/// Error class for passing custom error details to Dart side. +final class PigeonError: Error { + let code: String + let message: String? + let details: Any? + + init(code: String, message: String?, details: Any?) { + self.code = code + self.message = message + self.details = details + } + + var localizedDescription: String { + return + "PigeonError(code: \(code), message: \(message ?? ""), details: \(details ?? "")" + } +} + private func wrapResult(_ result: Any?) -> [Any?] { return [result] } private func wrapError(_ error: Any) -> [Any?] { + if let pigeonError = error as? PigeonError { + return [ + pigeonError.code, + pigeonError.message, + pigeonError.details, + ] + } if let flutterError = error as? FlutterError { return [ flutterError.code, @@ -33,6 +58,10 @@ private func wrapError(_ error: Any) -> [Any?] { ] } +private func isNullish(_ value: Any?) -> Bool { + return value is NSNull || value == nil +} + private func nilOrValue(_ value: Any?) -> T? { if value is NSNull { return nil } return value as! T? @@ -42,14 +71,15 @@ private func nilOrValue(_ value: Any?) -> T? { /// /// Generated class from Pigeon that represents data sent in messages. struct AllowedTypes { - var extensions: [String?] - var mimeTypes: [String?] - var utis: [String?] + var extensions: [String] + var mimeTypes: [String] + var utis: [String] - static func fromList(_ list: [Any?]) -> AllowedTypes? { - let extensions = list[0] as! [String?] - let mimeTypes = list[1] as! [String?] - let utis = list[2] as! [String?] + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ pigeonVar_list: [Any?]) -> AllowedTypes? { + let extensions = pigeonVar_list[0] as! [String] + let mimeTypes = pigeonVar_list[1] as! [String] + let utis = pigeonVar_list[2] as! [String] return AllowedTypes( extensions: extensions, @@ -78,14 +108,12 @@ struct SavePanelOptions { var nameFieldStringValue: String? = nil var prompt: String? = nil - static func fromList(_ list: [Any?]) -> SavePanelOptions? { - var allowedFileTypes: AllowedTypes? = nil - if let allowedFileTypesList: [Any?] = nilOrValue(list[0]) { - allowedFileTypes = AllowedTypes.fromList(allowedFileTypesList) - } - let directoryPath: String? = nilOrValue(list[1]) - let nameFieldStringValue: String? = nilOrValue(list[2]) - let prompt: String? = nilOrValue(list[3]) + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ pigeonVar_list: [Any?]) -> SavePanelOptions? { + let allowedFileTypes: AllowedTypes? = nilOrValue(pigeonVar_list[0]) + let directoryPath: String? = nilOrValue(pigeonVar_list[1]) + let nameFieldStringValue: String? = nilOrValue(pigeonVar_list[2]) + let prompt: String? = nilOrValue(pigeonVar_list[3]) return SavePanelOptions( allowedFileTypes: allowedFileTypes, @@ -96,7 +124,7 @@ struct SavePanelOptions { } func toList() -> [Any?] { return [ - allowedFileTypes?.toList(), + allowedFileTypes, directoryPath, nameFieldStringValue, prompt, @@ -115,11 +143,12 @@ struct OpenPanelOptions { var canChooseFiles: Bool var baseOptions: SavePanelOptions - static func fromList(_ list: [Any?]) -> OpenPanelOptions? { - let allowsMultipleSelection = list[0] as! Bool - let canChooseDirectories = list[1] as! Bool - let canChooseFiles = list[2] as! Bool - let baseOptions = SavePanelOptions.fromList(list[3] as! [Any?])! + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ pigeonVar_list: [Any?]) -> OpenPanelOptions? { + let allowsMultipleSelection = pigeonVar_list[0] as! Bool + let canChooseDirectories = pigeonVar_list[1] as! Bool + let canChooseFiles = pigeonVar_list[2] as! Bool + let baseOptions = pigeonVar_list[3] as! SavePanelOptions return OpenPanelOptions( allowsMultipleSelection: allowsMultipleSelection, @@ -133,55 +162,55 @@ struct OpenPanelOptions { allowsMultipleSelection, canChooseDirectories, canChooseFiles, - baseOptions.toList(), + baseOptions, ] } } -private class FileSelectorApiCodecReader: FlutterStandardReader { +private class messagesPigeonCodecReader: FlutterStandardReader { override func readValue(ofType type: UInt8) -> Any? { switch type { - case 128: - return AllowedTypes.fromList(self.readValue() as! [Any?]) case 129: - return OpenPanelOptions.fromList(self.readValue() as! [Any?]) + return AllowedTypes.fromList(self.readValue() as! [Any?]) case 130: return SavePanelOptions.fromList(self.readValue() as! [Any?]) + case 131: + return OpenPanelOptions.fromList(self.readValue() as! [Any?]) default: return super.readValue(ofType: type) } } } -private class FileSelectorApiCodecWriter: FlutterStandardWriter { +private class messagesPigeonCodecWriter: FlutterStandardWriter { override func writeValue(_ value: Any) { if let value = value as? AllowedTypes { - super.writeByte(128) - super.writeValue(value.toList()) - } else if let value = value as? OpenPanelOptions { super.writeByte(129) super.writeValue(value.toList()) } else if let value = value as? SavePanelOptions { super.writeByte(130) super.writeValue(value.toList()) + } else if let value = value as? OpenPanelOptions { + super.writeByte(131) + super.writeValue(value.toList()) } else { super.writeValue(value) } } } -private class FileSelectorApiCodecReaderWriter: FlutterStandardReaderWriter { +private class messagesPigeonCodecReaderWriter: FlutterStandardReaderWriter { override func reader(with data: Data) -> FlutterStandardReader { - return FileSelectorApiCodecReader(data: data) + return messagesPigeonCodecReader(data: data) } override func writer(with data: NSMutableData) -> FlutterStandardWriter { - return FileSelectorApiCodecWriter(data: data) + return messagesPigeonCodecWriter(data: data) } } -class FileSelectorApiCodec: FlutterStandardMessageCodec { - static let shared = FileSelectorApiCodec(readerWriter: FileSelectorApiCodecReaderWriter()) +class messagesPigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable { + static let shared = messagesPigeonCodec(readerWriter: messagesPigeonCodecReaderWriter()) } /// Generated protocol from Pigeon that represents a handler of messages from Flutter. @@ -191,7 +220,7 @@ protocol FileSelectorApi { /// /// An empty list corresponds to a cancelled selection. func displayOpenPanel( - options: OpenPanelOptions, completion: @escaping (Result<[String?], Error>) -> Void) + options: OpenPanelOptions, completion: @escaping (Result<[String], Error>) -> Void) /// Shows a save panel with the given [options], returning the selected path. /// /// A null return corresponds to a cancelled save. @@ -201,17 +230,21 @@ protocol FileSelectorApi { /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. class FileSelectorApiSetup { - /// The codec used by FileSelectorApi. - static var codec: FlutterStandardMessageCodec { FileSelectorApiCodec.shared } + static var codec: FlutterStandardMessageCodec { messagesPigeonCodec.shared } /// Sets up an instance of `FileSelectorApi` to handle messages through the `binaryMessenger`. - static func setUp(binaryMessenger: FlutterBinaryMessenger, api: FileSelectorApi?) { + static func setUp( + binaryMessenger: FlutterBinaryMessenger, api: FileSelectorApi?, + messageChannelSuffix: String = "" + ) { + let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : "" /// Shows an open panel with the given [options], returning the list of /// selected paths. /// /// An empty list corresponds to a cancelled selection. let displayOpenPanelChannel = FlutterBasicMessageChannel( - name: "dev.flutter.pigeon.FileSelectorApi.displayOpenPanel", binaryMessenger: binaryMessenger, - codec: codec) + name: + "dev.flutter.pigeon.file_selector_macos.FileSelectorApi.displayOpenPanel\(channelSuffix)", + binaryMessenger: binaryMessenger, codec: codec) if let api = api { displayOpenPanelChannel.setMessageHandler { message, reply in let args = message as! [Any?] @@ -232,8 +265,9 @@ class FileSelectorApiSetup { /// /// A null return corresponds to a cancelled save. let displaySavePanelChannel = FlutterBasicMessageChannel( - name: "dev.flutter.pigeon.FileSelectorApi.displaySavePanel", binaryMessenger: binaryMessenger, - codec: codec) + name: + "dev.flutter.pigeon.file_selector_macos.FileSelectorApi.displaySavePanel\(channelSuffix)", + binaryMessenger: binaryMessenger, codec: codec) if let api = api { displaySavePanelChannel.setMessageHandler { message, reply in let args = message as! [Any?] diff --git a/packages/file_selector/file_selector_macos/pigeons/messages.dart b/packages/file_selector/file_selector_macos/pigeons/messages.dart index 698ebcfc1002..6b80c3d29c48 100644 --- a/packages/file_selector/file_selector_macos/pigeons/messages.dart +++ b/packages/file_selector/file_selector_macos/pigeons/messages.dart @@ -20,12 +20,9 @@ class AllowedTypes { this.utis = const [], }); - // TODO(stuartmorgan): Declare these as non-nullable generics once - // https://github.com/flutter/flutter/issues/97848 is fixed. In practice, - // the values will never be null, and the native implementation assumes that. - final List extensions; - final List mimeTypes; - final List utis; + final List extensions; + final List mimeTypes; + final List utis; } /// Options for save panels. @@ -50,10 +47,10 @@ class SavePanelOptions { /// These correspond to NSOpenPanel properties. class OpenPanelOptions extends SavePanelOptions { const OpenPanelOptions({ - this.allowsMultipleSelection = false, - this.canChooseDirectories = false, - this.canChooseFiles = true, - this.baseOptions = const SavePanelOptions(), + required this.allowsMultipleSelection, + required this.canChooseDirectories, + required this.canChooseFiles, + required this.baseOptions, }); final bool allowsMultipleSelection; final bool canChooseDirectories; @@ -71,11 +68,8 @@ abstract class FileSelectorApi { /// selected paths. /// /// An empty list corresponds to a cancelled selection. - // TODO(stuartmorgan): Declare this return as a non-nullable generic once - // https://github.com/flutter/flutter/issues/97848 is fixed. In practice, - // the values will never be null, and the calling code assumes that. @async - List displayOpenPanel(OpenPanelOptions options); + List displayOpenPanel(OpenPanelOptions options); /// Shows a save panel with the given [options], returning the selected path. /// diff --git a/packages/file_selector/file_selector_macos/pubspec.yaml b/packages/file_selector/file_selector_macos/pubspec.yaml index 70beb3613b88..580eca085ee7 100644 --- a/packages/file_selector/file_selector_macos/pubspec.yaml +++ b/packages/file_selector/file_selector_macos/pubspec.yaml @@ -2,7 +2,7 @@ name: file_selector_macos description: macOS implementation of the file_selector plugin. repository: https://github.com/flutter/packages/tree/main/packages/file_selector/file_selector_macos issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+file_selector%22 -version: 0.9.4+1 +version: 0.9.4+2 environment: sdk: ^3.3.0 @@ -27,7 +27,7 @@ dev_dependencies: flutter_test: sdk: flutter mockito: ^5.4.4 - pigeon: ^10.1.3 + pigeon: ^22.4.1 topics: - files diff --git a/packages/file_selector/file_selector_macos/test/file_selector_macos_test.dart b/packages/file_selector/file_selector_macos/test/file_selector_macos_test.dart index c7268a6be891..39534230f010 100644 --- a/packages/file_selector/file_selector_macos/test/file_selector_macos_test.dart +++ b/packages/file_selector/file_selector_macos/test/file_selector_macos_test.dart @@ -22,12 +22,12 @@ void main() { setUp(() { plugin = FileSelectorMacOS(); mockApi = MockTestFileSelectorApi(); - TestFileSelectorApi.setup(mockApi); + TestFileSelectorApi.setUp(mockApi); // Set default stubs for tests that don't expect a specific return value, // so calls don't throw. Tests that `expect` return values should override // these locally. - when(mockApi.displayOpenPanel(any)).thenAnswer((_) async => []); + when(mockApi.displayOpenPanel(any)).thenAnswer((_) async => []); when(mockApi.displaySavePanel(any)).thenAnswer((_) async => null); }); @@ -39,7 +39,7 @@ void main() { group('openFile', () { test('works as expected with no arguments', () async { when(mockApi.displayOpenPanel(any)) - .thenAnswer((_) async => ['foo']); + .thenAnswer((_) async => ['foo']); final XFile? file = await plugin.openFile(); @@ -57,7 +57,7 @@ void main() { }); test('handles cancel', () async { - when(mockApi.displayOpenPanel(any)).thenAnswer((_) async => []); + when(mockApi.displayOpenPanel(any)).thenAnswer((_) async => []); final XFile? file = await plugin.openFile(); @@ -134,7 +134,7 @@ void main() { group('openFiles', () { test('works as expected with no arguments', () async { when(mockApi.displayOpenPanel(any)) - .thenAnswer((_) async => ['foo', 'bar']); + .thenAnswer((_) async => ['foo', 'bar']); final List files = await plugin.openFiles(); @@ -153,7 +153,7 @@ void main() { }); test('handles cancel', () async { - when(mockApi.displayOpenPanel(any)).thenAnswer((_) async => []); + when(mockApi.displayOpenPanel(any)).thenAnswer((_) async => []); final List files = await plugin.openFiles(); @@ -467,7 +467,7 @@ void main() { group('getDirectoryPath', () { test('works as expected with no arguments', () async { when(mockApi.displayOpenPanel(any)) - .thenAnswer((_) async => ['foo']); + .thenAnswer((_) async => ['foo']); final String? path = await plugin.getDirectoryPath(); @@ -485,7 +485,7 @@ void main() { }); test('handles cancel', () async { - when(mockApi.displayOpenPanel(any)).thenAnswer((_) async => []); + when(mockApi.displayOpenPanel(any)).thenAnswer((_) async => []); final String? path = await plugin.getDirectoryPath(); @@ -533,7 +533,7 @@ void main() { }); test('handles cancel', () async { - when(mockApi.displayOpenPanel(any)).thenAnswer((_) async => []); + when(mockApi.displayOpenPanel(any)).thenAnswer((_) async => []); final List paths = await plugin.getDirectoryPaths(); diff --git a/packages/file_selector/file_selector_macos/test/file_selector_macos_test.mocks.dart b/packages/file_selector/file_selector_macos/test/file_selector_macos_test.mocks.dart index 6743cfa138ea..63ade67d21a3 100644 --- a/packages/file_selector/file_selector_macos/test/file_selector_macos_test.mocks.dart +++ b/packages/file_selector/file_selector_macos/test/file_selector_macos_test.mocks.dart @@ -33,14 +33,14 @@ class MockTestFileSelectorApi extends _i1.Mock } @override - _i3.Future> displayOpenPanel(_i4.OpenPanelOptions? options) => + _i3.Future> displayOpenPanel(_i4.OpenPanelOptions? options) => (super.noSuchMethod( Invocation.method( #displayOpenPanel, [options], ), - returnValue: _i3.Future>.value([]), - ) as _i3.Future>); + returnValue: _i3.Future>.value([]), + ) as _i3.Future>); @override _i3.Future displaySavePanel(_i4.SavePanelOptions? options) => diff --git a/packages/file_selector/file_selector_macos/test/messages_test.g.dart b/packages/file_selector/file_selector_macos/test/messages_test.g.dart index 893161f8e811..98f1e560b9e0 100644 --- a/packages/file_selector/file_selector_macos/test/messages_test.g.dart +++ b/packages/file_selector/file_selector_macos/test/messages_test.g.dart @@ -1,9 +1,9 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v10.1.3), do not edit directly. +// Autogenerated from Pigeon (v22.4.1), do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import, no_leading_underscores_for_local_identifiers // ignore_for_file: avoid_relative_lib_imports import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; @@ -13,19 +13,22 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:file_selector_macos/src/messages.g.dart'; -class _TestFileSelectorApiCodec extends StandardMessageCodec { - const _TestFileSelectorApiCodec(); +class _PigeonCodec extends StandardMessageCodec { + const _PigeonCodec(); @override void writeValue(WriteBuffer buffer, Object? value) { - if (value is AllowedTypes) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else if (value is OpenPanelOptions) { + if (value is int) { + buffer.putUint8(4); + buffer.putInt64(value); + } else if (value is AllowedTypes) { buffer.putUint8(129); writeValue(buffer, value.encode()); } else if (value is SavePanelOptions) { buffer.putUint8(130); writeValue(buffer, value.encode()); + } else if (value is OpenPanelOptions) { + buffer.putUint8(131); + writeValue(buffer, value.encode()); } else { super.writeValue(buffer, value); } @@ -34,12 +37,12 @@ class _TestFileSelectorApiCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: - return AllowedTypes.decode(readValue(buffer)!); case 129: - return OpenPanelOptions.decode(readValue(buffer)!); + return AllowedTypes.decode(readValue(buffer)!); case 130: return SavePanelOptions.decode(readValue(buffer)!); + case 131: + return OpenPanelOptions.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); } @@ -49,62 +52,88 @@ class _TestFileSelectorApiCodec extends StandardMessageCodec { abstract class TestFileSelectorApi { static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec codec = _TestFileSelectorApiCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); /// Shows an open panel with the given [options], returning the list of /// selected paths. /// /// An empty list corresponds to a cancelled selection. - Future> displayOpenPanel(OpenPanelOptions options); + Future> displayOpenPanel(OpenPanelOptions options); /// Shows a save panel with the given [options], returning the selected path. /// /// A null return corresponds to a cancelled save. Future displaySavePanel(SavePanelOptions options); - static void setup(TestFileSelectorApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setUp( + TestFileSelectorApi? api, { + BinaryMessenger? binaryMessenger, + String messageChannelSuffix = '', + }) { + messageChannelSuffix = + messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.FileSelectorApi.displayOpenPanel', codec, + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.file_selector_macos.FileSelectorApi.displayOpenPanel$messageChannelSuffix', + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + .setMockDecodedMessageHandler(pigeonVar_channel, null); } else { _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, + .setMockDecodedMessageHandler(pigeonVar_channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.FileSelectorApi.displayOpenPanel was null.'); + 'Argument for dev.flutter.pigeon.file_selector_macos.FileSelectorApi.displayOpenPanel was null.'); final List args = (message as List?)!; final OpenPanelOptions? arg_options = (args[0] as OpenPanelOptions?); assert(arg_options != null, - 'Argument for dev.flutter.pigeon.FileSelectorApi.displayOpenPanel was null, expected non-null OpenPanelOptions.'); - final List output = await api.displayOpenPanel(arg_options!); - return [output]; + 'Argument for dev.flutter.pigeon.file_selector_macos.FileSelectorApi.displayOpenPanel was null, expected non-null OpenPanelOptions.'); + try { + final List output = + await api.displayOpenPanel(arg_options!); + return [output]; + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } }); } } { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.FileSelectorApi.displaySavePanel', codec, + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.file_selector_macos.FileSelectorApi.displaySavePanel$messageChannelSuffix', + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + .setMockDecodedMessageHandler(pigeonVar_channel, null); } else { _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, + .setMockDecodedMessageHandler(pigeonVar_channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.FileSelectorApi.displaySavePanel was null.'); + 'Argument for dev.flutter.pigeon.file_selector_macos.FileSelectorApi.displaySavePanel was null.'); final List args = (message as List?)!; final SavePanelOptions? arg_options = (args[0] as SavePanelOptions?); assert(arg_options != null, - 'Argument for dev.flutter.pigeon.FileSelectorApi.displaySavePanel was null, expected non-null SavePanelOptions.'); - final String? output = await api.displaySavePanel(arg_options!); - return [output]; + 'Argument for dev.flutter.pigeon.file_selector_macos.FileSelectorApi.displaySavePanel was null, expected non-null SavePanelOptions.'); + try { + final String? output = await api.displaySavePanel(arg_options!); + return [output]; + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } }); } } diff --git a/packages/shared_preferences/shared_preferences_foundation/CHANGELOG.md b/packages/shared_preferences/shared_preferences_foundation/CHANGELOG.md index 4fb4e5381c2d..42722fe4b182 100644 --- a/packages/shared_preferences/shared_preferences_foundation/CHANGELOG.md +++ b/packages/shared_preferences/shared_preferences_foundation/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.5.3 + +* Updates Pigeon for non-nullable collection type support. + ## 2.5.2 * Fixes getting all preferences when suite name is used. diff --git a/packages/shared_preferences/shared_preferences_foundation/darwin/shared_preferences_foundation/Sources/shared_preferences_foundation/SharedPreferencesPlugin.swift b/packages/shared_preferences/shared_preferences_foundation/darwin/shared_preferences_foundation/Sources/shared_preferences_foundation/SharedPreferencesPlugin.swift index 71602ab21e9c..5fdf2e9960f6 100644 --- a/packages/shared_preferences/shared_preferences_foundation/darwin/shared_preferences_foundation/Sources/shared_preferences_foundation/SharedPreferencesPlugin.swift +++ b/packages/shared_preferences/shared_preferences_foundation/darwin/shared_preferences_foundation/Sources/shared_preferences_foundation/SharedPreferencesPlugin.swift @@ -25,7 +25,7 @@ public class LegacySharedPreferencesPlugin: NSObject, FlutterPlugin, LegacyUserD LegacyUserDefaultsApiSetup.setUp(binaryMessenger: messenger, api: instance) } - func getAll(prefix: String, allowList: [String]?) -> [String?: Any?] { + func getAll(prefix: String, allowList: [String]?) -> [String: Any] { return getAllPrefs(prefix: prefix, allowList: allowList) } diff --git a/packages/shared_preferences/shared_preferences_foundation/darwin/shared_preferences_foundation/Sources/shared_preferences_foundation/messages.g.swift b/packages/shared_preferences/shared_preferences_foundation/darwin/shared_preferences_foundation/Sources/shared_preferences_foundation/messages.g.swift index 1c843a6522ca..275de0921d50 100644 --- a/packages/shared_preferences/shared_preferences_foundation/darwin/shared_preferences_foundation/Sources/shared_preferences_foundation/messages.g.swift +++ b/packages/shared_preferences/shared_preferences_foundation/darwin/shared_preferences_foundation/Sources/shared_preferences_foundation/messages.g.swift @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v16.0.5), do not edit directly. +// Autogenerated from Pigeon (v22.4.1), do not edit directly. // See also: https://pub.dev/packages/pigeon import Foundation @@ -14,11 +14,36 @@ import Foundation #error("Unsupported platform.") #endif +/// Error class for passing custom error details to Dart side. +final class PigeonError: Error { + let code: String + let message: String? + let details: Any? + + init(code: String, message: String?, details: Any?) { + self.code = code + self.message = message + self.details = details + } + + var localizedDescription: String { + return + "PigeonError(code: \(code), message: \(message ?? ""), details: \(details ?? "")" + } +} + private func wrapResult(_ result: Any?) -> [Any?] { return [result] } private func wrapError(_ error: Any) -> [Any?] { + if let pigeonError = error as? PigeonError { + return [ + pigeonError.code, + pigeonError.message, + pigeonError.details, + ] + } if let flutterError = error as? FlutterError { return [ flutterError.code, @@ -46,8 +71,9 @@ private func nilOrValue(_ value: Any?) -> T? { struct SharedPreferencesPigeonOptions { var suiteName: String? = nil - static func fromList(_ list: [Any?]) -> SharedPreferencesPigeonOptions? { - let suiteName: String? = nilOrValue(list[0]) + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ pigeonVar_list: [Any?]) -> SharedPreferencesPigeonOptions? { + let suiteName: String? = nilOrValue(pigeonVar_list[0]) return SharedPreferencesPigeonOptions( suiteName: suiteName @@ -59,10 +85,11 @@ struct SharedPreferencesPigeonOptions { ] } } -private class LegacyUserDefaultsApiCodecReader: FlutterStandardReader { + +private class messagesPigeonCodecReader: FlutterStandardReader { override func readValue(ofType type: UInt8) -> Any? { switch type { - case 128: + case 129: return SharedPreferencesPigeonOptions.fromList(self.readValue() as! [Any?]) default: return super.readValue(ofType: type) @@ -70,10 +97,10 @@ private class LegacyUserDefaultsApiCodecReader: FlutterStandardReader { } } -private class LegacyUserDefaultsApiCodecWriter: FlutterStandardWriter { +private class messagesPigeonCodecWriter: FlutterStandardWriter { override func writeValue(_ value: Any) { if let value = value as? SharedPreferencesPigeonOptions { - super.writeByte(128) + super.writeByte(129) super.writeValue(value.toList()) } else { super.writeValue(value) @@ -81,19 +108,18 @@ private class LegacyUserDefaultsApiCodecWriter: FlutterStandardWriter { } } -private class LegacyUserDefaultsApiCodecReaderWriter: FlutterStandardReaderWriter { +private class messagesPigeonCodecReaderWriter: FlutterStandardReaderWriter { override func reader(with data: Data) -> FlutterStandardReader { - return LegacyUserDefaultsApiCodecReader(data: data) + return messagesPigeonCodecReader(data: data) } override func writer(with data: NSMutableData) -> FlutterStandardWriter { - return LegacyUserDefaultsApiCodecWriter(data: data) + return messagesPigeonCodecWriter(data: data) } } -class LegacyUserDefaultsApiCodec: FlutterStandardMessageCodec { - static let shared = LegacyUserDefaultsApiCodec( - readerWriter: LegacyUserDefaultsApiCodecReaderWriter()) +class messagesPigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable { + static let shared = messagesPigeonCodec(readerWriter: messagesPigeonCodecReaderWriter()) } /// Generated protocol from Pigeon that represents a handler of messages from Flutter. @@ -102,18 +128,22 @@ protocol LegacyUserDefaultsApi { func setBool(key: String, value: Bool) throws func setDouble(key: String, value: Double) throws func setValue(key: String, value: Any) throws - func getAll(prefix: String, allowList: [String]?) throws -> [String?: Any?] + func getAll(prefix: String, allowList: [String]?) throws -> [String: Any] func clear(prefix: String, allowList: [String]?) throws -> Bool } /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. class LegacyUserDefaultsApiSetup { - /// The codec used by LegacyUserDefaultsApi. - static var codec: FlutterStandardMessageCodec { LegacyUserDefaultsApiCodec.shared } + static var codec: FlutterStandardMessageCodec { messagesPigeonCodec.shared } /// Sets up an instance of `LegacyUserDefaultsApi` to handle messages through the `binaryMessenger`. - static func setUp(binaryMessenger: FlutterBinaryMessenger, api: LegacyUserDefaultsApi?) { + static func setUp( + binaryMessenger: FlutterBinaryMessenger, api: LegacyUserDefaultsApi?, + messageChannelSuffix: String = "" + ) { + let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : "" let removeChannel = FlutterBasicMessageChannel( - name: "dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.remove", + name: + "dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.remove\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { removeChannel.setMessageHandler { message, reply in @@ -130,7 +160,8 @@ class LegacyUserDefaultsApiSetup { removeChannel.setMessageHandler(nil) } let setBoolChannel = FlutterBasicMessageChannel( - name: "dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.setBool", + name: + "dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.setBool\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { setBoolChannel.setMessageHandler { message, reply in @@ -148,7 +179,8 @@ class LegacyUserDefaultsApiSetup { setBoolChannel.setMessageHandler(nil) } let setDoubleChannel = FlutterBasicMessageChannel( - name: "dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.setDouble", + name: + "dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.setDouble\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { setDoubleChannel.setMessageHandler { message, reply in @@ -166,7 +198,8 @@ class LegacyUserDefaultsApiSetup { setDoubleChannel.setMessageHandler(nil) } let setValueChannel = FlutterBasicMessageChannel( - name: "dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.setValue", + name: + "dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.setValue\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { setValueChannel.setMessageHandler { message, reply in @@ -184,7 +217,8 @@ class LegacyUserDefaultsApiSetup { setValueChannel.setMessageHandler(nil) } let getAllChannel = FlutterBasicMessageChannel( - name: "dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.getAll", + name: + "dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.getAll\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { getAllChannel.setMessageHandler { message, reply in @@ -202,7 +236,8 @@ class LegacyUserDefaultsApiSetup { getAllChannel.setMessageHandler(nil) } let clearChannel = FlutterBasicMessageChannel( - name: "dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.clear", + name: + "dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.clear\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { clearChannel.setMessageHandler { message, reply in @@ -221,42 +256,6 @@ class LegacyUserDefaultsApiSetup { } } } -private class UserDefaultsApiCodecReader: FlutterStandardReader { - override func readValue(ofType type: UInt8) -> Any? { - switch type { - case 128: - return SharedPreferencesPigeonOptions.fromList(self.readValue() as! [Any?]) - default: - return super.readValue(ofType: type) - } - } -} - -private class UserDefaultsApiCodecWriter: FlutterStandardWriter { - override func writeValue(_ value: Any) { - if let value = value as? SharedPreferencesPigeonOptions { - super.writeByte(128) - super.writeValue(value.toList()) - } else { - super.writeValue(value) - } - } -} - -private class UserDefaultsApiCodecReaderWriter: FlutterStandardReaderWriter { - override func reader(with data: Data) -> FlutterStandardReader { - return UserDefaultsApiCodecReader(data: data) - } - - override func writer(with data: NSMutableData) -> FlutterStandardWriter { - return UserDefaultsApiCodecWriter(data: data) - } -} - -class UserDefaultsApiCodec: FlutterStandardMessageCodec { - static let shared = UserDefaultsApiCodec(readerWriter: UserDefaultsApiCodecReaderWriter()) -} - /// Generated protocol from Pigeon that represents a handler of messages from Flutter. protocol UserDefaultsApi { /// Adds property to shared preferences data set of type String. @@ -273,13 +272,16 @@ protocol UserDefaultsApi { /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. class UserDefaultsApiSetup { - /// The codec used by UserDefaultsApi. - static var codec: FlutterStandardMessageCodec { UserDefaultsApiCodec.shared } + static var codec: FlutterStandardMessageCodec { messagesPigeonCodec.shared } /// Sets up an instance of `UserDefaultsApi` to handle messages through the `binaryMessenger`. - static func setUp(binaryMessenger: FlutterBinaryMessenger, api: UserDefaultsApi?) { + static func setUp( + binaryMessenger: FlutterBinaryMessenger, api: UserDefaultsApi?, + messageChannelSuffix: String = "" + ) { + let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : "" /// Adds property to shared preferences data set of type String. let setChannel = FlutterBasicMessageChannel( - name: "dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.set", + name: "dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.set\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { setChannel.setMessageHandler { message, reply in @@ -299,7 +301,8 @@ class UserDefaultsApiSetup { } /// Removes all properties from shared preferences data set with matching prefix. let clearChannel = FlutterBasicMessageChannel( - name: "dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.clear", + name: + "dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.clear\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { clearChannel.setMessageHandler { message, reply in @@ -318,7 +321,8 @@ class UserDefaultsApiSetup { } /// Gets all properties from shared preferences data set with matching prefix. let getAllChannel = FlutterBasicMessageChannel( - name: "dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.getAll", + name: + "dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.getAll\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { getAllChannel.setMessageHandler { message, reply in @@ -337,7 +341,8 @@ class UserDefaultsApiSetup { } /// Gets individual value stored with [key], if any. let getValueChannel = FlutterBasicMessageChannel( - name: "dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.getValue", + name: + "dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.getValue\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { getValueChannel.setMessageHandler { message, reply in @@ -356,7 +361,8 @@ class UserDefaultsApiSetup { } /// Gets all properties from shared preferences data set with matching prefix. let getKeysChannel = FlutterBasicMessageChannel( - name: "dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.getKeys", + name: + "dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.getKeys\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { getKeysChannel.setMessageHandler { message, reply in diff --git a/packages/shared_preferences/shared_preferences_foundation/lib/src/messages.g.dart b/packages/shared_preferences/shared_preferences_foundation/lib/src/messages.g.dart index 6594deec3bb7..50d77fcdc77a 100644 --- a/packages/shared_preferences/shared_preferences_foundation/lib/src/messages.g.dart +++ b/packages/shared_preferences/shared_preferences_foundation/lib/src/messages.g.dart @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v16.0.5), do not edit directly. +// Autogenerated from Pigeon (v22.4.1), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers @@ -50,12 +50,15 @@ class SharedPreferencesPigeonOptions { } } -class _LegacyUserDefaultsApiCodec extends StandardMessageCodec { - const _LegacyUserDefaultsApiCodec(); +class _PigeonCodec extends StandardMessageCodec { + const _PigeonCodec(); @override void writeValue(WriteBuffer buffer, Object? value) { - if (value is SharedPreferencesPigeonOptions) { - buffer.putUint8(128); + if (value is int) { + buffer.putUint8(4); + buffer.putInt64(value); + } else if (value is SharedPreferencesPigeonOptions) { + buffer.putUint8(129); writeValue(buffer, value.encode()); } else { super.writeValue(buffer, value); @@ -65,7 +68,7 @@ class _LegacyUserDefaultsApiCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: + case 129: return SharedPreferencesPigeonOptions.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); @@ -77,31 +80,35 @@ class LegacyUserDefaultsApi { /// Constructor for [LegacyUserDefaultsApi]. 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. - LegacyUserDefaultsApi({BinaryMessenger? binaryMessenger}) - : __pigeon_binaryMessenger = binaryMessenger; - final BinaryMessenger? __pigeon_binaryMessenger; + LegacyUserDefaultsApi( + {BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) + : pigeonVar_binaryMessenger = binaryMessenger, + pigeonVar_messageChannelSuffix = + messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; + final BinaryMessenger? pigeonVar_binaryMessenger; - static const MessageCodec pigeonChannelCodec = - _LegacyUserDefaultsApiCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); + + final String pigeonVar_messageChannelSuffix; Future remove(String key) async { - const String __pigeon_channelName = - 'dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.remove'; - final BasicMessageChannel __pigeon_channel = + final String pigeonVar_channelName = + 'dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.remove$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([key]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = + await pigeonVar_channel.send([key]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; @@ -109,23 +116,23 @@ class LegacyUserDefaultsApi { } Future setBool(String key, bool value) async { - const String __pigeon_channelName = - 'dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.setBool'; - final BasicMessageChannel __pigeon_channel = + final String pigeonVar_channelName = + 'dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.setBool$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([key, value]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = + await pigeonVar_channel.send([key, value]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; @@ -133,23 +140,23 @@ class LegacyUserDefaultsApi { } Future setDouble(String key, double value) async { - const String __pigeon_channelName = - 'dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.setDouble'; - final BasicMessageChannel __pigeon_channel = + final String pigeonVar_channelName = + 'dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.setDouble$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([key, value]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = + await pigeonVar_channel.send([key, value]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; @@ -157,109 +164,86 @@ class LegacyUserDefaultsApi { } Future setValue(String key, Object value) async { - const String __pigeon_channelName = - 'dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.setValue'; - final BasicMessageChannel __pigeon_channel = + final String pigeonVar_channelName = + 'dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.setValue$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([key, value]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = + await pigeonVar_channel.send([key, value]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } - Future> getAll( - String prefix, List? allowList) async { - const String __pigeon_channelName = - 'dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.getAll'; - final BasicMessageChannel __pigeon_channel = + Future> getAll( + String prefix, List? allowList) async { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.getAll$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel + final List? pigeonVar_replyList = await pigeonVar_channel .send([prefix, allowList]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); - } else if (__pigeon_replyList[0] == null) { + } else if (pigeonVar_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (__pigeon_replyList[0] as Map?)! - .cast(); + return (pigeonVar_replyList[0] as Map?)! + .cast(); } } - Future clear(String prefix, List? allowList) async { - const String __pigeon_channelName = - 'dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.clear'; - final BasicMessageChannel __pigeon_channel = + Future clear(String prefix, List? allowList) async { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.clear$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel + final List? pigeonVar_replyList = await pigeonVar_channel .send([prefix, allowList]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); - } else if (__pigeon_replyList[0] == null) { + } else if (pigeonVar_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (__pigeon_replyList[0] as bool?)!; - } - } -} - -class _UserDefaultsApiCodec extends StandardMessageCodec { - const _UserDefaultsApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is SharedPreferencesPigeonOptions) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return SharedPreferencesPigeonOptions.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); + return (pigeonVar_replyList[0] as bool?)!; } } } @@ -268,33 +252,37 @@ class UserDefaultsApi { /// Constructor for [UserDefaultsApi]. 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. - UserDefaultsApi({BinaryMessenger? binaryMessenger}) - : __pigeon_binaryMessenger = binaryMessenger; - final BinaryMessenger? __pigeon_binaryMessenger; + UserDefaultsApi( + {BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) + : pigeonVar_binaryMessenger = binaryMessenger, + pigeonVar_messageChannelSuffix = + messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; + final BinaryMessenger? pigeonVar_binaryMessenger; + + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); - static const MessageCodec pigeonChannelCodec = - _UserDefaultsApiCodec(); + final String pigeonVar_messageChannelSuffix; /// Adds property to shared preferences data set of type String. Future set( String key, Object value, SharedPreferencesPigeonOptions options) async { - const String __pigeon_channelName = - 'dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.set'; - final BasicMessageChannel __pigeon_channel = + final String pigeonVar_channelName = + 'dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.set$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel + final List? pigeonVar_replyList = await pigeonVar_channel .send([key, value, options]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; @@ -303,24 +291,24 @@ class UserDefaultsApi { /// Removes all properties from shared preferences data set with matching prefix. Future clear( - List? allowList, SharedPreferencesPigeonOptions options) async { - const String __pigeon_channelName = - 'dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.clear'; - final BasicMessageChannel __pigeon_channel = + List? allowList, SharedPreferencesPigeonOptions options) async { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.clear$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel + final List? pigeonVar_replyList = await pigeonVar_channel .send([allowList, options]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; @@ -328,91 +316,91 @@ class UserDefaultsApi { } /// Gets all properties from shared preferences data set with matching prefix. - Future> getAll( - List? allowList, SharedPreferencesPigeonOptions options) async { - const String __pigeon_channelName = - 'dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.getAll'; - final BasicMessageChannel __pigeon_channel = + Future> getAll( + List? allowList, SharedPreferencesPigeonOptions options) async { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.getAll$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel + final List? pigeonVar_replyList = await pigeonVar_channel .send([allowList, options]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); - } else if (__pigeon_replyList[0] == null) { + } else if (pigeonVar_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (__pigeon_replyList[0] as Map?)! - .cast(); + return (pigeonVar_replyList[0] as Map?)! + .cast(); } } /// Gets individual value stored with [key], if any. Future getValue( String key, SharedPreferencesPigeonOptions options) async { - const String __pigeon_channelName = - 'dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.getValue'; - final BasicMessageChannel __pigeon_channel = + final String pigeonVar_channelName = + 'dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.getValue$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([key, options]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + final List? pigeonVar_replyList = + await pigeonVar_channel.send([key, options]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { - return __pigeon_replyList[0]; + return pigeonVar_replyList[0]; } } /// Gets all properties from shared preferences data set with matching prefix. - Future> getKeys( - List? allowList, SharedPreferencesPigeonOptions options) async { - const String __pigeon_channelName = - 'dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.getKeys'; - final BasicMessageChannel __pigeon_channel = + Future> getKeys( + List? allowList, SharedPreferencesPigeonOptions options) async { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.getKeys$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - __pigeon_channelName, + pigeonVar_channelName, pigeonChannelCodec, - binaryMessenger: __pigeon_binaryMessenger, + binaryMessenger: pigeonVar_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel + final List? pigeonVar_replyList = await pigeonVar_channel .send([allowList, options]) as List?; - if (__pigeon_replyList == null) { - throw _createConnectionError(__pigeon_channelName); - } else if (__pigeon_replyList.length > 1) { + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: __pigeon_replyList[0]! as String, - message: __pigeon_replyList[1] as String?, - details: __pigeon_replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); - } else if (__pigeon_replyList[0] == null) { + } else if (pigeonVar_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (__pigeon_replyList[0] as List?)!.cast(); + return (pigeonVar_replyList[0] as List?)!.cast(); } } } diff --git a/packages/shared_preferences/shared_preferences_foundation/lib/src/shared_preferences_async_foundation.dart b/packages/shared_preferences/shared_preferences_foundation/lib/src/shared_preferences_async_foundation.dart index df60e88522db..d821f1cb378c 100644 --- a/packages/shared_preferences/shared_preferences_foundation/lib/src/shared_preferences_async_foundation.dart +++ b/packages/shared_preferences/shared_preferences_foundation/lib/src/shared_preferences_async_foundation.dart @@ -47,14 +47,11 @@ base class SharedPreferencesAsyncFoundation SharedPreferencesOptions options, ) async { final PreferencesFilters filter = parameters.filter; - // TODO(tarrinneal): Remove cast once https://github.com/flutter/flutter/issues/97848 - // is fixed. In practice, the values will never be null, and the native implementation assumes that. return (await _convertKnownExceptions>( - () async => (await _api.getKeys( + () async => _api.getKeys( filter.allowList?.toList(), _convertOptionsToPigeonOptions(options), - )) - .cast()))! + )))! .toSet(); } @@ -153,8 +150,8 @@ base class SharedPreferencesAsyncFoundation String key, SharedPreferencesOptions options, ) async { - // TODO(tarrinneal): Remove cast once https://github.com/flutter/flutter/issues/97848 - // is fixed. In practice, the values will never be null, and the native implementation assumes that. + // Since `getValue` is not strongly typed, the array type won't be set + // during deserialization, and needs to be manually cast. return _convertKnownExceptions>(() async => ((await _api.getValue(key, _convertOptionsToPigeonOptions(options))) as List?) @@ -180,14 +177,11 @@ base class SharedPreferencesAsyncFoundation SharedPreferencesOptions options, ) async { final PreferencesFilters filter = parameters.filter; - final Map? data = - await _convertKnownExceptions>( - () async => _api.getAll( - filter.allowList?.toList(), - _convertOptionsToPigeonOptions(options), - )); - - return data!.cast(); + return (await _convertKnownExceptions>( + () async => _api.getAll( + filter.allowList?.toList(), + _convertOptionsToPigeonOptions(options), + )))!; } Future _convertKnownExceptions(Future Function() method) async { diff --git a/packages/shared_preferences/shared_preferences_foundation/lib/src/shared_preferences_foundation.dart b/packages/shared_preferences/shared_preferences_foundation/lib/src/shared_preferences_foundation.dart index b68b6308c74b..3fccb90e73c6 100644 --- a/packages/shared_preferences/shared_preferences_foundation/lib/src/shared_preferences_foundation.dart +++ b/packages/shared_preferences/shared_preferences_foundation/lib/src/shared_preferences_foundation.dart @@ -85,9 +85,7 @@ class SharedPreferencesFoundation extends SharedPreferencesStorePlatform { Future> getAllWithParameters( GetAllParameters parameters) async { final PreferencesFilter filter = parameters.filter; - final Map data = - await _api.getAll(filter.prefix, filter.allowList?.toList()); - return data.cast(); + return _api.getAll(filter.prefix, filter.allowList?.toList()); } @override diff --git a/packages/shared_preferences/shared_preferences_foundation/pigeons/messages.dart b/packages/shared_preferences/shared_preferences_foundation/pigeons/messages.dart index 96430e55662b..d740b1ebd0a2 100644 --- a/packages/shared_preferences/shared_preferences_foundation/pigeons/messages.dart +++ b/packages/shared_preferences/shared_preferences_foundation/pigeons/messages.dart @@ -17,9 +17,7 @@ abstract class LegacyUserDefaultsApi { void setBool(String key, bool value); void setDouble(String key, double value); void setValue(String key, Object value); - // TODO(stuartmorgan): Make these non-nullable once - // https://github.com/flutter/flutter/issues/97848 is fixed. - Map getAll(String prefix, List? allowList); + Map getAll(String prefix, List? allowList); bool clear(String prefix, List? allowList); } diff --git a/packages/shared_preferences/shared_preferences_foundation/pubspec.yaml b/packages/shared_preferences/shared_preferences_foundation/pubspec.yaml index f873bb6d8e70..50b73b1264bb 100644 --- a/packages/shared_preferences/shared_preferences_foundation/pubspec.yaml +++ b/packages/shared_preferences/shared_preferences_foundation/pubspec.yaml @@ -2,7 +2,7 @@ name: shared_preferences_foundation description: iOS and macOS implementation of the shared_preferences plugin. repository: https://github.com/flutter/packages/tree/main/packages/shared_preferences/shared_preferences_foundation issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+shared_preferences%22 -version: 2.5.2 +version: 2.5.3 environment: sdk: ^3.3.0 @@ -29,7 +29,7 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter - pigeon: ^16.0.4 + pigeon: ^22.4.1 topics: - persistence diff --git a/packages/shared_preferences/shared_preferences_foundation/test/shared_preferences_async_foundation_test.dart b/packages/shared_preferences/shared_preferences_foundation/test/shared_preferences_async_foundation_test.dart index 74278d6b344f..584e35100c8b 100644 --- a/packages/shared_preferences/shared_preferences_foundation/test/shared_preferences_async_foundation_test.dart +++ b/packages/shared_preferences/shared_preferences_foundation/test/shared_preferences_async_foundation_test.dart @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'package:flutter/src/services/binary_messenger.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:shared_preferences_foundation/shared_preferences_foundation.dart'; import 'package:shared_preferences_foundation/src/messages.g.dart'; @@ -214,7 +215,7 @@ class _FakeSharedPreferencesApi implements UserDefaultsApi { } @override - Future> getAll( + Future> getAll( List? allowList, SharedPreferencesPigeonOptions options) async { final Map filteredItems = {...items}; if (allowList != null) { @@ -224,7 +225,7 @@ class _FakeSharedPreferencesApi implements UserDefaultsApi { } @override - Future> getKeys( + Future> getKeys( List? allowList, SharedPreferencesPigeonOptions options) async { final List filteredItems = items.keys.toList(); if (allowList != null) { @@ -244,4 +245,12 @@ class _FakeSharedPreferencesApi implements UserDefaultsApi { String key, SharedPreferencesPigeonOptions options) async { return items[key]; } + + @override + // ignore: non_constant_identifier_names + BinaryMessenger? get pigeonVar_binaryMessenger => null; + + @override + // ignore: non_constant_identifier_names + String get pigeonVar_messageChannelSuffix => ''; } diff --git a/packages/shared_preferences/shared_preferences_foundation/test/shared_preferences_foundation_test.dart b/packages/shared_preferences/shared_preferences_foundation/test/shared_preferences_foundation_test.dart index f733122e7ad6..3543e69b9bc5 100644 --- a/packages/shared_preferences/shared_preferences_foundation/test/shared_preferences_foundation_test.dart +++ b/packages/shared_preferences/shared_preferences_foundation/test/shared_preferences_foundation_test.dart @@ -14,7 +14,7 @@ class _MockSharedPreferencesApi implements TestUserDefaultsApi { final Map items = {}; @override - Map getAll( + Map getAll( String prefix, List? allowList, ) { @@ -22,11 +22,11 @@ class _MockSharedPreferencesApi implements TestUserDefaultsApi { if (allowList != null) { allowSet = Set.from(allowList); } - return { - for (final String key in items.keys) - if (key.startsWith(prefix) && - (allowSet == null || allowSet.contains(key))) - key: items[key] + return { + for (final MapEntry entry in items.entries) + if (entry.key.startsWith(prefix) && + (allowSet == null || allowSet.contains(entry.key))) + entry.key: entry.value }; } @@ -98,7 +98,7 @@ void main() { setUp(() { api = _MockSharedPreferencesApi(); - TestUserDefaultsApi.setup(api); + TestUserDefaultsApi.setUp(api); }); test('registerWith', () async { diff --git a/packages/shared_preferences/shared_preferences_foundation/test/test_api.g.dart b/packages/shared_preferences/shared_preferences_foundation/test/test_api.g.dart index 25617165035c..ebeabbc6d16f 100644 --- a/packages/shared_preferences/shared_preferences_foundation/test/test_api.g.dart +++ b/packages/shared_preferences/shared_preferences_foundation/test/test_api.g.dart @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v16.0.5), do not edit directly. +// Autogenerated from Pigeon (v22.4.1), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import, no_leading_underscores_for_local_identifiers // ignore_for_file: avoid_relative_lib_imports @@ -13,12 +13,15 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:shared_preferences_foundation/src/messages.g.dart'; -class _TestUserDefaultsApiCodec extends StandardMessageCodec { - const _TestUserDefaultsApiCodec(); +class _PigeonCodec extends StandardMessageCodec { + const _PigeonCodec(); @override void writeValue(WriteBuffer buffer, Object? value) { - if (value is SharedPreferencesPigeonOptions) { - buffer.putUint8(128); + if (value is int) { + buffer.putUint8(4); + buffer.putInt64(value); + } else if (value is SharedPreferencesPigeonOptions) { + buffer.putUint8(129); writeValue(buffer, value.encode()); } else { super.writeValue(buffer, value); @@ -28,7 +31,7 @@ class _TestUserDefaultsApiCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: + case 129: return SharedPreferencesPigeonOptions.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); @@ -39,8 +42,7 @@ class _TestUserDefaultsApiCodec extends StandardMessageCodec { abstract class TestUserDefaultsApi { static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec pigeonChannelCodec = - _TestUserDefaultsApiCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); void remove(String key); @@ -50,24 +52,30 @@ abstract class TestUserDefaultsApi { void setValue(String key, Object value); - Map getAll(String prefix, List? allowList); + Map getAll(String prefix, List? allowList); - bool clear(String prefix, List? allowList); + bool clear(String prefix, List? allowList); - static void setup(TestUserDefaultsApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setUp( + TestUserDefaultsApi? api, { + BinaryMessenger? binaryMessenger, + String messageChannelSuffix = '', + }) { + messageChannelSuffix = + messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< Object?>( - 'dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.remove', + 'dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.remove$messageChannelSuffix', pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); + .setMockDecodedMessageHandler(pigeonVar_channel, null); } else { _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, + .setMockDecodedMessageHandler(pigeonVar_channel, (Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.remove was null.'); @@ -88,17 +96,18 @@ abstract class TestUserDefaultsApi { } } { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< Object?>( - 'dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.setBool', + 'dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.setBool$messageChannelSuffix', pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); + .setMockDecodedMessageHandler(pigeonVar_channel, null); } else { _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, + .setMockDecodedMessageHandler(pigeonVar_channel, (Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.setBool was null.'); @@ -122,17 +131,18 @@ abstract class TestUserDefaultsApi { } } { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< Object?>( - 'dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.setDouble', + 'dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.setDouble$messageChannelSuffix', pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); + .setMockDecodedMessageHandler(pigeonVar_channel, null); } else { _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, + .setMockDecodedMessageHandler(pigeonVar_channel, (Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.setDouble was null.'); @@ -156,17 +166,18 @@ abstract class TestUserDefaultsApi { } } { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< Object?>( - 'dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.setValue', + 'dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.setValue$messageChannelSuffix', pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); + .setMockDecodedMessageHandler(pigeonVar_channel, null); } else { _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, + .setMockDecodedMessageHandler(pigeonVar_channel, (Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.setValue was null.'); @@ -190,17 +201,18 @@ abstract class TestUserDefaultsApi { } } { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< Object?>( - 'dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.getAll', + 'dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.getAll$messageChannelSuffix', pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); + .setMockDecodedMessageHandler(pigeonVar_channel, null); } else { _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, + .setMockDecodedMessageHandler(pigeonVar_channel, (Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.getAll was null.'); @@ -208,10 +220,10 @@ abstract class TestUserDefaultsApi { final String? arg_prefix = (args[0] as String?); assert(arg_prefix != null, 'Argument for dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.getAll was null, expected non-null String.'); - final List? arg_allowList = - (args[1] as List?)?.cast(); + final List? arg_allowList = + (args[1] as List?)?.cast(); try { - final Map output = + final Map output = api.getAll(arg_prefix!, arg_allowList); return [output]; } on PlatformException catch (e) { @@ -224,17 +236,18 @@ abstract class TestUserDefaultsApi { } } { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< Object?>( - 'dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.clear', + 'dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.clear$messageChannelSuffix', pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); + .setMockDecodedMessageHandler(pigeonVar_channel, null); } else { _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, + .setMockDecodedMessageHandler(pigeonVar_channel, (Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.clear was null.'); @@ -242,8 +255,8 @@ abstract class TestUserDefaultsApi { final String? arg_prefix = (args[0] as String?); assert(arg_prefix != null, 'Argument for dev.flutter.pigeon.shared_preferences_foundation.LegacyUserDefaultsApi.clear was null, expected non-null String.'); - final List? arg_allowList = - (args[1] as List?)?.cast(); + final List? arg_allowList = + (args[1] as List?)?.cast(); try { final bool output = api.clear(arg_prefix!, arg_allowList); return [output]; @@ -259,66 +272,48 @@ abstract class TestUserDefaultsApi { } } -class _TestSharedPreferencesAsyncApiCodec extends StandardMessageCodec { - const _TestSharedPreferencesAsyncApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is SharedPreferencesPigeonOptions) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return SharedPreferencesPigeonOptions.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - abstract class TestSharedPreferencesAsyncApi { static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec pigeonChannelCodec = - _TestSharedPreferencesAsyncApiCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); /// Adds property to shared preferences data set of type String. void set(String key, Object value, SharedPreferencesPigeonOptions options); /// Removes all properties from shared preferences data set with matching prefix. - void clear(List? allowList, SharedPreferencesPigeonOptions options); + void clear(List? allowList, SharedPreferencesPigeonOptions options); /// Gets all properties from shared preferences data set with matching prefix. - Map getAll( - List? allowList, SharedPreferencesPigeonOptions options); + Map getAll( + List? allowList, SharedPreferencesPigeonOptions options); /// Gets individual value stored with [key], if any. Object? getValue(String key, SharedPreferencesPigeonOptions options); /// Gets all properties from shared preferences data set with matching prefix. - List getKeys( - List? allowList, SharedPreferencesPigeonOptions options); + List getKeys( + List? allowList, SharedPreferencesPigeonOptions options); - static void setup(TestSharedPreferencesAsyncApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setUp( + TestSharedPreferencesAsyncApi? api, { + BinaryMessenger? binaryMessenger, + String messageChannelSuffix = '', + }) { + messageChannelSuffix = + messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< Object?>( - 'dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.set', + 'dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.set$messageChannelSuffix', pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); + .setMockDecodedMessageHandler(pigeonVar_channel, null); } else { _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, + .setMockDecodedMessageHandler(pigeonVar_channel, (Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.set was null.'); @@ -346,23 +341,24 @@ abstract class TestSharedPreferencesAsyncApi { } } { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< Object?>( - 'dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.clear', + 'dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.clear$messageChannelSuffix', pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); + .setMockDecodedMessageHandler(pigeonVar_channel, null); } else { _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, + .setMockDecodedMessageHandler(pigeonVar_channel, (Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.clear was null.'); final List args = (message as List?)!; - final List? arg_allowList = - (args[0] as List?)?.cast(); + final List? arg_allowList = + (args[0] as List?)?.cast(); final SharedPreferencesPigeonOptions? arg_options = (args[1] as SharedPreferencesPigeonOptions?); assert(arg_options != null, @@ -380,29 +376,30 @@ abstract class TestSharedPreferencesAsyncApi { } } { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< Object?>( - 'dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.getAll', + 'dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.getAll$messageChannelSuffix', pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); + .setMockDecodedMessageHandler(pigeonVar_channel, null); } else { _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, + .setMockDecodedMessageHandler(pigeonVar_channel, (Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.getAll was null.'); final List args = (message as List?)!; - final List? arg_allowList = - (args[0] as List?)?.cast(); + final List? arg_allowList = + (args[0] as List?)?.cast(); final SharedPreferencesPigeonOptions? arg_options = (args[1] as SharedPreferencesPigeonOptions?); assert(arg_options != null, 'Argument for dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.getAll was null, expected non-null SharedPreferencesPigeonOptions.'); try { - final Map output = + final Map output = api.getAll(arg_allowList, arg_options!); return [output]; } on PlatformException catch (e) { @@ -415,17 +412,18 @@ abstract class TestSharedPreferencesAsyncApi { } } { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< Object?>( - 'dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.getValue', + 'dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.getValue$messageChannelSuffix', pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); + .setMockDecodedMessageHandler(pigeonVar_channel, null); } else { _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, + .setMockDecodedMessageHandler(pigeonVar_channel, (Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.getValue was null.'); @@ -450,29 +448,30 @@ abstract class TestSharedPreferencesAsyncApi { } } { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< Object?>( - 'dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.getKeys', + 'dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.getKeys$messageChannelSuffix', pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); + .setMockDecodedMessageHandler(pigeonVar_channel, null); } else { _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, + .setMockDecodedMessageHandler(pigeonVar_channel, (Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.getKeys was null.'); final List args = (message as List?)!; - final List? arg_allowList = - (args[0] as List?)?.cast(); + final List? arg_allowList = + (args[0] as List?)?.cast(); final SharedPreferencesPigeonOptions? arg_options = (args[1] as SharedPreferencesPigeonOptions?); assert(arg_options != null, 'Argument for dev.flutter.pigeon.shared_preferences_foundation.UserDefaultsApi.getKeys was null, expected non-null SharedPreferencesPigeonOptions.'); try { - final List output = + final List output = api.getKeys(arg_allowList, arg_options!); return [output]; } on PlatformException catch (e) {