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

Commit

Permalink
apply feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
adpinola committed Nov 17, 2022
1 parent 253ef76 commit 14b4098
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 73 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
## 2.3.0+1
## 2.4.0

* Adds `getDirectoryPaths` method to the interface.

## 2.3.0

* Adds `getDirectoriesPaths` method to the interface.
* Replaces `macUTIs` with `uniformTypeIdentifiers`. `macUTIs` is available as an alias, but will be deprecated in a future release.

## 2.2.0
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 @@ -94,17 +90,16 @@ class MethodChannelFileSelector extends FileSelectorPlatform {
);
}

/// Gets a list of directories paths from a dialog
@override
Future<List<String>?> getDirectoriesPaths(
Future<List<String>> getDirectoryPaths(
{String? initialDirectory, String? confirmButtonText}) async {
return _channel.invokeListMethod<String>(
'getDirectoriesPaths',
final List<String>? pathList = await _channel.invokeListMethod<String>(
'getDirectoryPaths',
<String, dynamic>{
'initialDirectory': initialDirectory,
'confirmButtonText': confirmButtonText,
'multiple': true,
},
);
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,7 +66,7 @@ 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,
Expand All @@ -75,12 +75,11 @@ abstract class FileSelectorPlatform extends PlatformInterface {
throw UnimplementedError('getDirectoryPath() has not been implemented.');
}

/// Open file dialog for loading directories and return multiple directories paths
/// Returns `null` if user cancels the operation.
Future<List<String>?> getDirectoriesPaths({
/// Opens a file dialog for loading directories and returns multiple directory paths.
Future<List<String>> getDirectoryPaths({
String? initialDirectory,
String? confirmButtonText,
}) {
throw UnimplementedError('getDirectoriesPaths() has not been implemented.');
throw UnimplementedError('getDirectoryPaths() has not been implemented.');
}
}
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+1
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 sut = ExtendsFileSelectorPlatform();

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

class ExtendsFileSelectorPlatform extends FileSelectorPlatform {}
Original file line number Diff line number Diff line change
Expand Up @@ -219,64 +219,62 @@ void main() {
],
);
});
group('#getDirectoryPath', () {
test('passes initialDirectory correctly', () async {
await plugin.getDirectoryPath(initialDirectory: '/example/directory');
});
group('#getDirectoryPath', () {
test('passes initialDirectory correctly', () async {
await plugin.getDirectoryPath(initialDirectory: '/example/directory');

expect(
log,
<Matcher>[
isMethodCall('getDirectoryPath', arguments: <String, dynamic>{
'initialDirectory': '/example/directory',
'confirmButtonText': null,
}),
],
);
});
test('passes confirmButtonText correctly', () async {
await plugin.getDirectoryPath(confirmButtonText: 'Open File');
expect(
log,
<Matcher>[
isMethodCall('getDirectoryPath', arguments: <String, dynamic>{
'initialDirectory': '/example/directory',
'confirmButtonText': null,
}),
],
);
});
test('passes confirmButtonText correctly', () async {
await plugin.getDirectoryPath(confirmButtonText: 'Select Folder');

expect(
log,
<Matcher>[
isMethodCall('getDirectoryPath', arguments: <String, dynamic>{
'initialDirectory': null,
'confirmButtonText': 'Open File',
}),
],
);
});
expect(
log,
<Matcher>[
isMethodCall('getDirectoryPath', arguments: <String, dynamic>{
'initialDirectory': null,
'confirmButtonText': 'Select Folder',
}),
],
);
});
group('#getDirectoriesPaths', () {
test('passes initialDirectory correctly', () async {
await plugin.getDirectoriesPaths(
initialDirectory: '/example/directory');
});
group('#getDirectoryPaths', () {
test('passes initialDirectory correctly', () async {
await plugin.getDirectoryPaths(initialDirectory: '/example/directory');

expect(
log,
<Matcher>[
isMethodCall('getDirectoriesPaths', arguments: <String, dynamic>{
'initialDirectory': '/example/directory',
'confirmButtonText': null,
'multiple': true
}),
],
);
});
test('passes confirmButtonText correctly', () async {
await plugin.getDirectoriesPaths(confirmButtonText: 'Open File');
expect(
log,
<Matcher>[
isMethodCall('getDirectoryPaths', arguments: <String, dynamic>{
'initialDirectory': '/example/directory',
'confirmButtonText': null,
}),
],
);
});
test('passes confirmButtonText correctly', () async {
await plugin.getDirectoryPaths(
confirmButtonText: 'Select one or more Folders');

expect(
log,
<Matcher>[
isMethodCall('getDirectoriesPaths', arguments: <String, dynamic>{
'initialDirectory': null,
'confirmButtonText': 'Open File',
'multiple': true
}),
],
);
});
expect(
log,
<Matcher>[
isMethodCall('getDirectoryPaths', arguments: <String, dynamic>{
'initialDirectory': null,
'confirmButtonText': 'Select one or more Folders',
}),
],
);
});
});
});
Expand Down

0 comments on commit 14b4098

Please sign in to comment.