From 6c716473a26133fb22206e4588b9cd4170a11387 Mon Sep 17 00:00:00 2001 From: TowaYamashita Date: Sun, 13 Feb 2022 17:01:20 +0900 Subject: [PATCH 01/24] Add detail comment in file_selector --- .../file_selector/lib/file_selector.dart | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/packages/file_selector/file_selector/lib/file_selector.dart b/packages/file_selector/file_selector/lib/file_selector.dart index c2803d60c972..e89ca35cac78 100644 --- a/packages/file_selector/file_selector/lib/file_selector.dart +++ b/packages/file_selector/file_selector/lib/file_selector.dart @@ -10,6 +10,18 @@ export 'package:file_selector_platform_interface/file_selector_platform_interfac show XFile, XTypeGroup; /// Open file dialog for loading files and return a file path +/// +/// The [acceptedTypeGroups] argument is the file type that can be selected in the dialog. +/// When omitted, Open file dialog with all file types. +/// +/// The [initialDirectory] argument is directory that will be displayed when the dialog is opened. +/// (NOTICE: specify a directory as a full path, not a relative path.) +/// When omitted, The result of each platform's `getDirectoryPath()` execution is used. +/// +/// The [confirmButtonText] argument is the text in the confirmation button of the dialog. +/// When omitted, the wording specified in the OS standard is used.(e.g. open) +/// +/// Returns `null` if user cancels the operation. Future openFile({ List acceptedTypeGroups = const [], String? initialDirectory, @@ -22,6 +34,16 @@ Future openFile({ } /// Open file dialog for loading files and return a list of file paths +/// +/// The [acceptedTypeGroups] argument is the file type that can be selected in the dialog. +/// When omitted, Open file dialog with all file types. +/// +/// The [initialDirectory] argument is directory that will be displayed when the dialog is opened. +/// (NOTICE: specify a directory as a full path, not a relative path.) +/// When omitted, The result of each platform's `getDirectoryPath()` execution is used. +/// +/// The [confirmButtonText] argument is the text in the confirmation button of the dialog. +/// When omitted, the wording specified in the OS standard is used.(e.g. open) Future> openFiles({ List acceptedTypeGroups = const [], String? initialDirectory, @@ -34,6 +56,21 @@ Future> openFiles({ } /// Saves File to user's file system +/// +/// The [acceptedTypeGroups] argument is the file type that can be selected in the dialog. +/// When omitted, Open file dialog with all file types. +/// +/// The [initialDirectory] argument is directory that will be displayed when the dialog is opened. +/// (NOTICE: specify a directory as a full path, not a relative path.) +/// When omitted, The result of each platform's `getDirectoryPath()` execution is used. +/// +/// The [suggestedName] argument is he name of the file to save. +/// When omitted, use UUID(version4) as file name. +/// +/// The [confirmButtonText] argument is the text in the confirmation button of the dialog. +/// When omitted, the wording specified in the OS standard is used.(e.g. open) +/// +/// Returns `null` if user cancels the operation. Future getSavePath({ List acceptedTypeGroups = const [], String? initialDirectory, @@ -48,6 +85,15 @@ Future getSavePath({ } /// Gets a directory path from a user's file system +/// +/// The [initialDirectory] argument is directory that will be displayed when the dialog is opened. +/// (NOTICE: specify a directory as a full path, not a relative path.) +/// When omitted, The result of each platform's `getDirectoryPath()` execution is used. +/// +/// The [confirmButtonText] argument is the text in the confirmation button of the dialog. +/// When omitted, the wording specified in the OS standard is used.(e.g. open) +/// +/// Returns `null` if user cancels the operation. Future getDirectoryPath({ String? initialDirectory, String? confirmButtonText, From b0215307b46d547fb0c66491a5bae0531c9b64c2 Mon Sep 17 00:00:00 2001 From: TowaYamashita Date: Sun, 13 Feb 2022 22:17:51 +0900 Subject: [PATCH 02/24] change sample code for file_selector --- .../example/lib/open_image_page.dart | 7 +++-- .../lib/open_multiple_images_page.dart | 12 +++++--- .../example/lib/open_text_page.dart | 7 +++-- .../example/lib/save_text_page.dart | 17 ++++++----- .../example/test/widget_test.dart | 30 +++++++++++++++++++ 5 files changed, 58 insertions(+), 15 deletions(-) create mode 100644 packages/file_selector/file_selector/example/test/widget_test.dart diff --git a/packages/file_selector/file_selector/example/lib/open_image_page.dart b/packages/file_selector/file_selector/example/lib/open_image_page.dart index 0abdba6eb72d..79024d59d863 100644 --- a/packages/file_selector/file_selector/example/lib/open_image_page.dart +++ b/packages/file_selector/file_selector/example/lib/open_image_page.dart @@ -15,8 +15,11 @@ class OpenImagePage extends StatelessWidget { label: 'images', extensions: ['jpg', 'png'], ); - final List files = - await openFiles(acceptedTypeGroups: [typeGroup]); + final List files = await openFiles( + acceptedTypeGroups: [typeGroup], + initialDirectory: '/', + confirmButtonText: 'select image file', + ); if (files.isEmpty) { // Operation was canceled by the user. return; diff --git a/packages/file_selector/file_selector/example/lib/open_multiple_images_page.dart b/packages/file_selector/file_selector/example/lib/open_multiple_images_page.dart index 9a1101214aaa..1284d9d7189c 100644 --- a/packages/file_selector/file_selector/example/lib/open_multiple_images_page.dart +++ b/packages/file_selector/file_selector/example/lib/open_multiple_images_page.dart @@ -19,10 +19,14 @@ class OpenMultipleImagesPage extends StatelessWidget { label: 'PNGs', extensions: ['png'], ); - final List files = await openFiles(acceptedTypeGroups: [ - jpgsTypeGroup, - pngTypeGroup, - ]); + final List files = await openFiles( + acceptedTypeGroups: [ + jpgsTypeGroup, + pngTypeGroup, + ], + initialDirectory: '/', + confirmButtonText: 'select image files', + ); if (files.isEmpty) { // Operation was canceled by the user. return; diff --git a/packages/file_selector/file_selector/example/lib/open_text_page.dart b/packages/file_selector/file_selector/example/lib/open_text_page.dart index 652e8596cf81..b4e13854901c 100644 --- a/packages/file_selector/file_selector/example/lib/open_text_page.dart +++ b/packages/file_selector/file_selector/example/lib/open_text_page.dart @@ -12,8 +12,11 @@ class OpenTextPage extends StatelessWidget { label: 'text', extensions: ['txt', 'json'], ); - final XFile? file = - await openFile(acceptedTypeGroups: [typeGroup]); + final XFile? file = await openFile( + acceptedTypeGroups: [typeGroup], + initialDirectory: '/', + confirmButtonText: 'select text file', + ); if (file == null) { // Operation was canceled by the user. return; diff --git a/packages/file_selector/file_selector/example/lib/save_text_page.dart b/packages/file_selector/file_selector/example/lib/save_text_page.dart index 108ef89b0248..ec29d501da8b 100644 --- a/packages/file_selector/file_selector/example/lib/save_text_page.dart +++ b/packages/file_selector/file_selector/example/lib/save_text_page.dart @@ -12,17 +12,20 @@ class SaveTextPage extends StatelessWidget { final TextEditingController _contentController = TextEditingController(); Future _saveFile() async { - final String? path = await getSavePath(); - if (path == null) { - // Operation was canceled by the user. - return; - } 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 XFile textFile = XFile.fromData(fileData, mimeType: fileMimeType); + final String? path = await getSavePath( + initialDirectory: '/', + suggestedName: fileName, + ); + if (path == null) { + // Operation was canceled by the user. + return; + } + await textFile.saveTo(path); } diff --git a/packages/file_selector/file_selector/example/test/widget_test.dart b/packages/file_selector/file_selector/example/test/widget_test.dart new file mode 100644 index 000000000000..a19dabb076e8 --- /dev/null +++ b/packages/file_selector/file_selector/example/test/widget_test.dart @@ -0,0 +1,30 @@ +// This is a basic Flutter widget test. +// +// To perform an interaction with a widget in your test, use the WidgetTester +// utility that Flutter provides. For example, you can send tap and scroll +// gestures. You can also use WidgetTester to find child widgets in the widget +// tree, read text, and verify that the values of widget properties are correct. + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'package:example/main.dart'; + +void main() { + testWidgets('Counter increments smoke test', (WidgetTester tester) async { + // Build our app and trigger a frame. + await tester.pumpWidget(const MyApp()); + + // Verify that our counter starts at 0. + expect(find.text('0'), findsOneWidget); + expect(find.text('1'), findsNothing); + + // Tap the '+' icon and trigger a frame. + await tester.tap(find.byIcon(Icons.add)); + await tester.pump(); + + // Verify that our counter has incremented. + expect(find.text('0'), findsNothing); + expect(find.text('1'), findsOneWidget); + }); +} From a6cc58ff8d691e3a0b429c9ca5d02aa51d2e5738 Mon Sep 17 00:00:00 2001 From: TowaYamashita Date: Sun, 13 Feb 2022 22:36:08 +0900 Subject: [PATCH 03/24] Update CHAGELOG.md --- packages/file_selector/file_selector/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/file_selector/file_selector/CHANGELOG.md b/packages/file_selector/file_selector/CHANGELOG.md index 65c41651935c..73121b119cdb 100644 --- a/packages/file_selector/file_selector/CHANGELOG.md +++ b/packages/file_selector/file_selector/CHANGELOG.md @@ -1,3 +1,6 @@ +## 0.8.4 +* Improve API docs and examples + ## 0.8.3 * Adds an endorsed Windows implementation. From 08a3deaa8db950dd8d40a8edb7e6f00f90579b11 Mon Sep 17 00:00:00 2001 From: TowaYamashita Date: Sun, 13 Feb 2022 22:55:19 +0900 Subject: [PATCH 04/24] Fix CHANGELOG version --- packages/file_selector/file_selector/CHANGELOG.md | 2 +- packages/file_selector/file_selector/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/file_selector/file_selector/CHANGELOG.md b/packages/file_selector/file_selector/CHANGELOG.md index 73121b119cdb..6247aba03306 100644 --- a/packages/file_selector/file_selector/CHANGELOG.md +++ b/packages/file_selector/file_selector/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.8.4 +## 0.8.3+1 * Improve API docs and examples ## 0.8.3 diff --git a/packages/file_selector/file_selector/pubspec.yaml b/packages/file_selector/file_selector/pubspec.yaml index 41ff35307867..2e71fe4ff066 100644 --- a/packages/file_selector/file_selector/pubspec.yaml +++ b/packages/file_selector/file_selector/pubspec.yaml @@ -3,7 +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 -version: 0.8.3 +version: 0.8.3+1 environment: sdk: ">=2.12.0 <3.0.0" From 2b391d646142fe3a9e639438c12827679a338758 Mon Sep 17 00:00:00 2001 From: TowaYamashita Date: Sun, 13 Feb 2022 22:59:32 +0900 Subject: [PATCH 05/24] Remove const from MyApp() in widget test --- .../file_selector/file_selector/example/test/widget_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/file_selector/file_selector/example/test/widget_test.dart b/packages/file_selector/file_selector/example/test/widget_test.dart index a19dabb076e8..747db1da35e8 100644 --- a/packages/file_selector/file_selector/example/test/widget_test.dart +++ b/packages/file_selector/file_selector/example/test/widget_test.dart @@ -13,7 +13,7 @@ import 'package:example/main.dart'; void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async { // Build our app and trigger a frame. - await tester.pumpWidget(const MyApp()); + await tester.pumpWidget(MyApp()); // Verify that our counter starts at 0. expect(find.text('0'), findsOneWidget); From fe101807694160d2e209d8cabd29cce97ff1168f Mon Sep 17 00:00:00 2001 From: TowaYamashita Date: Sun, 13 Feb 2022 23:08:42 +0900 Subject: [PATCH 06/24] Sort directive sections alphabetically --- .../file_selector/file_selector/example/test/widget_test.dart | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/file_selector/file_selector/example/test/widget_test.dart b/packages/file_selector/file_selector/example/test/widget_test.dart index 747db1da35e8..a01bbe9cd6f7 100644 --- a/packages/file_selector/file_selector/example/test/widget_test.dart +++ b/packages/file_selector/file_selector/example/test/widget_test.dart @@ -5,11 +5,10 @@ // gestures. You can also use WidgetTester to find child widgets in the widget // tree, read text, and verify that the values of widget properties are correct. +import 'package:example/main.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:example/main.dart'; - void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async { // Build our app and trigger a frame. From 09d9bf890768ec2c460b786efcb6828b03925e4e Mon Sep 17 00:00:00 2001 From: TowaYamashita Date: Sun, 13 Feb 2022 23:09:03 +0900 Subject: [PATCH 07/24] Update Authors --- packages/file_selector/file_selector/AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/file_selector/file_selector/AUTHORS b/packages/file_selector/file_selector/AUTHORS index dbf9d190931b..01e1f829aa9d 100644 --- a/packages/file_selector/file_selector/AUTHORS +++ b/packages/file_selector/file_selector/AUTHORS @@ -63,3 +63,4 @@ Aleksandr Yurkovskiy Anton Borries Alex Li Rahul Raj <64.rahulraj@gmail.com> +TowaYamashita <8rine23dev@gmail.com> \ No newline at end of file From a3a820deb575f5d5a2fff2347472071bcc97105a Mon Sep 17 00:00:00 2001 From: TowaYamashita Date: Sun, 13 Feb 2022 23:32:49 +0900 Subject: [PATCH 08/24] Fix my mailaddress --- packages/file_selector/file_selector/AUTHORS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/file_selector/file_selector/AUTHORS b/packages/file_selector/file_selector/AUTHORS index 01e1f829aa9d..596b07bddae7 100644 --- a/packages/file_selector/file_selector/AUTHORS +++ b/packages/file_selector/file_selector/AUTHORS @@ -63,4 +63,4 @@ Aleksandr Yurkovskiy Anton Borries Alex Li Rahul Raj <64.rahulraj@gmail.com> -TowaYamashita <8rine23dev@gmail.com> \ No newline at end of file +TowaYamashita \ No newline at end of file From 422b13320279db8b29bf098fe20950f8e674786d Mon Sep 17 00:00:00 2001 From: TowaYamashita Date: Thu, 17 Feb 2022 22:41:18 +0900 Subject: [PATCH 09/24] remove accidentally created test --- .../example/test/widget_test.dart | 29 ------------------- 1 file changed, 29 deletions(-) delete mode 100644 packages/file_selector/file_selector/example/test/widget_test.dart diff --git a/packages/file_selector/file_selector/example/test/widget_test.dart b/packages/file_selector/file_selector/example/test/widget_test.dart deleted file mode 100644 index a01bbe9cd6f7..000000000000 --- a/packages/file_selector/file_selector/example/test/widget_test.dart +++ /dev/null @@ -1,29 +0,0 @@ -// This is a basic Flutter widget test. -// -// To perform an interaction with a widget in your test, use the WidgetTester -// utility that Flutter provides. For example, you can send tap and scroll -// gestures. You can also use WidgetTester to find child widgets in the widget -// tree, read text, and verify that the values of widget properties are correct. - -import 'package:example/main.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - testWidgets('Counter increments smoke test', (WidgetTester tester) async { - // Build our app and trigger a frame. - await tester.pumpWidget(MyApp()); - - // Verify that our counter starts at 0. - expect(find.text('0'), findsOneWidget); - expect(find.text('1'), findsNothing); - - // Tap the '+' icon and trigger a frame. - await tester.tap(find.byIcon(Icons.add)); - await tester.pump(); - - // Verify that our counter has incremented. - expect(find.text('0'), findsNothing); - expect(find.text('1'), findsOneWidget); - }); -} From 63bbfe8c9a171a9e7fc5422ff51293366544296f Mon Sep 17 00:00:00 2001 From: TowaYamashita Date: Sun, 27 Mar 2022 21:23:23 +0900 Subject: [PATCH 10/24] fix comment of function in file_selector.dart --- .../file_selector/lib/file_selector.dart | 67 +++++++++---------- 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/packages/file_selector/file_selector/lib/file_selector.dart b/packages/file_selector/file_selector/lib/file_selector.dart index e89ca35cac78..3f7bd11ccc3b 100644 --- a/packages/file_selector/file_selector/lib/file_selector.dart +++ b/packages/file_selector/file_selector/lib/file_selector.dart @@ -9,19 +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. /// -/// The [acceptedTypeGroups] argument is the file type that can be selected in the dialog. -/// When omitted, Open file dialog with all file types. +/// [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. /// -/// The [initialDirectory] argument is directory that will be displayed when the dialog is opened. -/// (NOTICE: specify a directory as a full path, not a relative path.) -/// When omitted, The result of each platform's `getDirectoryPath()` execution is used. +/// [initialDirectory] is the full path to the directory that will be displayed when the dialog is opened. /// -/// The [confirmButtonText] argument is the text in the confirmation button of the dialog. -/// When omitted, the wording specified in the OS standard is used.(e.g. open) +/// [confirmButtonText] is the text in the confirmation button of the dialog. +/// when omitted, the default OS label. (for example, "Open") /// -/// Returns `null` if user cancels the operation. +/// returns `null` if user cancels the operation. Future openFile({ List acceptedTypeGroups = const [], String? initialDirectory, @@ -33,17 +33,17 @@ Future 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. /// -/// The [acceptedTypeGroups] argument is the file type that can be selected in the dialog. -/// When omitted, Open file dialog with all file types. +/// [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. /// -/// The [initialDirectory] argument is directory that will be displayed when the dialog is opened. -/// (NOTICE: specify a directory as a full path, not a relative path.) -/// When omitted, The result of each platform's `getDirectoryPath()` execution is used. +/// [initialDirectory] is the full path to the directory that will be displayed when the dialog is opened. /// -/// The [confirmButtonText] argument is the text in the confirmation button of the dialog. -/// When omitted, the wording specified in the OS standard is used.(e.g. open) +/// [confirmButtonText] is the text in the confirmation button of the dialog. +/// when omitted, the default OS label. (for example, "Open") Future> openFiles({ List acceptedTypeGroups = const [], String? initialDirectory, @@ -55,22 +55,21 @@ Future> openFiles({ confirmButtonText: confirmButtonText); } -/// Saves File to user's file system +/// Saves File to user's file system. /// -/// The [acceptedTypeGroups] argument is the file type that can be selected in the dialog. -/// When omitted, Open file dialog with all file types. +/// [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. /// -/// The [initialDirectory] argument is directory that will be displayed when the dialog is opened. -/// (NOTICE: specify a directory as a full path, not a relative path.) -/// When omitted, The result of each platform's `getDirectoryPath()` execution is used. +/// [initialDirectory] is the full path to the directory that will be displayed when the dialog is opened. /// -/// The [suggestedName] argument is he name of the file to save. -/// When omitted, use UUID(version4) as file name. +/// [suggestedName] is initial value of file name. /// -/// The [confirmButtonText] argument is the text in the confirmation button of the dialog. -/// When omitted, the wording specified in the OS standard is used.(e.g. open) +/// [confirmButtonText] is the text in the confirmation button of the dialog. +/// when omitted, the default OS label. (for example, "Open") /// -/// Returns `null` if user cancels the operation. +/// returns `null` if user cancels the operation. Future getSavePath({ List acceptedTypeGroups = const [], String? initialDirectory, @@ -84,16 +83,14 @@ Future getSavePath({ confirmButtonText: confirmButtonText); } -/// Gets a directory path from a user's file system +/// Gets a directory path from a user's file system. /// -/// The [initialDirectory] argument is directory that will be displayed when the dialog is opened. -/// (NOTICE: specify a directory as a full path, not a relative path.) -/// When omitted, The result of each platform's `getDirectoryPath()` execution is used. +/// [initialDirectory] is the full path to the directory that will be displayed when the dialog is opened. /// -/// The [confirmButtonText] argument is the text in the confirmation button of the dialog. -/// When omitted, the wording specified in the OS standard is used.(e.g. open) +/// [confirmButtonText] is the text in the confirmation button of the dialog. +/// when omitted, the default OS label. (for example, "Open") /// -/// Returns `null` if user cancels the operation. +/// returns `null` if user cancels the operation. Future getDirectoryPath({ String? initialDirectory, String? confirmButtonText, From 55bd1a5d66fd9d34e195107946d2da3eec5ef46e Mon Sep 17 00:00:00 2001 From: TowaYamashita Date: Sun, 27 Mar 2022 21:32:31 +0900 Subject: [PATCH 11/24] install path_provider --- packages/file_selector/file_selector/example/pubspec.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/file_selector/file_selector/example/pubspec.yaml b/packages/file_selector/file_selector/example/pubspec.yaml index 531f4790afd0..7ef0736fbcca 100644 --- a/packages/file_selector/file_selector/example/pubspec.yaml +++ b/packages/file_selector/file_selector/example/pubspec.yaml @@ -17,6 +17,7 @@ dependencies: path: ../ flutter: sdk: flutter + path_provider: ^2.0.9 dev_dependencies: flutter_test: From d51b01cc56635e6a290cb0d8062fb26f8d43ac59 Mon Sep 17 00:00:00 2001 From: TowaYamashita Date: Sun, 27 Mar 2022 21:38:01 +0900 Subject: [PATCH 12/24] change initial directory to useful example --- .../file_selector/example/lib/open_image_page.dart | 5 ++++- .../file_selector/example/lib/open_multiple_images_page.dart | 5 ++++- .../file_selector/example/lib/open_text_page.dart | 5 ++++- .../file_selector/example/lib/save_text_page.dart | 5 ++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/file_selector/file_selector/example/lib/open_image_page.dart b/packages/file_selector/file_selector/example/lib/open_image_page.dart index 79024d59d863..b67d4088f521 100644 --- a/packages/file_selector/file_selector/example/lib/open_image_page.dart +++ b/packages/file_selector/file_selector/example/lib/open_image_page.dart @@ -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 { @@ -15,9 +16,11 @@ class OpenImagePage extends StatelessWidget { label: 'images', extensions: ['jpg', 'png'], ); + final String initialDirectory = + (await getApplicationDocumentsDirectory()).path; final List files = await openFiles( acceptedTypeGroups: [typeGroup], - initialDirectory: '/', + initialDirectory: initialDirectory, confirmButtonText: 'select image file', ); if (files.isEmpty) { diff --git a/packages/file_selector/file_selector/example/lib/open_multiple_images_page.dart b/packages/file_selector/file_selector/example/lib/open_multiple_images_page.dart index 1284d9d7189c..9af75b293a60 100644 --- a/packages/file_selector/file_selector/example/lib/open_multiple_images_page.dart +++ b/packages/file_selector/file_selector/example/lib/open_multiple_images_page.dart @@ -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 { @@ -19,12 +20,14 @@ class OpenMultipleImagesPage extends StatelessWidget { label: 'PNGs', extensions: ['png'], ); + final String initialDirectory = + (await getApplicationDocumentsDirectory()).path; final List files = await openFiles( acceptedTypeGroups: [ jpgsTypeGroup, pngTypeGroup, ], - initialDirectory: '/', + initialDirectory: initialDirectory, confirmButtonText: 'select image files', ); if (files.isEmpty) { diff --git a/packages/file_selector/file_selector/example/lib/open_text_page.dart b/packages/file_selector/file_selector/example/lib/open_text_page.dart index b4e13854901c..a449452c8bda 100644 --- a/packages/file_selector/file_selector/example/lib/open_text_page.dart +++ b/packages/file_selector/file_selector/example/lib/open_text_page.dart @@ -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 { @@ -12,9 +13,11 @@ class OpenTextPage extends StatelessWidget { label: 'text', extensions: ['txt', 'json'], ); + final String initialDirectory = + (await getApplicationDocumentsDirectory()).path; final XFile? file = await openFile( acceptedTypeGroups: [typeGroup], - initialDirectory: '/', + initialDirectory: initialDirectory, confirmButtonText: 'select text file', ); if (file == null) { diff --git a/packages/file_selector/file_selector/example/lib/save_text_page.dart b/packages/file_selector/file_selector/example/lib/save_text_page.dart index ec29d501da8b..fdd7a2b2fbd1 100644 --- a/packages/file_selector/file_selector/example/lib/save_text_page.dart +++ b/packages/file_selector/file_selector/example/lib/save_text_page.dart @@ -5,6 +5,7 @@ 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 { @@ -17,8 +18,10 @@ class SaveTextPage extends StatelessWidget { final Uint8List fileData = Uint8List.fromList(text.codeUnits); const String fileMimeType = 'text/plain'; final XFile textFile = XFile.fromData(fileData, mimeType: fileMimeType); + final String initialDirectory = + (await getApplicationDocumentsDirectory()).path; final String? path = await getSavePath( - initialDirectory: '/', + initialDirectory: initialDirectory, suggestedName: fileName, ); if (path == null) { From cbed80f1a0b2458f146777d026f652b5405c454e Mon Sep 17 00:00:00 2001 From: TowaYamashita Date: Sun, 27 Mar 2022 21:41:00 +0900 Subject: [PATCH 13/24] fix not to regress web --- .../file_selector/example/lib/save_text_page.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/file_selector/file_selector/example/lib/save_text_page.dart b/packages/file_selector/file_selector/example/lib/save_text_page.dart index fdd7a2b2fbd1..8b601a421e14 100644 --- a/packages/file_selector/file_selector/example/lib/save_text_page.dart +++ b/packages/file_selector/file_selector/example/lib/save_text_page.dart @@ -17,7 +17,8 @@ class SaveTextPage extends StatelessWidget { 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); + final XFile textFile = + XFile.fromData(fileData, mimeType: fileMimeType, name: fileName); final String initialDirectory = (await getApplicationDocumentsDirectory()).path; final String? path = await getSavePath( From d9dc0bc0134632d42e5e02309adec4725d91f8d4 Mon Sep 17 00:00:00 2001 From: TowaYamashita Date: Sun, 27 Mar 2022 21:56:32 +0900 Subject: [PATCH 14/24] fix typo --- packages/file_selector/file_selector/lib/file_selector.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/file_selector/file_selector/lib/file_selector.dart b/packages/file_selector/file_selector/lib/file_selector.dart index 3f7bd11ccc3b..cfea72d2e032 100644 --- a/packages/file_selector/file_selector/lib/file_selector.dart +++ b/packages/file_selector/file_selector/lib/file_selector.dart @@ -67,7 +67,7 @@ Future> openFiles({ /// [suggestedName] is initial value of file name. /// /// [confirmButtonText] is the text in the confirmation button of the dialog. -/// when omitted, the default OS label. (for example, "Open") +/// when omitted, the default OS label. (for example, "Save") /// /// returns `null` if user cancels the operation. Future getSavePath({ From 229657d7040fb8d175e897949cefc8b0a398c6ca Mon Sep 17 00:00:00 2001 From: TowaYamashita Date: Sun, 27 Mar 2022 22:00:08 +0900 Subject: [PATCH 15/24] fix button labels not to change in example --- .../file_selector/file_selector/example/lib/open_image_page.dart | 1 - .../file_selector/example/lib/open_multiple_images_page.dart | 1 - .../file_selector/file_selector/example/lib/open_text_page.dart | 1 - 3 files changed, 3 deletions(-) diff --git a/packages/file_selector/file_selector/example/lib/open_image_page.dart b/packages/file_selector/file_selector/example/lib/open_image_page.dart index b67d4088f521..ce5880120634 100644 --- a/packages/file_selector/file_selector/example/lib/open_image_page.dart +++ b/packages/file_selector/file_selector/example/lib/open_image_page.dart @@ -21,7 +21,6 @@ class OpenImagePage extends StatelessWidget { final List files = await openFiles( acceptedTypeGroups: [typeGroup], initialDirectory: initialDirectory, - confirmButtonText: 'select image file', ); if (files.isEmpty) { // Operation was canceled by the user. diff --git a/packages/file_selector/file_selector/example/lib/open_multiple_images_page.dart b/packages/file_selector/file_selector/example/lib/open_multiple_images_page.dart index 9af75b293a60..cf39aa87e263 100644 --- a/packages/file_selector/file_selector/example/lib/open_multiple_images_page.dart +++ b/packages/file_selector/file_selector/example/lib/open_multiple_images_page.dart @@ -28,7 +28,6 @@ class OpenMultipleImagesPage extends StatelessWidget { pngTypeGroup, ], initialDirectory: initialDirectory, - confirmButtonText: 'select image files', ); if (files.isEmpty) { // Operation was canceled by the user. diff --git a/packages/file_selector/file_selector/example/lib/open_text_page.dart b/packages/file_selector/file_selector/example/lib/open_text_page.dart index a449452c8bda..d4143b95b34c 100644 --- a/packages/file_selector/file_selector/example/lib/open_text_page.dart +++ b/packages/file_selector/file_selector/example/lib/open_text_page.dart @@ -18,7 +18,6 @@ class OpenTextPage extends StatelessWidget { final XFile? file = await openFile( acceptedTypeGroups: [typeGroup], initialDirectory: initialDirectory, - confirmButtonText: 'select text file', ); if (file == null) { // Operation was canceled by the user. From d190b513b2c7ec7bbbce5a0c12594f4e69743d0a Mon Sep 17 00:00:00 2001 From: TowaYamashita Date: Sun, 27 Mar 2022 22:05:49 +0900 Subject: [PATCH 16/24] fix CHANGELOG.md to follow CHANGELOG style --- packages/file_selector/file_selector/CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/file_selector/file_selector/CHANGELOG.md b/packages/file_selector/file_selector/CHANGELOG.md index 6247aba03306..8380411224e5 100644 --- a/packages/file_selector/file_selector/CHANGELOG.md +++ b/packages/file_selector/file_selector/CHANGELOG.md @@ -1,5 +1,6 @@ -## 0.8.3+1 -* Improve API docs and examples +## NEXT + +* Improve API docs and examples. ## 0.8.3 From ef47a7a4db4ef1bd80f8ac1b96c589341fc5110d Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 7 Jun 2022 10:40:27 -0400 Subject: [PATCH 17/24] Remove some use of initialDirectory, and add comments on the others --- .../file_selector/example/lib/open_image_page.dart | 9 ++------- .../example/lib/open_multiple_images_page.dart | 14 ++++---------- .../file_selector/example/lib/open_text_page.dart | 3 +++ .../file_selector/example/lib/save_text_page.dart | 14 +++++++++----- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/packages/file_selector/file_selector/example/lib/open_image_page.dart b/packages/file_selector/file_selector/example/lib/open_image_page.dart index 5b458283a32d..e520ffb402aa 100644 --- a/packages/file_selector/file_selector/example/lib/open_image_page.dart +++ b/packages/file_selector/file_selector/example/lib/open_image_page.dart @@ -7,7 +7,6 @@ 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 { @@ -19,12 +18,8 @@ class OpenImagePage extends StatelessWidget { label: 'images', extensions: ['jpg', 'png'], ); - final String initialDirectory = - (await getApplicationDocumentsDirectory()).path; - final List files = await openFiles( - acceptedTypeGroups: [typeGroup], - initialDirectory: initialDirectory, - ); + final List files = + await openFiles(acceptedTypeGroups: [typeGroup]); if (files.isEmpty) { // Operation was canceled by the user. return; diff --git a/packages/file_selector/file_selector/example/lib/open_multiple_images_page.dart b/packages/file_selector/file_selector/example/lib/open_multiple_images_page.dart index e43fe784ec27..e2d21c7f04d1 100644 --- a/packages/file_selector/file_selector/example/lib/open_multiple_images_page.dart +++ b/packages/file_selector/file_selector/example/lib/open_multiple_images_page.dart @@ -7,7 +7,6 @@ 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 { @@ -23,15 +22,10 @@ class OpenMultipleImagesPage extends StatelessWidget { label: 'PNGs', extensions: ['png'], ); - final String initialDirectory = - (await getApplicationDocumentsDirectory()).path; - final List files = await openFiles( - acceptedTypeGroups: [ - jpgsTypeGroup, - pngTypeGroup, - ], - initialDirectory: initialDirectory, - ); + final List files = await openFiles(acceptedTypeGroups: [ + jpgsTypeGroup, + pngTypeGroup, + ]); if (files.isEmpty) { // Operation was canceled by the user. return; diff --git a/packages/file_selector/file_selector/example/lib/open_text_page.dart b/packages/file_selector/file_selector/example/lib/open_text_page.dart index cf39b3413f71..057925ed43c2 100644 --- a/packages/file_selector/file_selector/example/lib/open_text_page.dart +++ b/packages/file_selector/file_selector/example/lib/open_text_page.dart @@ -16,6 +16,9 @@ class OpenTextPage extends StatelessWidget { label: 'text', extensions: ['txt', 'json'], ); + // This demonstrates using an initial directory for the prompt, which should + // only be done in cases where the application can likely predict where the + // file would be. In most cases, this parameter should not be provided. final String initialDirectory = (await getApplicationDocumentsDirectory()).path; final XFile? file = await openFile( diff --git a/packages/file_selector/file_selector/example/lib/save_text_page.dart b/packages/file_selector/file_selector/example/lib/save_text_page.dart index fe354c12dad0..257add5b6de8 100644 --- a/packages/file_selector/file_selector/example/lib/save_text_page.dart +++ b/packages/file_selector/file_selector/example/lib/save_text_page.dart @@ -16,12 +16,10 @@ class SaveTextPage extends StatelessWidget { final TextEditingController _contentController = TextEditingController(); Future _saveFile() async { - 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); + // This demonstrates using an initial directory for the prompt, which should + // only be done in cases where the application can likely predict where the + // file will be saved. In most cases, this parameter should not be provided. final String initialDirectory = (await getApplicationDocumentsDirectory()).path; final String? path = await getSavePath( @@ -33,6 +31,12 @@ class SaveTextPage extends StatelessWidget { 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); } From e0eac1a36975b242cbe3443fee921a6b17f1e63a Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 7 Jun 2022 10:49:15 -0400 Subject: [PATCH 18/24] Clean up comments --- .../file_selector/lib/file_selector.dart | 44 ++++++++++++------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/packages/file_selector/file_selector/lib/file_selector.dart b/packages/file_selector/file_selector/lib/file_selector.dart index cfea72d2e032..ae25f0689bfd 100644 --- a/packages/file_selector/file_selector/lib/file_selector.dart +++ b/packages/file_selector/file_selector/lib/file_selector.dart @@ -9,19 +9,23 @@ 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. +/// Opens a file selection dialog and returns the path chosen by the user. /// -/// [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. +/// [acceptedTypeGroups] is a list of file type groups that can be selected in +/// the dialog. How this is displayed depends on the pltaform, for example: +/// - On Windows and Linux, each group will be an entry in a list of filter +/// options. +/// - On 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. +/// [initialDirectory] is the full path to the directory that will be displayed +/// when the dialog is opened. When not provided, the platform will pick an +/// initial location. /// /// [confirmButtonText] is the text in the confirmation button of the dialog. -/// when omitted, the default OS label. (for example, "Open") +/// When not provided, the default OS label is used (for example, "Open"). /// -/// returns `null` if user cancels the operation. +/// Returns `null` if the user cancels the operation. Future openFile({ List acceptedTypeGroups = const [], String? initialDirectory, @@ -40,10 +44,14 @@ Future openFile({ /// - 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. +/// [initialDirectory] is the full path to the directory that will be displayed +/// when the dialog is opened. When not provided, the platform will pick an +/// initial location. /// /// [confirmButtonText] is the text in the confirmation button of the dialog. -/// when omitted, the default OS label. (for example, "Open") +/// When not provided, the default OS label is used (for example, "Open"). +/// +/// Returns an empty list if the user cancels the operation. Future> openFiles({ List acceptedTypeGroups = const [], String? initialDirectory, @@ -62,14 +70,16 @@ Future> openFiles({ /// - 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. +/// [initialDirectory] is the full path to the directory that will be displayed +/// when the dialog is opened. When not provided, the platform will pick an +/// initial location. /// /// [suggestedName] is initial value of file name. /// /// [confirmButtonText] is the text in the confirmation button of the dialog. -/// when omitted, the default OS label. (for example, "Save") +/// When not provided, the default OS label is used (for example, "Save"). /// -/// returns `null` if user cancels the operation. +/// Returns `null` if the user cancels the operation. Future getSavePath({ List acceptedTypeGroups = const [], String? initialDirectory, @@ -85,12 +95,14 @@ Future getSavePath({ /// Gets a directory path from a user's file system. /// -/// [initialDirectory] is the full path to the directory that will be displayed when the dialog is opened. +/// [initialDirectory] is the full path to the directory that will be displayed +/// when the dialog is opened. When not provided, the platform will pick an +/// initial location. /// /// [confirmButtonText] is the text in the confirmation button of the dialog. -/// when omitted, the default OS label. (for example, "Open") +/// When not provided, the default OS label is used (for example, "Open"). /// -/// returns `null` if user cancels the operation. +/// Returns `null` if the user cancels the operation. Future getDirectoryPath({ String? initialDirectory, String? confirmButtonText, From bbe266d67370922da672da63fd0d3616069ebb39 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 7 Jun 2022 10:51:43 -0400 Subject: [PATCH 19/24] Missing newline --- packages/file_selector/file_selector/AUTHORS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/file_selector/file_selector/AUTHORS b/packages/file_selector/file_selector/AUTHORS index 596b07bddae7..94743a9a64ae 100644 --- a/packages/file_selector/file_selector/AUTHORS +++ b/packages/file_selector/file_selector/AUTHORS @@ -63,4 +63,4 @@ Aleksandr Yurkovskiy Anton Borries Alex Li Rahul Raj <64.rahulraj@gmail.com> -TowaYamashita \ No newline at end of file +TowaYamashita From bd4e16b1cacff21faa7e91fc0cbfef192d256bce Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 7 Jun 2022 10:52:49 -0400 Subject: [PATCH 20/24] Accidentally missed changes --- .../file_selector/lib/file_selector.dart | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/file_selector/file_selector/lib/file_selector.dart b/packages/file_selector/file_selector/lib/file_selector.dart index ae25f0689bfd..c21e788603b5 100644 --- a/packages/file_selector/file_selector/lib/file_selector.dart +++ b/packages/file_selector/file_selector/lib/file_selector.dart @@ -37,12 +37,15 @@ Future openFile({ confirmButtonText: confirmButtonText); } -/// Open file dialog for loading files and return a list of file paths. +/// Opens a file selection dialog and returns the list of paths chosen by the +/// user. /// -/// [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. +/// [acceptedTypeGroups] is a list of file type groups that can be selected in +/// the dialog. How this is displayed depends on the pltaform, for example: +/// - On Windows and Linux, each group will be an entry in a list of filter +/// options. +/// - On 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. When not provided, the platform will pick an @@ -63,12 +66,14 @@ Future> openFiles({ confirmButtonText: confirmButtonText); } -/// Saves File to user's file system. +/// Opens a save dialog and returns the target path chosen by the user. /// -/// [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. +/// [acceptedTypeGroups] is a list of file type groups that can be selected in +/// the dialog. How this is displayed depends on the pltaform, for example: +/// - On Windows and Linux, each group will be an entry in a list of filter +/// options. +/// - On 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. When not provided, the platform will pick an @@ -93,7 +98,7 @@ Future getSavePath({ confirmButtonText: confirmButtonText); } -/// Gets a directory path from a user's file system. +/// Opens a directory selection dialog and returns the path chosen by the user. /// /// [initialDirectory] is the full path to the directory that will be displayed /// when the dialog is opened. When not provided, the platform will pick an From fda0ed54089e03f3922f6cf93937437b6c3b731b Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 7 Jun 2022 10:57:50 -0400 Subject: [PATCH 21/24] Fix bug in singe-image example --- .../file_selector/example/lib/open_image_page.dart | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/file_selector/file_selector/example/lib/open_image_page.dart b/packages/file_selector/file_selector/example/lib/open_image_page.dart index e520ffb402aa..9e3da2dd1254 100644 --- a/packages/file_selector/file_selector/example/lib/open_image_page.dart +++ b/packages/file_selector/file_selector/example/lib/open_image_page.dart @@ -18,13 +18,12 @@ class OpenImagePage extends StatelessWidget { label: 'images', extensions: ['jpg', 'png'], ); - final List files = - await openFiles(acceptedTypeGroups: [typeGroup]); - if (files.isEmpty) { + final XFile? file = + await openFile(acceptedTypeGroups: [typeGroup]); + if (file == null) { // Operation was canceled by the user. return; } - final XFile file = files[0]; final String fileName = file.name; final String filePath = file.path; From e982e74892108495aa529c096f1d9393faa1225b Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 7 Jun 2022 11:16:59 -0400 Subject: [PATCH 22/24] Convert to code-excerpt --- .../file_selector/file_selector/README.md | 47 +++++++++++---- .../file_selector/example/build.excerpt.yaml | 15 +++++ .../file_selector/example/lib/main.dart | 13 +++-- .../example/lib/open_image_page.dart | 2 + .../lib/open_multiple_images_page.dart | 2 + .../lib/readme_standalone_excerpts.dart | 57 +++++++++++++++++++ .../file_selector/example/pubspec.yaml | 3 +- .../windows/flutter/generated_plugins.cmake | 8 +++ script/configs/temp_exclude_excerpt.yaml | 1 - 9 files changed, 130 insertions(+), 18 deletions(-) create mode 100644 packages/file_selector/file_selector/example/build.excerpt.yaml create mode 100644 packages/file_selector/file_selector/example/lib/readme_standalone_excerpts.dart diff --git a/packages/file_selector/file_selector/README.md b/packages/file_selector/file_selector/README.md index 89cac1e6fd5f..d48dd2491b0d 100644 --- a/packages/file_selector/file_selector/README.md +++ b/packages/file_selector/file_selector/README.md @@ -1,5 +1,7 @@ # file_selector + + [![pub package](https://img.shields.io/pub/v/file_selector.svg)](https://pub.dartlang.org/packages/file_selector) A Flutter plugin that manages files and interactions with file dialogs. @@ -30,25 +32,50 @@ Here are small examples that show you how to use the API. Please also take a look at our [example][example] app. #### Open a single file + ``` dart -final typeGroup = XTypeGroup(label: 'images', extensions: ['jpg', 'png']); -final file = await openFile(acceptedTypeGroups: [typeGroup]); +final XTypeGroup typeGroup = XTypeGroup( + label: 'images', + extensions: ['jpg', 'png'], +); +final XFile? file = + await openFile(acceptedTypeGroups: [typeGroup]); ``` #### Open multiple files at once + ``` dart -final typeGroup = XTypeGroup(label: 'images', extensions: ['jpg', 'png']); -final files = await openFiles(acceptedTypeGroups: [typeGroup]); +final XTypeGroup jpgsTypeGroup = XTypeGroup( + label: 'JPEGs', + extensions: ['jpg', 'jpeg'], +); +final XTypeGroup pngTypeGroup = XTypeGroup( + label: 'PNGs', + extensions: ['png'], +); +final List files = await openFiles(acceptedTypeGroups: [ + jpgsTypeGroup, + pngTypeGroup, +]); ``` #### Saving a file + ```dart -final path = await getSavePath(); -final name = "hello_file_selector.txt"; -final data = Uint8List.fromList("Hello World!".codeUnits); -final mimeType = "text/plain"; -final file = XFile.fromData(data, name: name, mimeType: mimeType); -await file.saveTo(path); +import 'dart:typed_data'; +// ··· + const String fileName = 'suggested_name.txt'; + final String? path = await getSavePath(suggestedName: fileName); + if (path == null) { + // Operation was canceled by the user. + return; + } + + final Uint8List fileData = Uint8List.fromList('Hello World!'.codeUnits); + const String mimeType = 'text/plain'; + final XFile textFile = + XFile.fromData(fileData, mimeType: mimeType, name: fileName); + await textFile.saveTo(path); ``` [example]:./example diff --git a/packages/file_selector/file_selector/example/build.excerpt.yaml b/packages/file_selector/file_selector/example/build.excerpt.yaml new file mode 100644 index 000000000000..e317efa11cb3 --- /dev/null +++ b/packages/file_selector/file_selector/example/build.excerpt.yaml @@ -0,0 +1,15 @@ +targets: + $default: + sources: + include: + - lib/** + # Some default includes that aren't really used here but will prevent + # false-negative warnings: + - $package$ + - lib/$lib$ + exclude: + - '**/.*/**' + - '**/build/**' + builders: + code_excerpter|code_excerpter: + enabled: true diff --git a/packages/file_selector/file_selector/example/lib/main.dart b/packages/file_selector/file_selector/example/lib/main.dart index 34f5857ab0bc..d05e80f1b755 100644 --- a/packages/file_selector/file_selector/example/lib/main.dart +++ b/packages/file_selector/file_selector/example/lib/main.dart @@ -2,14 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:example/get_directory_page.dart'; -import 'package:example/home_page.dart'; -import 'package:example/open_image_page.dart'; -import 'package:example/open_multiple_images_page.dart'; -import 'package:example/open_text_page.dart'; -import 'package:example/save_text_page.dart'; import 'package:flutter/material.dart'; +import 'get_directory_page.dart'; +import 'home_page.dart'; +import 'open_image_page.dart'; +import 'open_multiple_images_page.dart'; +import 'open_text_page.dart'; +import 'save_text_page.dart'; + void main() { runApp(const MyApp()); } diff --git a/packages/file_selector/file_selector/example/lib/open_image_page.dart b/packages/file_selector/file_selector/example/lib/open_image_page.dart index 9e3da2dd1254..4fb06864c570 100644 --- a/packages/file_selector/file_selector/example/lib/open_image_page.dart +++ b/packages/file_selector/file_selector/example/lib/open_image_page.dart @@ -14,12 +14,14 @@ class OpenImagePage extends StatelessWidget { const OpenImagePage({Key? key}) : super(key: key); Future _openImageFile(BuildContext context) async { + // #docregion SingleOpen final XTypeGroup typeGroup = XTypeGroup( label: 'images', extensions: ['jpg', 'png'], ); final XFile? file = await openFile(acceptedTypeGroups: [typeGroup]); + // #enddocregion SingleOpen if (file == null) { // Operation was canceled by the user. return; diff --git a/packages/file_selector/file_selector/example/lib/open_multiple_images_page.dart b/packages/file_selector/file_selector/example/lib/open_multiple_images_page.dart index e2d21c7f04d1..ac3d66fc955c 100644 --- a/packages/file_selector/file_selector/example/lib/open_multiple_images_page.dart +++ b/packages/file_selector/file_selector/example/lib/open_multiple_images_page.dart @@ -14,6 +14,7 @@ class OpenMultipleImagesPage extends StatelessWidget { const OpenMultipleImagesPage({Key? key}) : super(key: key); Future _openImageFile(BuildContext context) async { + // #docregion MultiOpen final XTypeGroup jpgsTypeGroup = XTypeGroup( label: 'JPEGs', extensions: ['jpg', 'jpeg'], @@ -26,6 +27,7 @@ class OpenMultipleImagesPage extends StatelessWidget { jpgsTypeGroup, pngTypeGroup, ]); + // #enddocregion MultiOpen if (files.isEmpty) { // Operation was canceled by the user. return; diff --git a/packages/file_selector/file_selector/example/lib/readme_standalone_excerpts.dart b/packages/file_selector/file_selector/example/lib/readme_standalone_excerpts.dart new file mode 100644 index 000000000000..48b6fbbdb772 --- /dev/null +++ b/packages/file_selector/file_selector/example/lib/readme_standalone_excerpts.dart @@ -0,0 +1,57 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This file exists solely to host compiled excerpts for README.md, and is not +// intended for use as an actual example application. + +// ignore_for_file: public_member_api_docs + +// #docregion Save +import 'dart:typed_data'; +// #enddocregion Save + +import 'package:file_selector/file_selector.dart'; +import 'package:flutter/material.dart'; + +void main() { + runApp(const MyApp()); +} + +class MyApp extends StatefulWidget { + const MyApp({Key? key}) : super(key: key); + + @override + State createState() => _MyAppState(); +} + +class _MyAppState extends State { + @override + Widget build(BuildContext context) { + return MaterialApp( + home: Scaffold( + appBar: AppBar( + title: const Text('README snippet app'), + ), + body: const Text('See example in main.dart'), + ), + ); + } + + Future saveFile() async { + // #docregion Save + const String fileName = 'suggested_name.txt'; + final String? path = await getSavePath(suggestedName: fileName); + if (path == null) { + // Operation was canceled by the user. + return; + } + + final Uint8List fileData = Uint8List.fromList('Hello World!'.codeUnits); + const String mimeType = 'text/plain'; + final XFile textFile = + XFile.fromData(fileData, mimeType: mimeType, name: fileName); + await textFile.saveTo(path); + // #enddocregion Save + } +} diff --git a/packages/file_selector/file_selector/example/pubspec.yaml b/packages/file_selector/file_selector/example/pubspec.yaml index 7ef0736fbcca..011d95874ae4 100644 --- a/packages/file_selector/file_selector/example/pubspec.yaml +++ b/packages/file_selector/file_selector/example/pubspec.yaml @@ -1,4 +1,4 @@ -name: example +name: file_selector_example description: A new Flutter project. publish_to: none @@ -20,6 +20,7 @@ dependencies: path_provider: ^2.0.9 dev_dependencies: + build_runner: ^2.1.10 flutter_test: sdk: flutter diff --git a/packages/file_selector/file_selector/example/windows/flutter/generated_plugins.cmake b/packages/file_selector/file_selector/example/windows/flutter/generated_plugins.cmake index 63eda9b7b59f..a423a02476a2 100644 --- a/packages/file_selector/file_selector/example/windows/flutter/generated_plugins.cmake +++ b/packages/file_selector/file_selector/example/windows/flutter/generated_plugins.cmake @@ -6,6 +6,9 @@ list(APPEND FLUTTER_PLUGIN_LIST file_selector_windows ) +list(APPEND FLUTTER_FFI_PLUGIN_LIST +) + set(PLUGIN_BUNDLED_LIBRARIES) foreach(plugin ${FLUTTER_PLUGIN_LIST}) @@ -14,3 +17,8 @@ foreach(plugin ${FLUTTER_PLUGIN_LIST}) list(APPEND PLUGIN_BUNDLED_LIBRARIES $) list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) endforeach(plugin) + +foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) + add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin}) + list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) +endforeach(ffi_plugin) diff --git a/script/configs/temp_exclude_excerpt.yaml b/script/configs/temp_exclude_excerpt.yaml index bd73880ee5ee..dec99ee6edd9 100644 --- a/script/configs/temp_exclude_excerpt.yaml +++ b/script/configs/temp_exclude_excerpt.yaml @@ -7,7 +7,6 @@ # https://github.com/flutter/flutter/issues/102679 - camera_web - espresso -- file_selector/file_selector - google_maps_flutter/google_maps_flutter - google_sign_in/google_sign_in - google_sign_in_web From 28fe8a45eac5fef5901bf757aaf827860187f11c Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Thu, 9 Jun 2022 15:40:55 -0400 Subject: [PATCH 23/24] Apply suggestions from code review Co-authored-by: David Iglesias --- packages/file_selector/file_selector/lib/file_selector.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/file_selector/file_selector/lib/file_selector.dart b/packages/file_selector/file_selector/lib/file_selector.dart index c21e788603b5..322ae6cda483 100644 --- a/packages/file_selector/file_selector/lib/file_selector.dart +++ b/packages/file_selector/file_selector/lib/file_selector.dart @@ -20,10 +20,11 @@ export 'package:file_selector_platform_interface/file_selector_platform_interfac /// /// [initialDirectory] is the full path to the directory that will be displayed /// when the dialog is opened. When not provided, the platform will pick an -/// initial location. +/// initial location. This is ignored on the Web platform. /// /// [confirmButtonText] is the text in the confirmation button of the dialog. /// When not provided, the default OS label is used (for example, "Open"). +/// This is ignored on the Web platform. /// /// Returns `null` if the user cancels the operation. Future openFile({ @@ -99,6 +100,7 @@ Future getSavePath({ } /// Opens a directory selection dialog and returns the path chosen by the user. +/// This always returns `null` on the web. /// /// [initialDirectory] is the full path to the directory that will be displayed /// when the dialog is opened. When not provided, the platform will pick an From 73d596e3fbf16dc010f0f7d641024b57169f068c Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Thu, 9 Jun 2022 15:41:54 -0400 Subject: [PATCH 24/24] Update save example --- .../file_selector/file_selector/README.md | 24 +++++++++---------- .../lib/readme_standalone_excerpts.dart | 4 ++-- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/packages/file_selector/file_selector/README.md b/packages/file_selector/file_selector/README.md index d48dd2491b0d..f5c1de8afebc 100644 --- a/packages/file_selector/file_selector/README.md +++ b/packages/file_selector/file_selector/README.md @@ -62,20 +62,18 @@ final List files = await openFiles(acceptedTypeGroups: [ #### Saving a file ```dart -import 'dart:typed_data'; -// ··· - const String fileName = 'suggested_name.txt'; - final String? path = await getSavePath(suggestedName: fileName); - if (path == null) { - // Operation was canceled by the user. - return; - } +const String fileName = 'suggested_name.txt'; +final String? path = await getSavePath(suggestedName: fileName); +if (path == null) { + // Operation was canceled by the user. + return; +} - final Uint8List fileData = Uint8List.fromList('Hello World!'.codeUnits); - const String mimeType = 'text/plain'; - final XFile textFile = - XFile.fromData(fileData, mimeType: mimeType, name: fileName); - await textFile.saveTo(path); +final Uint8List fileData = Uint8List.fromList('Hello World!'.codeUnits); +const String mimeType = 'text/plain'; +final XFile textFile = + XFile.fromData(fileData, mimeType: mimeType, name: fileName); +await textFile.saveTo(path); ``` [example]:./example diff --git a/packages/file_selector/file_selector/example/lib/readme_standalone_excerpts.dart b/packages/file_selector/file_selector/example/lib/readme_standalone_excerpts.dart index 48b6fbbdb772..c67c93fa63f2 100644 --- a/packages/file_selector/file_selector/example/lib/readme_standalone_excerpts.dart +++ b/packages/file_selector/file_selector/example/lib/readme_standalone_excerpts.dart @@ -7,9 +7,9 @@ // ignore_for_file: public_member_api_docs -// #docregion Save +// TODO(a14n): remove this import once Flutter 3.1 or later reaches stable (including flutter/flutter#104231) +// ignore: unnecessary_import import 'dart:typed_data'; -// #enddocregion Save import 'package:file_selector/file_selector.dart'; import 'package:flutter/material.dart';