Skip to content

Commit a3f1692

Browse files
[file_selector] Update Windows Pigeon for non-nullable generics (#7730)
Updates `file_selector_windows` to the latest version of Pigeon, picking up support for non-nullable generics, and updates the code accordingly. This doesn't affect any manually written native code because the C++ generator doesn't generate strongly type collections, but does make the Dart code simpler, and strongly enforces non-nullability for values coming *from* Dart. Part of flutter/flutter#155891
1 parent 925205d commit a3f1692

File tree

9 files changed

+96
-94
lines changed

9 files changed

+96
-94
lines changed

packages/file_selector/file_selector_windows/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
## NEXT
1+
## 0.9.3+3
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.9.3+2

packages/file_selector/file_selector_windows/lib/file_selector_windows.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class FileSelectorWindows extends FileSelectorPlatform {
2727
),
2828
initialDirectory,
2929
confirmButtonText);
30-
return result.paths.isEmpty ? null : XFile(result.paths.first!);
30+
return result.paths.isEmpty ? null : XFile(result.paths.first);
3131
}
3232

3333
@override
@@ -78,7 +78,7 @@ class FileSelectorWindows extends FileSelectorPlatform {
7878
final int? groupIndex = result.typeGroupIndex;
7979
return result.paths.isEmpty
8080
? null
81-
: FileSaveLocation(result.paths.first!,
81+
: FileSaveLocation(result.paths.first,
8282
activeFilter:
8383
groupIndex == null ? null : acceptedTypeGroups?[groupIndex]);
8484
}
@@ -95,7 +95,7 @@ class FileSelectorWindows extends FileSelectorPlatform {
9595
),
9696
initialDirectory,
9797
confirmButtonText);
98-
return result.paths.isEmpty ? null : result.paths.first!;
98+
return result.paths.isEmpty ? null : result.paths.first;
9999
}
100100

101101
@override

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

Lines changed: 44 additions & 41 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 (v21.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

@@ -37,7 +37,7 @@ class TypeGroup {
3737

3838
String label;
3939

40-
List<String?> extensions;
40+
List<String> extensions;
4141

4242
Object encode() {
4343
return <Object?>[
@@ -50,7 +50,7 @@ class TypeGroup {
5050
result as List<Object?>;
5151
return TypeGroup(
5252
label: result[0]! as String,
53-
extensions: (result[1] as List<Object?>?)!.cast<String?>(),
53+
extensions: (result[1] as List<Object?>?)!.cast<String>(),
5454
);
5555
}
5656
}
@@ -59,14 +59,14 @@ class SelectionOptions {
5959
SelectionOptions({
6060
this.allowMultiple = false,
6161
this.selectFolders = false,
62-
this.allowedTypes = const <TypeGroup?>[],
62+
this.allowedTypes = const <TypeGroup>[],
6363
});
6464

6565
bool allowMultiple;
6666

6767
bool selectFolders;
6868

69-
List<TypeGroup?> allowedTypes;
69+
List<TypeGroup> allowedTypes;
7070

7171
Object encode() {
7272
return <Object?>[
@@ -81,7 +81,7 @@ class SelectionOptions {
8181
return SelectionOptions(
8282
allowMultiple: result[0]! as bool,
8383
selectFolders: result[1]! as bool,
84-
allowedTypes: (result[2] as List<Object?>?)!.cast<TypeGroup?>(),
84+
allowedTypes: (result[2] as List<Object?>?)!.cast<TypeGroup>(),
8585
);
8686
}
8787
}
@@ -96,7 +96,7 @@ class FileDialogResult {
9696
/// The selected paths.
9797
///
9898
/// Empty if the dialog was canceled.
99-
List<String?> paths;
99+
List<String> paths;
100100

101101
/// The type group index (into the list provided in [SelectionOptions]) of
102102
/// the group that was selected when the dialog was confirmed.
@@ -114,7 +114,7 @@ class FileDialogResult {
114114
static FileDialogResult decode(Object result) {
115115
result as List<Object?>;
116116
return FileDialogResult(
117-
paths: (result[0] as List<Object?>?)!.cast<String?>(),
117+
paths: (result[0] as List<Object?>?)!.cast<String>(),
118118
typeGroupIndex: result[1] as int?,
119119
);
120120
}
@@ -124,7 +124,10 @@ class _PigeonCodec extends StandardMessageCodec {
124124
const _PigeonCodec();
125125
@override
126126
void writeValue(WriteBuffer buffer, Object? value) {
127-
if (value is TypeGroup) {
127+
if (value is int) {
128+
buffer.putUint8(4);
129+
buffer.putInt64(value);
130+
} else if (value is TypeGroup) {
128131
buffer.putUint8(129);
129132
writeValue(buffer, value.encode());
130133
} else if (value is SelectionOptions) {
@@ -159,43 +162,43 @@ class FileSelectorApi {
159162
/// BinaryMessenger will be used which routes to the host platform.
160163
FileSelectorApi(
161164
{BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''})
162-
: __pigeon_binaryMessenger = binaryMessenger,
163-
__pigeon_messageChannelSuffix =
165+
: pigeonVar_binaryMessenger = binaryMessenger,
166+
pigeonVar_messageChannelSuffix =
164167
messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : '';
165-
final BinaryMessenger? __pigeon_binaryMessenger;
168+
final BinaryMessenger? pigeonVar_binaryMessenger;
166169

167170
static const MessageCodec<Object?> pigeonChannelCodec = _PigeonCodec();
168171

169-
final String __pigeon_messageChannelSuffix;
172+
final String pigeonVar_messageChannelSuffix;
170173

171174
Future<FileDialogResult> showOpenDialog(SelectionOptions options,
172175
String? initialDirectory, String? confirmButtonText) async {
173-
final String __pigeon_channelName =
174-
'dev.flutter.pigeon.file_selector_windows.FileSelectorApi.showOpenDialog$__pigeon_messageChannelSuffix';
175-
final BasicMessageChannel<Object?> __pigeon_channel =
176+
final String pigeonVar_channelName =
177+
'dev.flutter.pigeon.file_selector_windows.FileSelectorApi.showOpenDialog$pigeonVar_messageChannelSuffix';
178+
final BasicMessageChannel<Object?> pigeonVar_channel =
176179
BasicMessageChannel<Object?>(
177-
__pigeon_channelName,
180+
pigeonVar_channelName,
178181
pigeonChannelCodec,
179-
binaryMessenger: __pigeon_binaryMessenger,
182+
binaryMessenger: pigeonVar_binaryMessenger,
180183
);
181-
final List<Object?>? __pigeon_replyList = await __pigeon_channel
184+
final List<Object?>? pigeonVar_replyList = await pigeonVar_channel
182185
.send(<Object?>[options, initialDirectory, confirmButtonText])
183186
as List<Object?>?;
184-
if (__pigeon_replyList == null) {
185-
throw _createConnectionError(__pigeon_channelName);
186-
} else if (__pigeon_replyList.length > 1) {
187+
if (pigeonVar_replyList == null) {
188+
throw _createConnectionError(pigeonVar_channelName);
189+
} else if (pigeonVar_replyList.length > 1) {
187190
throw PlatformException(
188-
code: __pigeon_replyList[0]! as String,
189-
message: __pigeon_replyList[1] as String?,
190-
details: __pigeon_replyList[2],
191+
code: pigeonVar_replyList[0]! as String,
192+
message: pigeonVar_replyList[1] as String?,
193+
details: pigeonVar_replyList[2],
191194
);
192-
} else if (__pigeon_replyList[0] == null) {
195+
} else if (pigeonVar_replyList[0] == null) {
193196
throw PlatformException(
194197
code: 'null-error',
195198
message: 'Host platform returned null value for non-null return value.',
196199
);
197200
} else {
198-
return (__pigeon_replyList[0] as FileDialogResult?)!;
201+
return (pigeonVar_replyList[0] as FileDialogResult?)!;
199202
}
200203
}
201204

@@ -204,36 +207,36 @@ class FileSelectorApi {
204207
String? initialDirectory,
205208
String? suggestedName,
206209
String? confirmButtonText) async {
207-
final String __pigeon_channelName =
208-
'dev.flutter.pigeon.file_selector_windows.FileSelectorApi.showSaveDialog$__pigeon_messageChannelSuffix';
209-
final BasicMessageChannel<Object?> __pigeon_channel =
210+
final String pigeonVar_channelName =
211+
'dev.flutter.pigeon.file_selector_windows.FileSelectorApi.showSaveDialog$pigeonVar_messageChannelSuffix';
212+
final BasicMessageChannel<Object?> pigeonVar_channel =
210213
BasicMessageChannel<Object?>(
211-
__pigeon_channelName,
214+
pigeonVar_channelName,
212215
pigeonChannelCodec,
213-
binaryMessenger: __pigeon_binaryMessenger,
216+
binaryMessenger: pigeonVar_binaryMessenger,
214217
);
215-
final List<Object?>? __pigeon_replyList = await __pigeon_channel
218+
final List<Object?>? pigeonVar_replyList = await pigeonVar_channel
216219
.send(<Object?>[
217220
options,
218221
initialDirectory,
219222
suggestedName,
220223
confirmButtonText
221224
]) as List<Object?>?;
222-
if (__pigeon_replyList == null) {
223-
throw _createConnectionError(__pigeon_channelName);
224-
} else if (__pigeon_replyList.length > 1) {
225+
if (pigeonVar_replyList == null) {
226+
throw _createConnectionError(pigeonVar_channelName);
227+
} else if (pigeonVar_replyList.length > 1) {
225228
throw PlatformException(
226-
code: __pigeon_replyList[0]! as String,
227-
message: __pigeon_replyList[1] as String?,
228-
details: __pigeon_replyList[2],
229+
code: pigeonVar_replyList[0]! as String,
230+
message: pigeonVar_replyList[1] as String?,
231+
details: pigeonVar_replyList[2],
229232
);
230-
} else if (__pigeon_replyList[0] == null) {
233+
} else if (pigeonVar_replyList[0] == null) {
231234
throw PlatformException(
232235
code: 'null-error',
233236
message: 'Host platform returned null value for non-null return value.',
234237
);
235238
} else {
236-
return (__pigeon_replyList[0] as FileDialogResult?)!;
239+
return (pigeonVar_replyList[0] as FileDialogResult?)!;
237240
}
238241
}
239242
}

packages/file_selector/file_selector_windows/pigeons/messages.dart

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,18 @@ class TypeGroup {
1616
TypeGroup(this.label, {required this.extensions});
1717

1818
String label;
19-
// TODO(stuartmorgan): Make the generic type non-nullable once supported.
20-
// https://github.com/flutter/flutter/issues/97848
21-
// The C++ code treats all of it as non-nullable.
22-
List<String?> extensions;
19+
List<String> extensions;
2320
}
2421

2522
class SelectionOptions {
2623
SelectionOptions({
2724
this.allowMultiple = false,
2825
this.selectFolders = false,
29-
this.allowedTypes = const <TypeGroup?>[],
26+
this.allowedTypes = const <TypeGroup>[],
3027
});
3128
bool allowMultiple;
3229
bool selectFolders;
33-
34-
// TODO(stuartmorgan): Make the generic type non-nullable once supported.
35-
// https://github.com/flutter/flutter/issues/97848
36-
// The C++ code treats the values as non-nullable.
37-
List<TypeGroup?> allowedTypes;
30+
List<TypeGroup> allowedTypes;
3831
}
3932

4033
/// The result from an open or save dialog.
@@ -44,10 +37,7 @@ class FileDialogResult {
4437
/// The selected paths.
4538
///
4639
/// Empty if the dialog was canceled.
47-
// TODO(stuartmorgan): Make the generic type non-nullable once supported.
48-
// https://github.com/flutter/flutter/issues/97848
49-
// The Dart code treats the values as non-nullable.
50-
List<String?> paths;
40+
List<String> paths;
5141

5242
/// The type group index (into the list provided in [SelectionOptions]) of
5343
/// the group that was selected when the dialog was confirmed.

packages/file_selector/file_selector_windows/pubspec.yaml

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

77
environment:
88
sdk: ^3.3.0
@@ -27,7 +27,7 @@ dev_dependencies:
2727
flutter_test:
2828
sdk: flutter
2929
mockito: 5.4.4
30-
pigeon: ^21.0.0
30+
pigeon: ^22.4.1
3131

3232
topics:
3333
- files

packages/file_selector/file_selector_windows/test/file_selector_windows_test.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void main() {
3333
group('openFile', () {
3434
setUp(() {
3535
when(mockApi.showOpenDialog(any, any, any))
36-
.thenReturn(FileDialogResult(paths: <String?>['foo']));
36+
.thenReturn(FileDialogResult(paths: <String>['foo']));
3737
});
3838

3939
test('simple call works', () async {
@@ -109,7 +109,7 @@ void main() {
109109
group('openFiles', () {
110110
setUp(() {
111111
when(mockApi.showOpenDialog(any, any, any))
112-
.thenReturn(FileDialogResult(paths: <String?>['foo', 'bar']));
112+
.thenReturn(FileDialogResult(paths: <String>['foo', 'bar']));
113113
});
114114

115115
test('simple call works', () async {
@@ -186,7 +186,7 @@ void main() {
186186
group('getDirectoryPath', () {
187187
setUp(() {
188188
when(mockApi.showOpenDialog(any, any, any))
189-
.thenReturn(FileDialogResult(paths: <String?>['foo']));
189+
.thenReturn(FileDialogResult(paths: <String>['foo']));
190190
});
191191

192192
test('simple call works', () async {
@@ -216,11 +216,11 @@ void main() {
216216
group('getDirectoryPaths', () {
217217
setUp(() {
218218
when(mockApi.showOpenDialog(any, any, any))
219-
.thenReturn(FileDialogResult(paths: <String?>['foo', 'bar']));
219+
.thenReturn(FileDialogResult(paths: <String>['foo', 'bar']));
220220
});
221221

222222
test('simple call works', () async {
223-
final List<String?> paths = await plugin.getDirectoryPaths();
223+
final List<String> paths = await plugin.getDirectoryPaths();
224224

225225
expect(paths[0], 'foo');
226226
expect(paths[1], 'bar');
@@ -247,7 +247,7 @@ void main() {
247247
group('getSaveLocation', () {
248248
setUp(() {
249249
when(mockApi.showSaveDialog(any, any, any, any))
250-
.thenReturn(FileDialogResult(paths: <String?>['foo']));
250+
.thenReturn(FileDialogResult(paths: <String>['foo']));
251251
});
252252

253253
test('simple call works', () async {
@@ -291,7 +291,7 @@ void main() {
291291

292292
test('returns the selected type group correctly', () async {
293293
when(mockApi.showSaveDialog(any, any, any, any)).thenReturn(
294-
FileDialogResult(paths: <String?>['foo'], typeGroupIndex: 1));
294+
FileDialogResult(paths: <String>['foo'], typeGroupIndex: 1));
295295
const XTypeGroup group = XTypeGroup(
296296
label: 'text',
297297
extensions: <String>['txt'],
@@ -359,7 +359,7 @@ void main() {
359359
group('getSavePath (deprecated)', () {
360360
setUp(() {
361361
when(mockApi.showSaveDialog(any, any, any, any))
362-
.thenReturn(FileDialogResult(paths: <String?>['foo']));
362+
.thenReturn(FileDialogResult(paths: <String>['foo']));
363363
});
364364

365365
test('simple call works', () async {

0 commit comments

Comments
 (0)