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

[file_selector] Add getDirectoryPaths method to the file_selector_platform_interface. #6572

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
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.4.0

* Adds `getDirectoryPaths` method to the interface.

## 2.3.0

* Replaces `macUTIs` with `uniformTypeIdentifiers`. `macUTIs` is available as an alias, but will be deprecated in a future release.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class MethodChannelFileSelector extends FileSelectorPlatform {
@visibleForTesting
MethodChannel get channel => _channel;

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

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

/// Gets the path from a save dialog
@override
Future<String?> getSavePath({
List<XTypeGroup>? acceptedTypeGroups,
Expand All @@ -79,7 +76,6 @@ class MethodChannelFileSelector extends FileSelectorPlatform {
);
}

/// Gets a directory path from a dialog
@override
Future<String?> getDirectoryPath({
String? initialDirectory,
Expand All @@ -93,4 +89,17 @@ class MethodChannelFileSelector extends FileSelectorPlatform {
},
);
}

@override
Future<List<String>> getDirectoryPaths(
{String? initialDirectory, String? confirmButtonText}) async {
final List<String>? pathList = await _channel.invokeListMethod<String>(
'getDirectoryPaths',
<String, dynamic>{
'initialDirectory': initialDirectory,
'confirmButtonText': confirmButtonText,
},
);
return pathList ?? <String>[];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ abstract class FileSelectorPlatform extends PlatformInterface {
_instance = instance;
}

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

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

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

/// Open file dialog for loading directories and return a directory path
/// Opens a file dialog for loading directories and returns a directory path.
/// Returns `null` if user cancels the operation.
Future<String?> getDirectoryPath({
String? initialDirectory,
String? confirmButtonText,
}) {
throw UnimplementedError('getDirectoryPath() has not been implemented.');
}

/// Opens a file dialog for loading directories and returns multiple directory paths.
Future<List<String>> getDirectoryPaths({
String? initialDirectory,
String? confirmButtonText,
}) {
throw UnimplementedError('getDirectoryPaths() has not been implemented.');
}
eugerossetto marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repository: https://github.com/flutter/plugins/tree/main/packages/file_selector/
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+file_selector%22
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 2.3.0
version: 2.4.0

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ void main() {
FileSelectorPlatform.instance = ExtendsFileSelectorPlatform();
});
});

group('#GetDirectoryPaths', () {
test('Should throw unimplemented exception', () async {
final FileSelectorPlatform fileSelector = ExtendsFileSelectorPlatform();

await expectLater(() async {
return fileSelector.getDirectoryPaths();
}, throwsA(isA<UnimplementedError>()));
});
});
}

class ExtendsFileSelectorPlatform extends FileSelectorPlatform {}
Loading