Skip to content

Commit 05bf1d4

Browse files
[various] Update Swift plugins for non-nullable generics (flutter#7742)
Updates Swift-based plugins to the current version of Pigeon: - Removes workarounds for previous lack of support for non-nullable generics. - Minor tweaks for other Pigeon changes in intervening versions. These are done as a batch since the Swift plugins are unusual among our plugins in having strong typing changes on the native side, making them easier to do mechanically. Part of flutter/flutter#155891
1 parent 6dd7f6b commit 05bf1d4

File tree

29 files changed

+732
-652
lines changed

29 files changed

+732
-652
lines changed

packages/file_selector/file_selector_ios/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
## NEXT
1+
## 0.5.3+1
22

3+
* Updates Pigeon for non-nullable collection type support.
34
* Updates minimum supported SDK version to Flutter 3.19/Dart 3.3.
45

56
## 0.5.3

packages/file_selector/file_selector_ios/ios/file_selector_ios/Sources/file_selector_ios/FileSelectorPlugin.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ public class FileSelectorPlugin: NSObject, FlutterPlugin, FileSelectorApi {
5959
let documentPicker =
6060
documentPickerViewControllerOverride
6161
?? UIDocumentPickerViewController(
62-
// See comment in messages.dart for why this is safe.
63-
documentTypes: config.utis as! [String],
62+
documentTypes: config.utis,
6463
in: .import)
6564
documentPicker.allowsMultipleSelection = config.allowMultiSelection
6665
documentPicker.delegate = completionBridge

packages/file_selector/file_selector_ios/ios/file_selector_ios/Sources/file_selector_ios/messages.g.swift

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2013 The Flutter Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
// Autogenerated from Pigeon (v19.0.0), do not edit directly.
4+
// Autogenerated from Pigeon (v22.4.1), do not edit directly.
55
// See also: https://pub.dev/packages/pigeon
66

77
import Foundation
@@ -69,13 +69,13 @@ private func nilOrValue<T>(_ value: Any?) -> T? {
6969

7070
/// Generated class from Pigeon that represents data sent in messages.
7171
struct FileSelectorConfig {
72-
var utis: [String?]
72+
var utis: [String]
7373
var allowMultiSelection: Bool
7474

7575
// swift-format-ignore: AlwaysUseLowerCamelCase
76-
static func fromList(_ __pigeon_list: [Any?]) -> FileSelectorConfig? {
77-
let utis = __pigeon_list[0] as! [String?]
78-
let allowMultiSelection = __pigeon_list[1] as! Bool
76+
static func fromList(_ pigeonVar_list: [Any?]) -> FileSelectorConfig? {
77+
let utis = pigeonVar_list[0] as! [String]
78+
let allowMultiSelection = pigeonVar_list[1] as! Bool
7979

8080
return FileSelectorConfig(
8181
utis: utis,
@@ -90,40 +90,40 @@ struct FileSelectorConfig {
9090
}
9191
}
9292

93-
private class FileSelectorApiCodecReader: FlutterStandardReader {
93+
private class messagesPigeonCodecReader: FlutterStandardReader {
9494
override func readValue(ofType type: UInt8) -> Any? {
9595
switch type {
96-
case 128:
96+
case 129:
9797
return FileSelectorConfig.fromList(self.readValue() as! [Any?])
9898
default:
9999
return super.readValue(ofType: type)
100100
}
101101
}
102102
}
103103

104-
private class FileSelectorApiCodecWriter: FlutterStandardWriter {
104+
private class messagesPigeonCodecWriter: FlutterStandardWriter {
105105
override func writeValue(_ value: Any) {
106106
if let value = value as? FileSelectorConfig {
107-
super.writeByte(128)
107+
super.writeByte(129)
108108
super.writeValue(value.toList())
109109
} else {
110110
super.writeValue(value)
111111
}
112112
}
113113
}
114114

115-
private class FileSelectorApiCodecReaderWriter: FlutterStandardReaderWriter {
115+
private class messagesPigeonCodecReaderWriter: FlutterStandardReaderWriter {
116116
override func reader(with data: Data) -> FlutterStandardReader {
117-
return FileSelectorApiCodecReader(data: data)
117+
return messagesPigeonCodecReader(data: data)
118118
}
119119

120120
override func writer(with data: NSMutableData) -> FlutterStandardWriter {
121-
return FileSelectorApiCodecWriter(data: data)
121+
return messagesPigeonCodecWriter(data: data)
122122
}
123123
}
124124

125-
class FileSelectorApiCodec: FlutterStandardMessageCodec {
126-
static let shared = FileSelectorApiCodec(readerWriter: FileSelectorApiCodecReaderWriter())
125+
class messagesPigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable {
126+
static let shared = messagesPigeonCodec(readerWriter: messagesPigeonCodecReaderWriter())
127127
}
128128

129129
/// Generated protocol from Pigeon that represents a handler of messages from Flutter.
@@ -133,8 +133,7 @@ protocol FileSelectorApi {
133133

134134
/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`.
135135
class FileSelectorApiSetup {
136-
/// The codec used by FileSelectorApi.
137-
static var codec: FlutterStandardMessageCodec { FileSelectorApiCodec.shared }
136+
static var codec: FlutterStandardMessageCodec { messagesPigeonCodec.shared }
138137
/// Sets up an instance of `FileSelectorApi` to handle messages through the `binaryMessenger`.
139138
static func setUp(
140139
binaryMessenger: FlutterBinaryMessenger, api: FileSelectorApi?,

packages/file_selector/file_selector_ios/lib/file_selector_ios.dart

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ class FileSelectorIOS extends FileSelectorPlatform {
2121
String? initialDirectory,
2222
String? confirmButtonText,
2323
}) async {
24-
final List<String> path = (await _hostApi.openFile(FileSelectorConfig(
25-
utis: _allowedUtiListFromTypeGroups(acceptedTypeGroups))))
26-
.cast<String>();
24+
final List<String> path = await _hostApi.openFile(FileSelectorConfig(
25+
utis: _allowedUtiListFromTypeGroups(acceptedTypeGroups)));
2726
return path.isEmpty ? null : XFile(path.first);
2827
}
2928

@@ -33,10 +32,9 @@ class FileSelectorIOS extends FileSelectorPlatform {
3332
String? initialDirectory,
3433
String? confirmButtonText,
3534
}) async {
36-
final List<String> pathList = (await _hostApi.openFile(FileSelectorConfig(
37-
utis: _allowedUtiListFromTypeGroups(acceptedTypeGroups),
38-
allowMultiSelection: true)))
39-
.cast<String>();
35+
final List<String> pathList = await _hostApi.openFile(FileSelectorConfig(
36+
utis: _allowedUtiListFromTypeGroups(acceptedTypeGroups),
37+
allowMultiSelection: true));
4038
return pathList.map((String path) => XFile(path)).toList();
4139
}
4240

packages/file_selector/file_selector_ios/lib/src/messages.g.dart

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2013 The Flutter Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
// Autogenerated from Pigeon (v19.0.0), do not edit directly.
4+
// Autogenerated from Pigeon (v22.4.1), do not edit directly.
55
// See also: https://pub.dev/packages/pigeon
66
// 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
77

@@ -31,11 +31,11 @@ List<Object?> wrapResponse(
3131

3232
class FileSelectorConfig {
3333
FileSelectorConfig({
34-
this.utis = const <String?>[],
34+
this.utis = const <String>[],
3535
this.allowMultiSelection = false,
3636
});
3737

38-
List<String?> utis;
38+
List<String> utis;
3939

4040
bool allowMultiSelection;
4141

@@ -49,18 +49,21 @@ class FileSelectorConfig {
4949
static FileSelectorConfig decode(Object result) {
5050
result as List<Object?>;
5151
return FileSelectorConfig(
52-
utis: (result[0] as List<Object?>?)!.cast<String?>(),
52+
utis: (result[0] as List<Object?>?)!.cast<String>(),
5353
allowMultiSelection: result[1]! as bool,
5454
);
5555
}
5656
}
5757

58-
class _FileSelectorApiCodec extends StandardMessageCodec {
59-
const _FileSelectorApiCodec();
58+
class _PigeonCodec extends StandardMessageCodec {
59+
const _PigeonCodec();
6060
@override
6161
void writeValue(WriteBuffer buffer, Object? value) {
62-
if (value is FileSelectorConfig) {
63-
buffer.putUint8(128);
62+
if (value is int) {
63+
buffer.putUint8(4);
64+
buffer.putInt64(value);
65+
} else if (value is FileSelectorConfig) {
66+
buffer.putUint8(129);
6467
writeValue(buffer, value.encode());
6568
} else {
6669
super.writeValue(buffer, value);
@@ -70,7 +73,7 @@ class _FileSelectorApiCodec extends StandardMessageCodec {
7073
@override
7174
Object? readValueOfType(int type, ReadBuffer buffer) {
7275
switch (type) {
73-
case 128:
76+
case 129:
7477
return FileSelectorConfig.decode(readValue(buffer)!);
7578
default:
7679
return super.readValueOfType(type, buffer);
@@ -84,42 +87,41 @@ class FileSelectorApi {
8487
/// BinaryMessenger will be used which routes to the host platform.
8588
FileSelectorApi(
8689
{BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''})
87-
: __pigeon_binaryMessenger = binaryMessenger,
88-
__pigeon_messageChannelSuffix =
90+
: pigeonVar_binaryMessenger = binaryMessenger,
91+
pigeonVar_messageChannelSuffix =
8992
messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : '';
90-
final BinaryMessenger? __pigeon_binaryMessenger;
93+
final BinaryMessenger? pigeonVar_binaryMessenger;
9194

92-
static const MessageCodec<Object?> pigeonChannelCodec =
93-
_FileSelectorApiCodec();
95+
static const MessageCodec<Object?> pigeonChannelCodec = _PigeonCodec();
9496

95-
final String __pigeon_messageChannelSuffix;
97+
final String pigeonVar_messageChannelSuffix;
9698

97-
Future<List<String?>> openFile(FileSelectorConfig config) async {
98-
final String __pigeon_channelName =
99-
'dev.flutter.pigeon.file_selector_ios.FileSelectorApi.openFile$__pigeon_messageChannelSuffix';
100-
final BasicMessageChannel<Object?> __pigeon_channel =
99+
Future<List<String>> openFile(FileSelectorConfig config) async {
100+
final String pigeonVar_channelName =
101+
'dev.flutter.pigeon.file_selector_ios.FileSelectorApi.openFile$pigeonVar_messageChannelSuffix';
102+
final BasicMessageChannel<Object?> pigeonVar_channel =
101103
BasicMessageChannel<Object?>(
102-
__pigeon_channelName,
104+
pigeonVar_channelName,
103105
pigeonChannelCodec,
104-
binaryMessenger: __pigeon_binaryMessenger,
106+
binaryMessenger: pigeonVar_binaryMessenger,
105107
);
106-
final List<Object?>? __pigeon_replyList =
107-
await __pigeon_channel.send(<Object?>[config]) as List<Object?>?;
108-
if (__pigeon_replyList == null) {
109-
throw _createConnectionError(__pigeon_channelName);
110-
} else if (__pigeon_replyList.length > 1) {
108+
final List<Object?>? pigeonVar_replyList =
109+
await pigeonVar_channel.send(<Object?>[config]) as List<Object?>?;
110+
if (pigeonVar_replyList == null) {
111+
throw _createConnectionError(pigeonVar_channelName);
112+
} else if (pigeonVar_replyList.length > 1) {
111113
throw PlatformException(
112-
code: __pigeon_replyList[0]! as String,
113-
message: __pigeon_replyList[1] as String?,
114-
details: __pigeon_replyList[2],
114+
code: pigeonVar_replyList[0]! as String,
115+
message: pigeonVar_replyList[1] as String?,
116+
details: pigeonVar_replyList[2],
115117
);
116-
} else if (__pigeon_replyList[0] == null) {
118+
} else if (pigeonVar_replyList[0] == null) {
117119
throw PlatformException(
118120
code: 'null-error',
119121
message: 'Host platform returned null value for non-null return value.',
120122
);
121123
} else {
122-
return (__pigeon_replyList[0] as List<Object?>?)!.cast<String?>();
124+
return (pigeonVar_replyList[0] as List<Object?>?)!.cast<String>();
123125
}
124126
}
125127
}

packages/file_selector/file_selector_ios/pigeons/messages.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@ import 'package:pigeon/pigeon.dart';
1212
))
1313
class FileSelectorConfig {
1414
FileSelectorConfig(
15-
{this.utis = const <String?>[], this.allowMultiSelection = false});
16-
// TODO(stuartmorgan): Declare these as non-nullable generics once
17-
// https://github.com/flutter/flutter/issues/97848 is fixed. In practice,
18-
// the values will never be null, and the native implementation assumes that.
19-
List<String?> utis;
15+
{this.utis = const <String>[], this.allowMultiSelection = false});
16+
List<String> utis;
2017
bool allowMultiSelection;
2118
}
2219

packages/file_selector/file_selector_ios/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: file_selector_ios
22
description: iOS implementation of the file_selector plugin.
33
repository: https://github.com/flutter/packages/tree/main/packages/file_selector/file_selector_ios
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+file_selector%22
5-
version: 0.5.3
5+
version: 0.5.3+1
66

77
environment:
88
sdk: ^3.3.0
@@ -26,7 +26,7 @@ dev_dependencies:
2626
flutter_test:
2727
sdk: flutter
2828
mockito: ^5.4.4
29-
pigeon: ^19.0.0
29+
pigeon: ^22.4.1
3030

3131
topics:
3232
- files

packages/file_selector/file_selector_ios/test/file_selector_ios_test.mocks.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ class MockTestFileSelectorApi extends _i1.Mock
3333
}
3434

3535
@override
36-
_i3.Future<List<String?>> openFile(_i4.FileSelectorConfig? config) =>
36+
_i3.Future<List<String>> openFile(_i4.FileSelectorConfig? config) =>
3737
(super.noSuchMethod(
3838
Invocation.method(
3939
#openFile,
4040
[config],
4141
),
42-
returnValue: _i3.Future<List<String?>>.value(<String?>[]),
43-
) as _i3.Future<List<String?>>);
42+
returnValue: _i3.Future<List<String>>.value(<String>[]),
43+
) as _i3.Future<List<String>>);
4444
}

packages/file_selector/file_selector_ios/test/test_api.g.dart

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2013 The Flutter Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
// Autogenerated from Pigeon (v19.0.0), do not edit directly.
4+
// Autogenerated from Pigeon (v22.4.1), do not edit directly.
55
// See also: https://pub.dev/packages/pigeon
66
// 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
77
// ignore_for_file: avoid_relative_lib_imports
@@ -13,12 +13,15 @@ import 'package:flutter_test/flutter_test.dart';
1313

1414
import 'package:file_selector_ios/src/messages.g.dart';
1515

16-
class _TestFileSelectorApiCodec extends StandardMessageCodec {
17-
const _TestFileSelectorApiCodec();
16+
class _PigeonCodec extends StandardMessageCodec {
17+
const _PigeonCodec();
1818
@override
1919
void writeValue(WriteBuffer buffer, Object? value) {
20-
if (value is FileSelectorConfig) {
21-
buffer.putUint8(128);
20+
if (value is int) {
21+
buffer.putUint8(4);
22+
buffer.putInt64(value);
23+
} else if (value is FileSelectorConfig) {
24+
buffer.putUint8(129);
2225
writeValue(buffer, value.encode());
2326
} else {
2427
super.writeValue(buffer, value);
@@ -28,7 +31,7 @@ class _TestFileSelectorApiCodec extends StandardMessageCodec {
2831
@override
2932
Object? readValueOfType(int type, ReadBuffer buffer) {
3033
switch (type) {
31-
case 128:
34+
case 129:
3235
return FileSelectorConfig.decode(readValue(buffer)!);
3336
default:
3437
return super.readValueOfType(type, buffer);
@@ -39,10 +42,9 @@ class _TestFileSelectorApiCodec extends StandardMessageCodec {
3942
abstract class TestFileSelectorApi {
4043
static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding =>
4144
TestDefaultBinaryMessengerBinding.instance;
42-
static const MessageCodec<Object?> pigeonChannelCodec =
43-
_TestFileSelectorApiCodec();
45+
static const MessageCodec<Object?> pigeonChannelCodec = _PigeonCodec();
4446

45-
Future<List<String?>> openFile(FileSelectorConfig config);
47+
Future<List<String>> openFile(FileSelectorConfig config);
4648

4749
static void setUp(
4850
TestFileSelectorApi? api, {
@@ -52,17 +54,18 @@ abstract class TestFileSelectorApi {
5254
messageChannelSuffix =
5355
messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : '';
5456
{
55-
final BasicMessageChannel<Object?> __pigeon_channel = BasicMessageChannel<
57+
final BasicMessageChannel<
58+
Object?> pigeonVar_channel = BasicMessageChannel<
5659
Object?>(
5760
'dev.flutter.pigeon.file_selector_ios.FileSelectorApi.openFile$messageChannelSuffix',
5861
pigeonChannelCodec,
5962
binaryMessenger: binaryMessenger);
6063
if (api == null) {
6164
_testBinaryMessengerBinding!.defaultBinaryMessenger
62-
.setMockDecodedMessageHandler<Object?>(__pigeon_channel, null);
65+
.setMockDecodedMessageHandler<Object?>(pigeonVar_channel, null);
6366
} else {
6467
_testBinaryMessengerBinding!.defaultBinaryMessenger
65-
.setMockDecodedMessageHandler<Object?>(__pigeon_channel,
68+
.setMockDecodedMessageHandler<Object?>(pigeonVar_channel,
6669
(Object? message) async {
6770
assert(message != null,
6871
'Argument for dev.flutter.pigeon.file_selector_ios.FileSelectorApi.openFile was null.');
@@ -72,7 +75,7 @@ abstract class TestFileSelectorApi {
7275
assert(arg_config != null,
7376
'Argument for dev.flutter.pigeon.file_selector_ios.FileSelectorApi.openFile was null, expected non-null FileSelectorConfig.');
7477
try {
75-
final List<String?> output = await api.openFile(arg_config!);
78+
final List<String> output = await api.openFile(arg_config!);
7679
return <Object?>[output];
7780
} on PlatformException catch (e) {
7881
return wrapResponse(error: e);

packages/file_selector/file_selector_macos/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.9.4+2
2+
3+
* Updates Pigeon for non-nullable collection type support.
4+
15
## 0.9.4+1
26

37
* Adds privacy manifest.

0 commit comments

Comments
 (0)