Skip to content
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
3 changes: 2 additions & 1 deletion packages/file_selector/file_selector_linux/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 0.9.2

* Adds `getSaveLocation` and deprecates `getSavePath`.
* Updates minimum supported SDK version to Flutter 3.3/Dart 2.18.

## 0.9.1+3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,20 @@ class SaveTextPage extends StatelessWidget {

Future<void> _saveFile() async {
final String fileName = _nameController.text;
// TODO(stuartmorgan): Update this to getSaveLocation in the next federated
// change PR.
// ignore: deprecated_member_use
final String? path = await FileSelectorPlatform.instance.getSavePath(
// Operation was canceled by the user.
suggestedName: fileName,
final FileSaveLocation? result =
await FileSelectorPlatform.instance.getSaveLocation(
options: SaveDialogOptions(suggestedName: fileName),
);
if (path == null) {
// Operation was canceled by the user.
if (result == null) {
return;
}
final String text = _contentController.text;
final Uint8List fileData = Uint8List.fromList(text.codeUnits);
const String fileMimeType = 'text/plain';
final XFile textFile =
XFile.fromData(fileData, mimeType: fileMimeType, name: fileName);
await textFile.saveTo(path);
await textFile.saveTo(result.path);
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ environment:
dependencies:
file_selector_linux:
path: ../
file_selector_platform_interface: ^2.4.0
file_selector_platform_interface: ^2.6.0
flutter:
sdk: flutter

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,37 @@ class FileSelectorLinux extends FileSelectorPlatform {
String? initialDirectory,
String? suggestedName,
String? confirmButtonText,
}) async {
final FileSaveLocation? location = await getSaveLocation(
acceptedTypeGroups: acceptedTypeGroups,
options: SaveDialogOptions(
initialDirectory: initialDirectory,
suggestedName: suggestedName,
confirmButtonText: confirmButtonText,
));
return location?.path;
}

@override
Future<FileSaveLocation?> getSaveLocation({
List<XTypeGroup>? acceptedTypeGroups,
SaveDialogOptions options = const SaveDialogOptions(),
}) async {
final List<Map<String, Object>> serializedTypeGroups =
_serializeTypeGroups(acceptedTypeGroups);
return _channel.invokeMethod<String>(
// TODO(stuartmorgan): Add the selected type group here and return it. See
// https://github.com/flutter/flutter/issues/107093
final String? path = await _channel.invokeMethod<String>(
_getSavePathMethod,
<String, dynamic>{
if (serializedTypeGroups.isNotEmpty)
_acceptedTypeGroupsKey: serializedTypeGroups,
_initialDirectoryKey: initialDirectory,
_suggestedNameKey: suggestedName,
_confirmButtonTextKey: confirmButtonText,
_initialDirectoryKey: options.initialDirectory,
_suggestedNameKey: options.suggestedName,
_confirmButtonTextKey: options.confirmButtonText,
},
);
return path == null ? null : FileSaveLocation(path);
}

@override
Expand Down
4 changes: 2 additions & 2 deletions packages/file_selector/file_selector_linux/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: file_selector_linux
description: Liunx implementation of the file_selector plugin.
repository: https://github.com/flutter/packages/tree/main/packages/file_selector/file_selector_linux
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+file_selector%22
version: 0.9.1+3
version: 0.9.2

environment:
sdk: ">=2.18.0 <4.0.0"
Expand All @@ -18,7 +18,7 @@ flutter:

dependencies:
cross_file: ^0.3.1
file_selector_platform_interface: ^2.4.0
file_selector_platform_interface: ^2.6.0
flutter:
sdk: flutter

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void main() {
expect(FileSelectorPlatform.instance, isA<FileSelectorLinux>());
});

group('#openFile', () {
group('openFile', () {
test('passes the accepted type groups correctly', () async {
const XTypeGroup group = XTypeGroup(
label: 'text',
Expand Down Expand Up @@ -135,7 +135,7 @@ void main() {
});
});

group('#openFiles', () {
group('openFiles', () {
test('passes the accepted type groups correctly', () async {
const XTypeGroup group = XTypeGroup(
label: 'text',
Expand Down Expand Up @@ -209,7 +209,7 @@ void main() {
);

await expectLater(
plugin.openFile(acceptedTypeGroups: <XTypeGroup>[group]),
plugin.openFiles(acceptedTypeGroups: <XTypeGroup>[group]),
throwsArgumentError);
});

Expand All @@ -218,7 +218,7 @@ void main() {
label: 'any',
);

await plugin.openFile(acceptedTypeGroups: <XTypeGroup>[group]);
await plugin.openFiles(acceptedTypeGroups: <XTypeGroup>[group]);

expectMethodCall(
log,
Expand All @@ -232,13 +232,120 @@ void main() {
],
'initialDirectory': null,
'confirmButtonText': null,
'multiple': false,
'multiple': true,
},
);
});
});

group('getSaveLocation', () {
test('passes the accepted type groups correctly', () async {
const XTypeGroup group = XTypeGroup(
label: 'text',
extensions: <String>['txt'],
mimeTypes: <String>['text/plain'],
);

const XTypeGroup groupTwo = XTypeGroup(
label: 'image',
extensions: <String>['jpg'],
mimeTypes: <String>['image/jpg'],
);

await plugin
.getSaveLocation(acceptedTypeGroups: <XTypeGroup>[group, groupTwo]);

expectMethodCall(
log,
'getSavePath',
arguments: <String, dynamic>{
'acceptedTypeGroups': <Map<String, dynamic>>[
<String, Object>{
'label': 'text',
'extensions': <String>['*.txt'],
'mimeTypes': <String>['text/plain'],
},
<String, Object>{
'label': 'image',
'extensions': <String>['*.jpg'],
'mimeTypes': <String>['image/jpg'],
},
],
'initialDirectory': null,
'suggestedName': null,
'confirmButtonText': null,
},
);
});

test('passes initialDirectory correctly', () async {
await plugin.getSaveLocation(
options:
const SaveDialogOptions(initialDirectory: '/example/directory'));

expectMethodCall(
log,
'getSavePath',
arguments: <String, dynamic>{
'initialDirectory': '/example/directory',
'suggestedName': null,
'confirmButtonText': null,
},
);
});

test('passes confirmButtonText correctly', () async {
await plugin.getSaveLocation(
options: const SaveDialogOptions(confirmButtonText: 'Open File'));

expectMethodCall(
log,
'getSavePath',
arguments: <String, dynamic>{
'initialDirectory': null,
'suggestedName': null,
'confirmButtonText': 'Open File',
},
);
});

test('throws for a type group that does not support Linux', () async {
const XTypeGroup group = XTypeGroup(
label: 'images',
webWildCards: <String>['images/*'],
);

await expectLater(
plugin.getSaveLocation(acceptedTypeGroups: <XTypeGroup>[group]),
throwsArgumentError);
});

test('passes a wildcard group correctly', () async {
const XTypeGroup group = XTypeGroup(
label: 'any',
);

await plugin.getSaveLocation(acceptedTypeGroups: <XTypeGroup>[group]);

expectMethodCall(
log,
'getSavePath',
arguments: <String, dynamic>{
'acceptedTypeGroups': <Map<String, dynamic>>[
<String, Object>{
'label': 'any',
'extensions': <String>['*'],
},
],
'initialDirectory': null,
'suggestedName': null,
'confirmButtonText': null,
},
);
});
});

group('#getSavePath', () {
group('getSavePath (deprecated)', () {
test('passes the accepted type groups correctly', () async {
const XTypeGroup group = XTypeGroup(
label: 'text',
Expand Down Expand Up @@ -313,7 +420,7 @@ void main() {
);

await expectLater(
plugin.openFile(acceptedTypeGroups: <XTypeGroup>[group]),
plugin.getSavePath(acceptedTypeGroups: <XTypeGroup>[group]),
throwsArgumentError);
});

Expand All @@ -322,11 +429,11 @@ void main() {
label: 'any',
);

await plugin.openFile(acceptedTypeGroups: <XTypeGroup>[group]);
await plugin.getSavePath(acceptedTypeGroups: <XTypeGroup>[group]);

expectMethodCall(
log,
'openFile',
'getSavePath',
arguments: <String, dynamic>{
'acceptedTypeGroups': <Map<String, dynamic>>[
<String, Object>{
Expand All @@ -335,14 +442,14 @@ void main() {
},
],
'initialDirectory': null,
'suggestedName': null,
'confirmButtonText': null,
'multiple': false,
},
);
});
});

group('#getDirectoryPath', () {
group('getDirectoryPath', () {
test('passes initialDirectory correctly', () async {
await plugin.getDirectoryPath(initialDirectory: '/example/directory');

Expand All @@ -369,7 +476,7 @@ void main() {
});
});

group('#getDirectoryPaths', () {
group('getDirectoryPaths', () {
test('passes initialDirectory correctly', () async {
await plugin.getDirectoryPaths(initialDirectory: '/example/directory');

Expand Down
3 changes: 2 additions & 1 deletion packages/file_selector/file_selector_macos/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 0.9.3

* Adds `getSaveLocation` and deprecates `getSavePath`.
* Updates minimum supported macOS version to 10.14.

## 0.9.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ class SaveTextPage extends StatelessWidget {

Future<void> _saveFile() async {
final String fileName = _nameController.text;
// TODO(stuartmorgan): Update this to getSaveLocation in the next federated
// change PR.
// ignore: deprecated_member_use
final String? path = await FileSelectorPlatform.instance.getSavePath(
suggestedName: fileName,
final FileSaveLocation? result =
await FileSelectorPlatform.instance.getSaveLocation(
options: SaveDialogOptions(suggestedName: fileName),
);
if (path == null) {
if (result == null) {
// Operation was canceled by the user.
return;
}
Expand All @@ -32,7 +30,7 @@ class SaveTextPage extends StatelessWidget {
const String fileMimeType = 'text/plain';
final XFile textFile =
XFile.fromData(fileData, mimeType: fileMimeType, name: fileName);
await textFile.saveTo(path);
await textFile.saveTo(result.path);
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies:
# The example app is bundled with the plugin so we use a path dependency on
# the parent directory to use the current plugin's version.
path: ..
file_selector_platform_interface: ^2.4.0
file_selector_platform_interface: ^2.6.0
flutter:
sdk: flutter

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,28 @@ class FileSelectorMacOS extends FileSelectorPlatform {
String? suggestedName,
String? confirmButtonText,
}) async {
return _hostApi.displaySavePanel(SavePanelOptions(
final FileSaveLocation? location = await getSaveLocation(
acceptedTypeGroups: acceptedTypeGroups,
options: SaveDialogOptions(
initialDirectory: initialDirectory,
suggestedName: suggestedName,
confirmButtonText: confirmButtonText,
));
return location?.path;
}

@override
Future<FileSaveLocation?> getSaveLocation({
List<XTypeGroup>? acceptedTypeGroups,
SaveDialogOptions options = const SaveDialogOptions(),
}) async {
final String? path = await _hostApi.displaySavePanel(SavePanelOptions(
allowedFileTypes: _allowedTypesFromTypeGroups(acceptedTypeGroups),
directoryPath: initialDirectory,
nameFieldStringValue: suggestedName,
prompt: confirmButtonText,
directoryPath: options.initialDirectory,
nameFieldStringValue: options.suggestedName,
prompt: options.confirmButtonText,
));
return path == null ? null : FileSaveLocation(path);
}

@override
Expand Down
Loading