Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[various] Update Swift plugins for non-nullable generics #7742

Merged
merged 7 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/file_selector/file_selector_ios/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -69,13 +69,13 @@ private func nilOrValue<T>(_ 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,
Expand All @@ -90,40 +90,40 @@ 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)
}
}
}

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)
}
}
}

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.
Expand All @@ -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?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ class FileSelectorIOS extends FileSelectorPlatform {
String? initialDirectory,
String? confirmButtonText,
}) async {
final List<String> path = (await _hostApi.openFile(FileSelectorConfig(
utis: _allowedUtiListFromTypeGroups(acceptedTypeGroups))))
.cast<String>();
final List<String> path = await _hostApi.openFile(FileSelectorConfig(
utis: _allowedUtiListFromTypeGroups(acceptedTypeGroups)));
return path.isEmpty ? null : XFile(path.first);
}

Expand All @@ -33,10 +32,9 @@ class FileSelectorIOS extends FileSelectorPlatform {
String? initialDirectory,
String? confirmButtonText,
}) async {
final List<String> pathList = (await _hostApi.openFile(FileSelectorConfig(
utis: _allowedUtiListFromTypeGroups(acceptedTypeGroups),
allowMultiSelection: true)))
.cast<String>();
final List<String> pathList = await _hostApi.openFile(FileSelectorConfig(
utis: _allowedUtiListFromTypeGroups(acceptedTypeGroups),
allowMultiSelection: true));
return pathList.map((String path) => XFile(path)).toList();
}

Expand Down
64 changes: 33 additions & 31 deletions packages/file_selector/file_selector_ios/lib/src/messages.g.dart
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -31,11 +31,11 @@ List<Object?> wrapResponse(

class FileSelectorConfig {
FileSelectorConfig({
this.utis = const <String?>[],
this.utis = const <String>[],
this.allowMultiSelection = false,
});

List<String?> utis;
List<String> utis;

bool allowMultiSelection;

Expand All @@ -49,18 +49,21 @@ class FileSelectorConfig {
static FileSelectorConfig decode(Object result) {
result as List<Object?>;
return FileSelectorConfig(
utis: (result[0] as List<Object?>?)!.cast<String?>(),
utis: (result[0] as List<Object?>?)!.cast<String>(),
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);
Expand All @@ -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);
Expand All @@ -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<Object?> pigeonChannelCodec =
_FileSelectorApiCodec();
static const MessageCodec<Object?> pigeonChannelCodec = _PigeonCodec();

final String __pigeon_messageChannelSuffix;
final String pigeonVar_messageChannelSuffix;

Future<List<String?>> openFile(FileSelectorConfig config) async {
final String __pigeon_channelName =
'dev.flutter.pigeon.file_selector_ios.FileSelectorApi.openFile$__pigeon_messageChannelSuffix';
final BasicMessageChannel<Object?> __pigeon_channel =
Future<List<String>> openFile(FileSelectorConfig config) async {
final String pigeonVar_channelName =
'dev.flutter.pigeon.file_selector_ios.FileSelectorApi.openFile$pigeonVar_messageChannelSuffix';
final BasicMessageChannel<Object?> pigeonVar_channel =
BasicMessageChannel<Object?>(
__pigeon_channelName,
pigeonVar_channelName,
pigeonChannelCodec,
binaryMessenger: __pigeon_binaryMessenger,
binaryMessenger: pigeonVar_binaryMessenger,
);
final List<Object?>? __pigeon_replyList =
await __pigeon_channel.send(<Object?>[config]) as List<Object?>?;
if (__pigeon_replyList == null) {
throw _createConnectionError(__pigeon_channelName);
} else if (__pigeon_replyList.length > 1) {
final List<Object?>? pigeonVar_replyList =
await pigeonVar_channel.send(<Object?>[config]) as List<Object?>?;
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<Object?>?)!.cast<String?>();
return (pigeonVar_replyList[0] as List<Object?>?)!.cast<String>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ import 'package:pigeon/pigeon.dart';
))
class FileSelectorConfig {
FileSelectorConfig(
{this.utis = const <String?>[], 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<String?> utis;
{this.utis = const <String>[], this.allowMultiSelection = false});
List<String> utis;
bool allowMultiSelection;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/file_selector/file_selector_ios/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,7 +26,7 @@ dev_dependencies:
flutter_test:
sdk: flutter
mockito: ^5.4.4
pigeon: ^19.0.0
pigeon: ^22.4.1

topics:
- files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ class MockTestFileSelectorApi extends _i1.Mock
}

@override
_i3.Future<List<String?>> openFile(_i4.FileSelectorConfig? config) =>
_i3.Future<List<String>> openFile(_i4.FileSelectorConfig? config) =>
(super.noSuchMethod(
Invocation.method(
#openFile,
[config],
),
returnValue: _i3.Future<List<String?>>.value(<String?>[]),
) as _i3.Future<List<String?>>);
returnValue: _i3.Future<List<String>>.value(<String>[]),
) as _i3.Future<List<String>>);
}
29 changes: 16 additions & 13 deletions packages/file_selector/file_selector_ios/test/test_api.g.dart
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -39,10 +42,9 @@ class _TestFileSelectorApiCodec extends StandardMessageCodec {
abstract class TestFileSelectorApi {
static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding =>
TestDefaultBinaryMessengerBinding.instance;
static const MessageCodec<Object?> pigeonChannelCodec =
_TestFileSelectorApiCodec();
static const MessageCodec<Object?> pigeonChannelCodec = _PigeonCodec();

Future<List<String?>> openFile(FileSelectorConfig config);
Future<List<String>> openFile(FileSelectorConfig config);

static void setUp(
TestFileSelectorApi? api, {
Expand All @@ -52,17 +54,18 @@ abstract class TestFileSelectorApi {
messageChannelSuffix =
messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : '';
{
final BasicMessageChannel<Object?> __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<Object?>(__pigeon_channel, null);
.setMockDecodedMessageHandler<Object?>(pigeonVar_channel, null);
} else {
_testBinaryMessengerBinding!.defaultBinaryMessenger
.setMockDecodedMessageHandler<Object?>(__pigeon_channel,
.setMockDecodedMessageHandler<Object?>(pigeonVar_channel,
(Object? message) async {
assert(message != null,
'Argument for dev.flutter.pigeon.file_selector_ios.FileSelectorApi.openFile was null.');
Expand All @@ -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<String?> output = await api.openFile(arg_config!);
final List<String> output = await api.openFile(arg_config!);
return <Object?>[output];
} on PlatformException catch (e) {
return wrapResponse(error: e);
Expand Down
4 changes: 4 additions & 0 deletions packages/file_selector/file_selector_macos/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.9.4+2

* Updates Pigeon for non-nullable collection type support.

## 0.9.4+1

* Adds privacy manifest.
Expand Down
Loading