Skip to content

Commit 0b3beb5

Browse files
committed
add parameter to getSaveLocation
1 parent ea3e2d8 commit 0b3beb5

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

packages/file_selector/file_selector/lib/file_selector.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,25 @@ Future<List<XFile>> openFiles({
9393
/// [confirmButtonText] is the text in the confirmation button of the dialog.
9494
/// When not provided, the default OS label is used (for example, "Save").
9595
///
96+
/// [canCreateDirectories] controls whether the user is allowed to create new
97+
/// directories in the save dialog. When not provided, uses the platform default.
98+
/// May not be supported on all platforms.
99+
///
96100
/// Returns `null` if the user cancels the operation.
97101
Future<FileSaveLocation?> getSaveLocation({
98102
List<XTypeGroup> acceptedTypeGroups = const <XTypeGroup>[],
99103
String? initialDirectory,
100104
String? suggestedName,
101105
String? confirmButtonText,
106+
bool? canCreateDirectories,
102107
}) async {
103108
return FileSelectorPlatform.instance.getSaveLocation(
104109
acceptedTypeGroups: acceptedTypeGroups,
105110
options: SaveDialogOptions(
106111
initialDirectory: initialDirectory,
107112
suggestedName: suggestedName,
108113
confirmButtonText: confirmButtonText,
114+
canCreateDirectories: canCreateDirectories,
109115
),
110116
);
111117
}

packages/file_selector/file_selector/test/file_selector_test.dart

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,18 @@ void main() {
228228
);
229229
expect(location?.path, expectedSavePath);
230230
});
231+
232+
test('sets to disable the creation of new directories', () async {
233+
const bool canCreateDirectories = false;
234+
fakePlatformImplementation
235+
..setExpectations(canCreateDirectories: canCreateDirectories)
236+
..setPathsResponse(<String>[expectedSavePath]);
237+
238+
final FileSaveLocation? location = await getSaveLocation(
239+
canCreateDirectories: canCreateDirectories,
240+
);
241+
expect(location?.path, expectedSavePath);
242+
});
231243
});
232244

233245
group('getDirectoryPath', () {
@@ -280,7 +292,7 @@ void main() {
280292
expect(directoryPath, expectedDirectoryPath);
281293
});
282294

283-
test('sets the canCreateDirectories parameter', () async {
295+
test('sets to enable de creation of new directories', () async {
284296
const bool canCreateDirectories = true;
285297
fakePlatformImplementation
286298
..setExpectations(canCreateDirectories: canCreateDirectories)
@@ -343,7 +355,7 @@ void main() {
343355
);
344356
expect(directoryPaths, expectedDirectoryPaths);
345357
});
346-
test('sets the canCreateDirectories parameter', () async {
358+
test('sets to enable de creation of new directories', () async {
347359
const bool canCreateDirectories = true;
348360
fakePlatformImplementation
349361
..setExpectations(canCreateDirectories: canCreateDirectories)

0 commit comments

Comments
 (0)