Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 2ba4c0a

Browse files
[file_selector] Add getDirectoryPaths method to the file_selector_platform_interface. (#6572)
* Add getDirectoriesPaths method to the file_selector_platform_interface * Add getDirectoriesPaths to method channel. * Increment version to 2.3.0 * apply feedback * extract assertion method Co-authored-by: Alejandro Pinola <[email protected]>
1 parent b828242 commit 2ba4c0a

File tree

6 files changed

+181
-126
lines changed

6 files changed

+181
-126
lines changed

packages/file_selector/file_selector_platform_interface/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.4.0
2+
3+
* Adds `getDirectoryPaths` method to the interface.
4+
15
## 2.3.0
26

37
* Replaces `macUTIs` with `uniformTypeIdentifiers`. `macUTIs` is available as an alias, but will be deprecated in a future release.

packages/file_selector/file_selector_platform_interface/lib/src/method_channel/method_channel_file_selector.dart

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class MethodChannelFileSelector extends FileSelectorPlatform {
1616
@visibleForTesting
1717
MethodChannel get channel => _channel;
1818

19-
/// Load a file from user's computer and return it as an XFile
2019
@override
2120
Future<XFile?> openFile({
2221
List<XTypeGroup>? acceptedTypeGroups,
@@ -37,7 +36,6 @@ class MethodChannelFileSelector extends FileSelectorPlatform {
3736
return path == null ? null : XFile(path.first);
3837
}
3938

40-
/// Load multiple files from user's computer and return it as an XFile
4139
@override
4240
Future<List<XFile>> openFiles({
4341
List<XTypeGroup>? acceptedTypeGroups,
@@ -58,7 +56,6 @@ class MethodChannelFileSelector extends FileSelectorPlatform {
5856
return pathList?.map((String path) => XFile(path)).toList() ?? <XFile>[];
5957
}
6058

61-
/// Gets the path from a save dialog
6259
@override
6360
Future<String?> getSavePath({
6461
List<XTypeGroup>? acceptedTypeGroups,
@@ -79,7 +76,6 @@ class MethodChannelFileSelector extends FileSelectorPlatform {
7976
);
8077
}
8178

82-
/// Gets a directory path from a dialog
8379
@override
8480
Future<String?> getDirectoryPath({
8581
String? initialDirectory,
@@ -93,4 +89,17 @@ class MethodChannelFileSelector extends FileSelectorPlatform {
9389
},
9490
);
9591
}
92+
93+
@override
94+
Future<List<String>> getDirectoryPaths(
95+
{String? initialDirectory, String? confirmButtonText}) async {
96+
final List<String>? pathList = await _channel.invokeListMethod<String>(
97+
'getDirectoryPaths',
98+
<String, dynamic>{
99+
'initialDirectory': initialDirectory,
100+
'confirmButtonText': confirmButtonText,
101+
},
102+
);
103+
return pathList ?? <String>[];
104+
}
96105
}

packages/file_selector/file_selector_platform_interface/lib/src/platform_interface/file_selector_interface.dart

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ abstract class FileSelectorPlatform extends PlatformInterface {
3636
_instance = instance;
3737
}
3838

39-
/// Open file dialog for loading files and return a file path
39+
/// Opens a file dialog for loading files and returns a file path.
4040
/// Returns `null` if user cancels the operation.
4141
Future<XFile?> openFile({
4242
List<XTypeGroup>? acceptedTypeGroups,
@@ -46,7 +46,7 @@ abstract class FileSelectorPlatform extends PlatformInterface {
4646
throw UnimplementedError('openFile() has not been implemented.');
4747
}
4848

49-
/// Open file dialog for loading files and return a list of file paths
49+
/// Opens a file dialog for loading files and returns a list of file paths.
5050
Future<List<XFile>> openFiles({
5151
List<XTypeGroup>? acceptedTypeGroups,
5252
String? initialDirectory,
@@ -55,7 +55,7 @@ abstract class FileSelectorPlatform extends PlatformInterface {
5555
throw UnimplementedError('openFiles() has not been implemented.');
5656
}
5757

58-
/// Open file dialog for saving files and return a file path at which to save
58+
/// Opens a file dialog for saving files and returns a file path at which to save.
5959
/// Returns `null` if user cancels the operation.
6060
Future<String?> getSavePath({
6161
List<XTypeGroup>? acceptedTypeGroups,
@@ -66,12 +66,20 @@ abstract class FileSelectorPlatform extends PlatformInterface {
6666
throw UnimplementedError('getSavePath() has not been implemented.');
6767
}
6868

69-
/// Open file dialog for loading directories and return a directory path
69+
/// Opens a file dialog for loading directories and returns a directory path.
7070
/// Returns `null` if user cancels the operation.
7171
Future<String?> getDirectoryPath({
7272
String? initialDirectory,
7373
String? confirmButtonText,
7474
}) {
7575
throw UnimplementedError('getDirectoryPath() has not been implemented.');
7676
}
77+
78+
/// Opens a file dialog for loading directories and returns multiple directory paths.
79+
Future<List<String>> getDirectoryPaths({
80+
String? initialDirectory,
81+
String? confirmButtonText,
82+
}) {
83+
throw UnimplementedError('getDirectoryPaths() has not been implemented.');
84+
}
7785
}

packages/file_selector/file_selector_platform_interface/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repository: https://github.com/flutter/plugins/tree/main/packages/file_selector/
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+file_selector%22
55
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
66
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
7-
version: 2.3.0
7+
version: 2.4.0
88

99
environment:
1010
sdk: ">=2.12.0 <3.0.0"

packages/file_selector/file_selector_platform_interface/test/file_selector_platform_interface_test.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ void main() {
1919
FileSelectorPlatform.instance = ExtendsFileSelectorPlatform();
2020
});
2121
});
22+
23+
group('#GetDirectoryPaths', () {
24+
test('Should throw unimplemented exception', () async {
25+
final FileSelectorPlatform fileSelector = ExtendsFileSelectorPlatform();
26+
27+
await expectLater(() async {
28+
return fileSelector.getDirectoryPaths();
29+
}, throwsA(isA<UnimplementedError>()));
30+
});
31+
});
2232
}
2333

2434
class ExtendsFileSelectorPlatform extends FileSelectorPlatform {}

0 commit comments

Comments
 (0)