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

[file_selector]Improve API docs and examples #4824

Merged
merged 27 commits into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6c71647
Add detail comment in file_selector
TowaYamashita Feb 13, 2022
b021530
change sample code for file_selector
TowaYamashita Feb 13, 2022
a6cc58f
Update CHAGELOG.md
TowaYamashita Feb 13, 2022
08a3dea
Fix CHANGELOG version
TowaYamashita Feb 13, 2022
2b391d6
Remove const from MyApp() in widget test
TowaYamashita Feb 13, 2022
fe10180
Sort directive sections alphabetically
TowaYamashita Feb 13, 2022
09d9bf8
Update Authors
TowaYamashita Feb 13, 2022
a3a820d
Fix my mailaddress
TowaYamashita Feb 13, 2022
422b133
remove accidentally created test
TowaYamashita Feb 17, 2022
63bbfe8
fix comment of function in file_selector.dart
TowaYamashita Mar 27, 2022
55bd1a5
install path_provider
TowaYamashita Mar 27, 2022
d51b01c
change initial directory to useful example
TowaYamashita Mar 27, 2022
cbed80f
fix not to regress web
TowaYamashita Mar 27, 2022
d9dc0bc
fix typo
TowaYamashita Mar 27, 2022
229657d
fix button labels not to change in example
TowaYamashita Mar 27, 2022
d190b51
fix CHANGELOG.md to follow CHANGELOG style
TowaYamashita Mar 27, 2022
c31eea7
Merge branch 'main' into towayamashita-patch-1
TowaYamashita Mar 27, 2022
750f8b7
Merge branch 'main' into towayamashita-patch-1
stuartmorgan Jun 7, 2022
ef47a7a
Remove some use of initialDirectory, and add comments on the others
stuartmorgan Jun 7, 2022
e0eac1a
Clean up comments
stuartmorgan Jun 7, 2022
bbe266d
Missing newline
stuartmorgan Jun 7, 2022
bd4e16b
Accidentally missed changes
stuartmorgan Jun 7, 2022
fda0ed5
Fix bug in singe-image example
stuartmorgan Jun 7, 2022
e982e74
Convert to code-excerpt
stuartmorgan Jun 7, 2022
28fe8a4
Apply suggestions from code review
stuartmorgan Jun 9, 2022
93a87a5
Merge branch 'main' into towayamashita-patch-1
stuartmorgan Jun 9, 2022
73d596e
Update save example
stuartmorgan Jun 9, 2022
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
1 change: 1 addition & 0 deletions packages/file_selector/file_selector/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ Aleksandr Yurkovskiy <[email protected]>
Anton Borries <[email protected]>
Alex Li <[email protected]>
Rahul Raj <[email protected]>
TowaYamashita <[email protected]>
4 changes: 4 additions & 0 deletions packages/file_selector/file_selector/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## NEXT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is not exempt from version changes; I'm not sure why you've changed this to NEXT since the previous review, but that's incorrect.


* Improve API docs and examples.

## 0.8.4+1

* Adds README information about macOS entitlements.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'dart:io';
import 'package:file_selector/file_selector.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';

/// Screen that shows an example of openFiles
class OpenImagePage extends StatelessWidget {
Expand All @@ -15,8 +16,12 @@ class OpenImagePage extends StatelessWidget {
label: 'images',
extensions: <String>['jpg', 'png'],
);
final List<XFile> files =
await openFiles(acceptedTypeGroups: <XTypeGroup>[typeGroup]);
final String initialDirectory =
(await getApplicationDocumentsDirectory()).path;
final List<XFile> files = await openFiles(
acceptedTypeGroups: <XTypeGroup>[typeGroup],
initialDirectory: initialDirectory,
);
if (files.isEmpty) {
// Operation was canceled by the user.
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'dart:io';
import 'package:file_selector/file_selector.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';

/// Screen that shows an example of openFiles
class OpenMultipleImagesPage extends StatelessWidget {
Expand All @@ -19,10 +20,15 @@ class OpenMultipleImagesPage extends StatelessWidget {
label: 'PNGs',
extensions: <String>['png'],
);
final List<XFile> files = await openFiles(acceptedTypeGroups: <XTypeGroup>[
jpgsTypeGroup,
pngTypeGroup,
]);
final String initialDirectory =
(await getApplicationDocumentsDirectory()).path;
final List<XFile> files = await openFiles(
acceptedTypeGroups: <XTypeGroup>[
jpgsTypeGroup,
pngTypeGroup,
],
initialDirectory: initialDirectory,
);
if (files.isEmpty) {
// Operation was canceled by the user.
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import 'package:file_selector/file_selector.dart';
import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';

/// Screen that shows an example of openFile
class OpenTextPage extends StatelessWidget {
Expand All @@ -12,8 +13,12 @@ class OpenTextPage extends StatelessWidget {
label: 'text',
extensions: <String>['txt', 'json'],
);
final XFile? file =
await openFile(acceptedTypeGroups: <XTypeGroup>[typeGroup]);
final String initialDirectory =
(await getApplicationDocumentsDirectory()).path;
final XFile? file = await openFile(
acceptedTypeGroups: <XTypeGroup>[typeGroup],
initialDirectory: initialDirectory,
);
if (file == null) {
// Operation was canceled by the user.
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,31 @@
import 'dart:typed_data';
import 'package:file_selector/file_selector.dart';
import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';

/// Page for showing an example of saving with file_selector
class SaveTextPage extends StatelessWidget {
final TextEditingController _nameController = TextEditingController();
final TextEditingController _contentController = TextEditingController();

Future<void> _saveFile() async {
final String? path = await getSavePath();
if (path == null) {
// Operation was canceled by the user.
return;
}
stuartmorgan marked this conversation as resolved.
Show resolved Hide resolved
final String text = _contentController.text;
final String fileName = _nameController.text;
final Uint8List fileData = Uint8List.fromList(text.codeUnits);
const String fileMimeType = 'text/plain';
final XFile textFile =
XFile.fromData(fileData, mimeType: fileMimeType, name: fileName);
final String initialDirectory =
(await getApplicationDocumentsDirectory()).path;
final String? path = await getSavePath(
initialDirectory: initialDirectory,
suggestedName: fileName,
);
if (path == null) {
// Operation was canceled by the user.
return;
}

await textFile.saveTo(path);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies:
path: ../
flutter:
sdk: flutter
path_provider: ^2.0.9

dev_dependencies:
flutter_test:
Expand Down
51 changes: 47 additions & 4 deletions packages/file_selector/file_selector/lib/file_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,19 @@ import 'package:file_selector_platform_interface/file_selector_platform_interfac
export 'package:file_selector_platform_interface/file_selector_platform_interface.dart'
show XFile, XTypeGroup;

/// Open file dialog for loading files and return a file path
/// Open file dialog for loading files and return a file path.
stuartmorgan marked this conversation as resolved.
Show resolved Hide resolved
///
/// [acceptedTypeGroups] is the file type that can be selected in the dialog.
/// there are differences in behavior depending on the platform as follows.
stuartmorgan marked this conversation as resolved.
Show resolved Hide resolved
/// - Windows: Each group will be an entry in a list of filter options.
/// - macOS: The union of all types allowed by all of the groups will be allowed.
///
/// [initialDirectory] is the full path to the directory that will be displayed when the dialog is opened.
stuartmorgan marked this conversation as resolved.
Show resolved Hide resolved
///
/// [confirmButtonText] is the text in the confirmation button of the dialog.
/// when omitted, the default OS label. (for example, "Open")
stuartmorgan marked this conversation as resolved.
Show resolved Hide resolved
stuartmorgan marked this conversation as resolved.
Show resolved Hide resolved
///
/// returns `null` if user cancels the operation.
Future<XFile?> openFile({
List<XTypeGroup> acceptedTypeGroups = const <XTypeGroup>[],
String? initialDirectory,
Expand All @@ -21,7 +33,17 @@ Future<XFile?> openFile({
confirmButtonText: confirmButtonText);
}

/// Open file dialog for loading files and return a list of file paths
/// Open file dialog for loading files and return a list of file paths.
stuartmorgan marked this conversation as resolved.
Show resolved Hide resolved
///
/// [acceptedTypeGroups] is the file type that can be selected in the dialog.
/// there are differences in behavior depending on the platform as follows.
stuartmorgan marked this conversation as resolved.
Show resolved Hide resolved
/// - Windows: Each group will be an entry in a list of filter options.
/// - macOS: The union of all types allowed by all of the groups will be allowed.
///
/// [initialDirectory] is the full path to the directory that will be displayed when the dialog is opened.
stuartmorgan marked this conversation as resolved.
Show resolved Hide resolved
///
/// [confirmButtonText] is the text in the confirmation button of the dialog.
/// when omitted, the default OS label. (for example, "Open")
stuartmorgan marked this conversation as resolved.
Show resolved Hide resolved
Future<List<XFile>> openFiles({
stuartmorgan marked this conversation as resolved.
Show resolved Hide resolved
List<XTypeGroup> acceptedTypeGroups = const <XTypeGroup>[],
String? initialDirectory,
Expand All @@ -33,7 +55,21 @@ Future<List<XFile>> openFiles({
confirmButtonText: confirmButtonText);
}

/// Saves File to user's file system
/// Saves File to user's file system.
stuartmorgan marked this conversation as resolved.
Show resolved Hide resolved
///
/// [acceptedTypeGroups] is the file type that can be selected in the dialog.
/// There are differences in behavior depending on the platform as follows.
/// - Windows: Each group will be an entry in a list of filter options.
/// - macOS: The union of all types allowed by all of the groups will be allowed.
stuartmorgan marked this conversation as resolved.
Show resolved Hide resolved
///
/// [initialDirectory] is the full path to the directory that will be displayed when the dialog is opened.
///
/// [suggestedName] is initial value of file name.
stuartmorgan marked this conversation as resolved.
Show resolved Hide resolved
///
/// [confirmButtonText] is the text in the confirmation button of the dialog.
/// when omitted, the default OS label. (for example, "Save")
stuartmorgan marked this conversation as resolved.
Show resolved Hide resolved
///
/// returns `null` if user cancels the operation.
Future<String?> getSavePath({
List<XTypeGroup> acceptedTypeGroups = const <XTypeGroup>[],
String? initialDirectory,
Expand All @@ -47,7 +83,14 @@ Future<String?> getSavePath({
confirmButtonText: confirmButtonText);
}

/// Gets a directory path from a user's file system
/// Gets a directory path from a user's file system.
stuartmorgan marked this conversation as resolved.
Show resolved Hide resolved
///
/// [initialDirectory] is the full path to the directory that will be displayed when the dialog is opened.
///
/// [confirmButtonText] is the text in the confirmation button of the dialog.
/// when omitted, the default OS label. (for example, "Open")
stuartmorgan marked this conversation as resolved.
Show resolved Hide resolved
///
/// returns `null` if user cancels the operation.
stuartmorgan marked this conversation as resolved.
Show resolved Hide resolved
Future<String?> getDirectoryPath({
String? initialDirectory,
String? confirmButtonText,
Expand Down
1 change: 1 addition & 0 deletions packages/file_selector/file_selector/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ description: Flutter plugin for opening and saving files, or selecting
directories, using native file selection UI.
repository: https://github.com/flutter/plugins/tree/main/packages/file_selector/file_selector
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+file_selector%22

stuartmorgan marked this conversation as resolved.
Show resolved Hide resolved
version: 0.8.4+1

environment:
Expand Down