From d1667c0671b03f8c1d94399275959de8a2716018 Mon Sep 17 00:00:00 2001 From: eugerossetto Date: Thu, 13 Oct 2022 12:33:24 -0300 Subject: [PATCH 1/4] Add getDirectoriesPaths method to the file_selector_platform_interface Add getDirectoriesPaths to method channel. Increment version to 2.3.0 apply feedback extract assertion method --- .../method_channel_file_selector_test.dart | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/packages/file_selector/file_selector_platform_interface/test/method_channel_file_selector_test.dart b/packages/file_selector/file_selector_platform_interface/test/method_channel_file_selector_test.dart index 9caa76c02bcb..3dff156606da 100644 --- a/packages/file_selector/file_selector_platform_interface/test/method_channel_file_selector_test.dart +++ b/packages/file_selector/file_selector_platform_interface/test/method_channel_file_selector_test.dart @@ -264,6 +264,33 @@ void main() { ); }); }); + group('#getDirectoryPaths', () { + test('passes initialDirectory correctly', () async { + await plugin.getDirectoryPaths(initialDirectory: '/example/directory'); + + expectMethodCall( + log, + 'getDirectoryPaths', + arguments: { + 'initialDirectory': '/example/directory', + 'confirmButtonText': null, + }, + ); + }); + test('passes confirmButtonText correctly', () async { + await plugin.getDirectoryPaths( + confirmButtonText: 'Select one or more Folders'); + + expectMethodCall( + log, + 'getDirectoryPaths', + arguments: { + 'initialDirectory': null, + 'confirmButtonText': 'Select one or more Folders', + }, + ); + }); + }); }); } From 348b55a92c49fc0a6cfa6809502648d6127fb0ab Mon Sep 17 00:00:00 2001 From: Alejandro Pinola Date: Mon, 17 Oct 2022 11:35:11 -0300 Subject: [PATCH 2/4] add getDirectoryPaths Linux implementation --- .../file_selector_linux/.gitignore | 4 + .../file_selector_linux/CHANGELOG.md | 4 + .../lib/get_multiple_directories_page.dart | 88 +++++++++++++++++++ .../example/lib/home_page.dart | 7 ++ .../file_selector_linux/example/lib/main.dart | 3 + .../file_selector_linux/example/pubspec.yaml | 6 +- .../lib/file_selector_linux.dart | 27 ++++-- .../linux/file_selector_plugin.cc | 6 +- .../linux/test/file_selector_plugin_test.cc | 14 +++ .../file_selector_linux/pubspec.yaml | 6 +- .../test/file_selector_linux_test.dart | 50 ++++++++++- 11 files changed, 199 insertions(+), 16 deletions(-) create mode 100644 packages/file_selector/file_selector_linux/example/lib/get_multiple_directories_page.dart diff --git a/packages/file_selector/file_selector_linux/.gitignore b/packages/file_selector/file_selector_linux/.gitignore index 0393a47ff732..f8596437dd77 100644 --- a/packages/file_selector/file_selector_linux/.gitignore +++ b/packages/file_selector/file_selector_linux/.gitignore @@ -3,3 +3,7 @@ .flutter-plugins .flutter-plugins-dependencies pubspec.lock + +# Linux specific +linux/CMakeFiles +linux/CMakeCache.txt \ No newline at end of file diff --git a/packages/file_selector/file_selector_linux/CHANGELOG.md b/packages/file_selector/file_selector_linux/CHANGELOG.md index a1f57b5cc857..28c4a7c41e7e 100644 --- a/packages/file_selector/file_selector_linux/CHANGELOG.md +++ b/packages/file_selector/file_selector_linux/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.9.0+2 + +* Adds `getDirectoryPaths` implementation. + ## 0.9.0+1 * Changes XTypeGroup initialization from final to const. diff --git a/packages/file_selector/file_selector_linux/example/lib/get_multiple_directories_page.dart b/packages/file_selector/file_selector_linux/example/lib/get_multiple_directories_page.dart new file mode 100644 index 000000000000..1b039954f3a9 --- /dev/null +++ b/packages/file_selector/file_selector_linux/example/lib/get_multiple_directories_page.dart @@ -0,0 +1,88 @@ +// 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. + +import 'package:file_selector_platform_interface/file_selector_platform_interface.dart'; +import 'package:flutter/material.dart'; + +/// Screen that allows the user to select one or more directories using `getDirectoryPaths`, +/// then displays the selected directories in a dialog. +class GetMultipleDirectoriesPage extends StatelessWidget { + /// Default Constructor + const GetMultipleDirectoriesPage({Key? key}) : super(key: key); + + Future _getDirectoryPaths(BuildContext context) async { + const String confirmButtonText = 'Choose'; + final List directoryPaths = + await FileSelectorPlatform.instance.getDirectoryPaths( + confirmButtonText: confirmButtonText, + ); + if (directoryPaths.isEmpty) { + // Operation was canceled by the user. + return; + } + String paths = ''; + for (final String? path in directoryPaths) { + paths += '${path!} \n'; + } + await showDialog( + context: context, + builder: (BuildContext context) => TextDisplay(paths), + ); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('Select multiple directories'), + ), + body: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + ElevatedButton( + style: ElevatedButton.styleFrom( + // TODO(darrenaustin): Migrate to new API once it lands in stable: https://github.com/flutter/flutter/issues/105724 + // ignore: deprecated_member_use + primary: Colors.blue, + // ignore: deprecated_member_use + onPrimary: Colors.white, + ), + child: const Text( + 'Press to ask user to choose multiple directories'), + onPressed: () => _getDirectoryPaths(context), + ), + ], + ), + ), + ); + } +} + +/// Widget that displays a text file in a dialog. +class TextDisplay extends StatelessWidget { + /// Creates a `TextDisplay`. + const TextDisplay(this.directoriesPaths, {Key? key}) : super(key: key); + + /// The path selected in the dialog. + final String directoriesPaths; + + @override + Widget build(BuildContext context) { + return AlertDialog( + title: const Text('Selected Directories'), + content: Scrollbar( + child: SingleChildScrollView( + child: Text(directoriesPaths), + ), + ), + actions: [ + TextButton( + child: const Text('Close'), + onPressed: () => Navigator.pop(context), + ), + ], + ); + } +} diff --git a/packages/file_selector/file_selector_linux/example/lib/home_page.dart b/packages/file_selector/file_selector_linux/example/lib/home_page.dart index a4b2ae1f63ea..7d08c56ad519 100644 --- a/packages/file_selector/file_selector_linux/example/lib/home_page.dart +++ b/packages/file_selector/file_selector_linux/example/lib/home_page.dart @@ -55,6 +55,13 @@ class HomePage extends StatelessWidget { child: const Text('Open a get directory dialog'), onPressed: () => Navigator.pushNamed(context, '/directory'), ), + const SizedBox(height: 10), + ElevatedButton( + style: style, + child: const Text('Open a get multi directories dialog'), + onPressed: () => + Navigator.pushNamed(context, '/multi-directories'), + ), ], ), ), diff --git a/packages/file_selector/file_selector_linux/example/lib/main.dart b/packages/file_selector/file_selector_linux/example/lib/main.dart index 3e447104ef9f..b8f047645a1d 100644 --- a/packages/file_selector/file_selector_linux/example/lib/main.dart +++ b/packages/file_selector/file_selector_linux/example/lib/main.dart @@ -5,6 +5,7 @@ import 'package:flutter/material.dart'; import 'get_directory_page.dart'; +import 'get_multiple_directories_page.dart'; import 'home_page.dart'; import 'open_image_page.dart'; import 'open_multiple_images_page.dart'; @@ -36,6 +37,8 @@ class MyApp extends StatelessWidget { '/open/text': (BuildContext context) => const OpenTextPage(), '/save/text': (BuildContext context) => SaveTextPage(), '/directory': (BuildContext context) => const GetDirectoryPage(), + '/multi-directories': (BuildContext context) => + const GetMultipleDirectoriesPage() }, ); } diff --git a/packages/file_selector/file_selector_linux/example/pubspec.yaml b/packages/file_selector/file_selector_linux/example/pubspec.yaml index 51bdb28717aa..92589eb1cc42 100644 --- a/packages/file_selector/file_selector_linux/example/pubspec.yaml +++ b/packages/file_selector/file_selector_linux/example/pubspec.yaml @@ -1,6 +1,6 @@ name: file_selector_linux_example description: Local testbed for Linux file_selector implementation. -publish_to: 'none' # Remove this line if you wish to publish to pub.dev +publish_to: 'none' version: 1.0.0+1 environment: @@ -9,7 +9,9 @@ environment: dependencies: file_selector_linux: path: ../ - file_selector_platform_interface: ^2.2.0 + # TODO(adpinola): This should be 2.4.0 once it is published. + file_selector_platform_interface: + path: ../../file_selector_platform_interface/ flutter: sdk: flutter diff --git a/packages/file_selector/file_selector_linux/lib/file_selector_linux.dart b/packages/file_selector/file_selector_linux/lib/file_selector_linux.dart index 430b41c398db..b8e3df6a11bd 100644 --- a/packages/file_selector/file_selector_linux/lib/file_selector_linux.dart +++ b/packages/file_selector/file_selector_linux/lib/file_selector_linux.dart @@ -102,13 +102,26 @@ class FileSelectorLinux extends FileSelectorPlatform { String? initialDirectory, String? confirmButtonText, }) async { - return _channel.invokeMethod( - _getDirectoryPathMethod, - { - _initialDirectoryKey: initialDirectory, - _confirmButtonTextKey: confirmButtonText, - }, - ); + final List? path = await _channel + .invokeListMethod(_getDirectoryPathMethod, { + _initialDirectoryKey: initialDirectory, + _confirmButtonTextKey: confirmButtonText, + }); + return path?.first; + } + + @override + Future> getDirectoryPaths({ + String? initialDirectory, + String? confirmButtonText, + }) async { + final List? pathList = await _channel + .invokeListMethod(_getDirectoryPathMethod, { + _initialDirectoryKey: initialDirectory, + _confirmButtonTextKey: confirmButtonText, + _multipleKey: true, + }); + return pathList ?? []; } } diff --git a/packages/file_selector/file_selector_linux/linux/file_selector_plugin.cc b/packages/file_selector/file_selector_linux/linux/file_selector_plugin.cc index 833771955120..5a8cc2132595 100644 --- a/packages/file_selector/file_selector_linux/linux/file_selector_plugin.cc +++ b/packages/file_selector/file_selector_linux/linux/file_selector_plugin.cc @@ -192,10 +192,10 @@ static void method_call_cb(FlMethodChannel* channel, FlMethodCall* method_call, FlValue* args = fl_method_call_get_args(method_call); g_autoptr(FlMethodResponse) response = nullptr; - if (strcmp(method, kOpenFileMethod) == 0) { + if (strcmp(method, kOpenFileMethod) == 0 || + strcmp(method, kGetDirectoryPathMethod) == 0) { response = show_dialog(self, method, args, true); - } else if (strcmp(method, kGetDirectoryPathMethod) == 0 || - strcmp(method, kGetSavePathMethod) == 0) { + } else if (strcmp(method, kGetSavePathMethod) == 0) { response = show_dialog(self, method, args, false); } else { response = FL_METHOD_RESPONSE(fl_method_not_implemented_response_new()); diff --git a/packages/file_selector/file_selector_linux/linux/test/file_selector_plugin_test.cc b/packages/file_selector/file_selector_linux/linux/test/file_selector_plugin_test.cc index 84c55ac91900..8762b4a5f9f6 100644 --- a/packages/file_selector/file_selector_linux/linux/test/file_selector_plugin_test.cc +++ b/packages/file_selector/file_selector_linux/linux/test/file_selector_plugin_test.cc @@ -169,3 +169,17 @@ TEST(FileSelectorPlugin, TestGetDirectory) { EXPECT_EQ(gtk_file_chooser_get_select_multiple(GTK_FILE_CHOOSER(dialog)), false); } + +TEST(FileSelectorPlugin, TestGetMultipleDirectories) { + g_autoptr(FlValue) args = fl_value_new_map(); + fl_value_set_string_take(args, "multiple", fl_value_new_bool(true)); + + g_autoptr(GtkFileChooserNative) dialog = + create_dialog_for_method(nullptr, "getDirectoryPath", args); + + ASSERT_NE(dialog, nullptr); + EXPECT_EQ(gtk_file_chooser_get_action(GTK_FILE_CHOOSER(dialog)), + GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); + EXPECT_EQ(gtk_file_chooser_get_select_multiple(GTK_FILE_CHOOSER(dialog)), + true); +} diff --git a/packages/file_selector/file_selector_linux/pubspec.yaml b/packages/file_selector/file_selector_linux/pubspec.yaml index a8aea37d72e2..85ecdb7da93c 100644 --- a/packages/file_selector/file_selector_linux/pubspec.yaml +++ b/packages/file_selector/file_selector_linux/pubspec.yaml @@ -2,7 +2,7 @@ name: file_selector_linux description: Liunx implementation of the file_selector plugin. repository: https://github.com/flutter/plugins/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.0+1 +version: 0.9.0+2 environment: sdk: ">=2.12.0 <3.0.0" @@ -18,7 +18,9 @@ flutter: dependencies: cross_file: ^0.3.1 - file_selector_platform_interface: ^2.2.0 + # TODO(adpinola): This should be 2.4.0 once it is published. + file_selector_platform_interface: + path: ../file_selector_platform_interface flutter: sdk: flutter diff --git a/packages/file_selector/file_selector_linux/test/file_selector_linux_test.dart b/packages/file_selector/file_selector_linux/test/file_selector_linux_test.dart index 748f922ae6ef..00f6a99a5c73 100644 --- a/packages/file_selector/file_selector_linux/test/file_selector_linux_test.dart +++ b/packages/file_selector/file_selector_linux/test/file_selector_linux_test.dart @@ -373,14 +373,60 @@ void main() { ); }); test('passes confirmButtonText correctly', () async { - await plugin.getDirectoryPath(confirmButtonText: 'Open File'); + await plugin.getDirectoryPath(confirmButtonText: 'Select Folder'); expect( log, [ isMethodCall('getDirectoryPath', arguments: { 'initialDirectory': null, - 'confirmButtonText': 'Open File', + 'confirmButtonText': 'Select Folder', + }), + ], + ); + }); + }); + + group('#getDirectoryPaths', () { + test('passes initialDirectory correctly', () async { + await plugin.getDirectoryPaths(initialDirectory: '/example/directory'); + + expect( + log, + [ + isMethodCall('getDirectoryPath', arguments: { + 'initialDirectory': '/example/directory', + 'confirmButtonText': null, + 'multiple': true, + }), + ], + ); + }); + test('passes confirmButtonText correctly', () async { + await plugin.getDirectoryPaths( + confirmButtonText: 'Select one or mode folders'); + + expect( + log, + [ + isMethodCall('getDirectoryPath', arguments: { + 'initialDirectory': null, + 'confirmButtonText': 'Select one or mode folders', + 'multiple': true, + }), + ], + ); + }); + test('passes multiple flag correctly', () async { + await plugin.getDirectoryPaths(); + + expect( + log, + [ + isMethodCall('getDirectoryPath', arguments: { + 'initialDirectory': null, + 'confirmButtonText': null, + 'multiple': true, }), ], ); From 1dde438ff62b83be3d446fe9141e2a0f3cc7b452 Mon Sep 17 00:00:00 2001 From: Alejandro Pinola Date: Fri, 18 Nov 2022 09:34:38 -0300 Subject: [PATCH 3/4] apply rebase --- .../example/lib/home_page.dart | 2 +- .../file_selector_linux/example/pubspec.yaml | 4 +- .../file_selector_linux/pubspec.yaml | 4 +- .../test/file_selector_linux_test.dart | 367 +++++++++--------- .../method_channel_file_selector_test.dart | 27 -- 5 files changed, 182 insertions(+), 222 deletions(-) diff --git a/packages/file_selector/file_selector_linux/example/lib/home_page.dart b/packages/file_selector/file_selector_linux/example/lib/home_page.dart index 7d08c56ad519..80e16332a017 100644 --- a/packages/file_selector/file_selector_linux/example/lib/home_page.dart +++ b/packages/file_selector/file_selector_linux/example/lib/home_page.dart @@ -58,7 +58,7 @@ class HomePage extends StatelessWidget { const SizedBox(height: 10), ElevatedButton( style: style, - child: const Text('Open a get multi directories dialog'), + child: const Text('Open a get directories dialog'), onPressed: () => Navigator.pushNamed(context, '/multi-directories'), ), diff --git a/packages/file_selector/file_selector_linux/example/pubspec.yaml b/packages/file_selector/file_selector_linux/example/pubspec.yaml index 92589eb1cc42..912a082bd602 100644 --- a/packages/file_selector/file_selector_linux/example/pubspec.yaml +++ b/packages/file_selector/file_selector_linux/example/pubspec.yaml @@ -9,9 +9,7 @@ environment: dependencies: file_selector_linux: path: ../ - # TODO(adpinola): This should be 2.4.0 once it is published. - file_selector_platform_interface: - path: ../../file_selector_platform_interface/ + file_selector_platform_interface: ^2.4.0 flutter: sdk: flutter diff --git a/packages/file_selector/file_selector_linux/pubspec.yaml b/packages/file_selector/file_selector_linux/pubspec.yaml index 85ecdb7da93c..79007e2a6361 100644 --- a/packages/file_selector/file_selector_linux/pubspec.yaml +++ b/packages/file_selector/file_selector_linux/pubspec.yaml @@ -18,9 +18,7 @@ flutter: dependencies: cross_file: ^0.3.1 - # TODO(adpinola): This should be 2.4.0 once it is published. - file_selector_platform_interface: - path: ../file_selector_platform_interface + file_selector_platform_interface: ^2.4.0 flutter: sdk: flutter diff --git a/packages/file_selector/file_selector_linux/test/file_selector_linux_test.dart b/packages/file_selector/file_selector_linux/test/file_selector_linux_test.dart index 00f6a99a5c73..4eae078def0c 100644 --- a/packages/file_selector/file_selector_linux/test/file_selector_linux_test.dart +++ b/packages/file_selector/file_selector_linux/test/file_selector_linux_test.dart @@ -46,57 +46,54 @@ void main() { await plugin.openFile(acceptedTypeGroups: [group, groupTwo]); - expect( + expectMethodCall( log, - [ - isMethodCall('openFile', arguments: { - 'acceptedTypeGroups': >[ - { - 'label': 'text', - 'extensions': ['*.txt'], - 'mimeTypes': ['text/plain'], - }, - { - 'label': 'image', - 'extensions': ['*.jpg'], - 'mimeTypes': ['image/jpg'], - }, - ], - 'initialDirectory': null, - 'confirmButtonText': null, - 'multiple': false, - }), - ], + 'openFile', + arguments: { + 'acceptedTypeGroups': >[ + { + 'label': 'text', + 'extensions': ['*.txt'], + 'mimeTypes': ['text/plain'], + }, + { + 'label': 'image', + 'extensions': ['*.jpg'], + 'mimeTypes': ['image/jpg'], + }, + ], + 'initialDirectory': null, + 'confirmButtonText': null, + 'multiple': false, + }, ); }); test('passes initialDirectory correctly', () async { await plugin.openFile(initialDirectory: '/example/directory'); - expect( + expectMethodCall( log, - [ - isMethodCall('openFile', arguments: { - 'initialDirectory': '/example/directory', - 'confirmButtonText': null, - 'multiple': false, - }), - ], + 'openFile', + arguments: { + 'initialDirectory': '/example/directory', + 'confirmButtonText': null, + 'multiple': false, + }, ); }); test('passes confirmButtonText correctly', () async { await plugin.openFile(confirmButtonText: 'Open File'); - expect( + expectMethodCall( log, - [ - isMethodCall('openFile', arguments: { - 'initialDirectory': null, - 'confirmButtonText': 'Open File', - 'multiple': false, - }), - ], + 'openFile', + arguments: { + 'initialDirectory': null, + 'confirmButtonText': 'Open File', + 'multiple': false, + }, ); }); @@ -118,21 +115,20 @@ void main() { await plugin.openFile(acceptedTypeGroups: [group]); - expect( + expectMethodCall( log, - [ - isMethodCall('openFile', arguments: { - 'acceptedTypeGroups': >[ - { - 'label': 'any', - 'extensions': ['*'], - }, - ], - 'initialDirectory': null, - 'confirmButtonText': null, - 'multiple': false, - }), - ], + 'openFile', + arguments: { + 'acceptedTypeGroups': >[ + { + 'label': 'any', + 'extensions': ['*'], + }, + ], + 'initialDirectory': null, + 'confirmButtonText': null, + 'multiple': false, + }, ); }); }); @@ -156,57 +152,54 @@ void main() { await plugin.openFiles(acceptedTypeGroups: [group, groupTwo]); - expect( + expectMethodCall( log, - [ - isMethodCall('openFile', arguments: { - 'acceptedTypeGroups': >[ - { - 'label': 'text', - 'extensions': ['*.txt'], - 'mimeTypes': ['text/plain'], - }, - { - 'label': 'image', - 'extensions': ['*.jpg'], - 'mimeTypes': ['image/jpg'], - }, - ], - 'initialDirectory': null, - 'confirmButtonText': null, - 'multiple': true, - }), - ], + 'openFile', + arguments: { + 'acceptedTypeGroups': >[ + { + 'label': 'text', + 'extensions': ['*.txt'], + 'mimeTypes': ['text/plain'], + }, + { + 'label': 'image', + 'extensions': ['*.jpg'], + 'mimeTypes': ['image/jpg'], + }, + ], + 'initialDirectory': null, + 'confirmButtonText': null, + 'multiple': true, + }, ); }); test('passes initialDirectory correctly', () async { await plugin.openFiles(initialDirectory: '/example/directory'); - expect( + expectMethodCall( log, - [ - isMethodCall('openFile', arguments: { - 'initialDirectory': '/example/directory', - 'confirmButtonText': null, - 'multiple': true, - }), - ], + 'openFile', + arguments: { + 'initialDirectory': '/example/directory', + 'confirmButtonText': null, + 'multiple': true, + }, ); }); test('passes confirmButtonText correctly', () async { await plugin.openFiles(confirmButtonText: 'Open File'); - expect( + expectMethodCall( log, - [ - isMethodCall('openFile', arguments: { - 'initialDirectory': null, - 'confirmButtonText': 'Open File', - 'multiple': true, - }), - ], + 'openFile', + arguments: { + 'initialDirectory': null, + 'confirmButtonText': 'Open File', + 'multiple': true, + }, ); }); @@ -228,21 +221,20 @@ void main() { await plugin.openFile(acceptedTypeGroups: [group]); - expect( + expectMethodCall( log, - [ - isMethodCall('openFile', arguments: { - 'acceptedTypeGroups': >[ - { - 'label': 'any', - 'extensions': ['*'], - }, - ], - 'initialDirectory': null, - 'confirmButtonText': null, - 'multiple': false, - }), - ], + 'openFile', + arguments: { + 'acceptedTypeGroups': >[ + { + 'label': 'any', + 'extensions': ['*'], + }, + ], + 'initialDirectory': null, + 'confirmButtonText': null, + 'multiple': false, + }, ); }); }); @@ -267,57 +259,54 @@ void main() { await plugin .getSavePath(acceptedTypeGroups: [group, groupTwo]); - expect( + expectMethodCall( log, - [ - isMethodCall('getSavePath', arguments: { - 'acceptedTypeGroups': >[ - { - 'label': 'text', - 'extensions': ['*.txt'], - 'mimeTypes': ['text/plain'], - }, - { - 'label': 'image', - 'extensions': ['*.jpg'], - 'mimeTypes': ['image/jpg'], - }, - ], - 'initialDirectory': null, - 'suggestedName': null, - 'confirmButtonText': null, - }), - ], + 'getSavePath', + arguments: { + 'acceptedTypeGroups': >[ + { + 'label': 'text', + 'extensions': ['*.txt'], + 'mimeTypes': ['text/plain'], + }, + { + 'label': 'image', + 'extensions': ['*.jpg'], + 'mimeTypes': ['image/jpg'], + }, + ], + 'initialDirectory': null, + 'suggestedName': null, + 'confirmButtonText': null, + }, ); }); test('passes initialDirectory correctly', () async { await plugin.getSavePath(initialDirectory: '/example/directory'); - expect( + expectMethodCall( log, - [ - isMethodCall('getSavePath', arguments: { - 'initialDirectory': '/example/directory', - 'suggestedName': null, - 'confirmButtonText': null, - }), - ], + 'getSavePath', + arguments: { + 'initialDirectory': '/example/directory', + 'suggestedName': null, + 'confirmButtonText': null, + }, ); }); test('passes confirmButtonText correctly', () async { await plugin.getSavePath(confirmButtonText: 'Open File'); - expect( + expectMethodCall( log, - [ - isMethodCall('getSavePath', arguments: { - 'initialDirectory': null, - 'suggestedName': null, - 'confirmButtonText': 'Open File', - }), - ], + 'getSavePath', + arguments: { + 'initialDirectory': null, + 'suggestedName': null, + 'confirmButtonText': 'Open File', + }, ); }); @@ -339,21 +328,20 @@ void main() { await plugin.openFile(acceptedTypeGroups: [group]); - expect( + expectMethodCall( log, - [ - isMethodCall('openFile', arguments: { - 'acceptedTypeGroups': >[ - { - 'label': 'any', - 'extensions': ['*'], - }, - ], - 'initialDirectory': null, - 'confirmButtonText': null, - 'multiple': false, - }), - ], + 'openFile', + arguments: { + 'acceptedTypeGroups': >[ + { + 'label': 'any', + 'extensions': ['*'], + }, + ], + 'initialDirectory': null, + 'confirmButtonText': null, + 'multiple': false, + }, ); }); }); @@ -362,27 +350,25 @@ void main() { test('passes initialDirectory correctly', () async { await plugin.getDirectoryPath(initialDirectory: '/example/directory'); - expect( + expectMethodCall( log, - [ - isMethodCall('getDirectoryPath', arguments: { - 'initialDirectory': '/example/directory', - 'confirmButtonText': null, - }), - ], + 'getDirectoryPath', + arguments: { + 'initialDirectory': '/example/directory', + 'confirmButtonText': null, + }, ); }); test('passes confirmButtonText correctly', () async { await plugin.getDirectoryPath(confirmButtonText: 'Select Folder'); - expect( + expectMethodCall( log, - [ - isMethodCall('getDirectoryPath', arguments: { - 'initialDirectory': null, - 'confirmButtonText': 'Select Folder', - }), - ], + 'getDirectoryPath', + arguments: { + 'initialDirectory': null, + 'confirmButtonText': 'Select Folder', + }, ); }); }); @@ -391,45 +377,50 @@ void main() { test('passes initialDirectory correctly', () async { await plugin.getDirectoryPaths(initialDirectory: '/example/directory'); - expect( + expectMethodCall( log, - [ - isMethodCall('getDirectoryPath', arguments: { - 'initialDirectory': '/example/directory', - 'confirmButtonText': null, - 'multiple': true, - }), - ], + 'getDirectoryPath', + arguments: { + 'initialDirectory': '/example/directory', + 'confirmButtonText': null, + 'multiple': true, + }, ); }); test('passes confirmButtonText correctly', () async { await plugin.getDirectoryPaths( confirmButtonText: 'Select one or mode folders'); - expect( + expectMethodCall( log, - [ - isMethodCall('getDirectoryPath', arguments: { - 'initialDirectory': null, - 'confirmButtonText': 'Select one or mode folders', - 'multiple': true, - }), - ], + 'getDirectoryPath', + arguments: { + 'initialDirectory': null, + 'confirmButtonText': 'Select one or mode folders', + 'multiple': true, + }, ); }); test('passes multiple flag correctly', () async { await plugin.getDirectoryPaths(); - expect( + expectMethodCall( log, - [ - isMethodCall('getDirectoryPath', arguments: { - 'initialDirectory': null, - 'confirmButtonText': null, - 'multiple': true, - }), - ], + 'getDirectoryPath', + arguments: { + 'initialDirectory': null, + 'confirmButtonText': null, + 'multiple': true, + }, ); }); }); } + +void expectMethodCall( + List log, + String methodName, { + Map? arguments, +}) { + expect(log, [isMethodCall(methodName, arguments: arguments)]); +} diff --git a/packages/file_selector/file_selector_platform_interface/test/method_channel_file_selector_test.dart b/packages/file_selector/file_selector_platform_interface/test/method_channel_file_selector_test.dart index 3dff156606da..9caa76c02bcb 100644 --- a/packages/file_selector/file_selector_platform_interface/test/method_channel_file_selector_test.dart +++ b/packages/file_selector/file_selector_platform_interface/test/method_channel_file_selector_test.dart @@ -264,33 +264,6 @@ void main() { ); }); }); - group('#getDirectoryPaths', () { - test('passes initialDirectory correctly', () async { - await plugin.getDirectoryPaths(initialDirectory: '/example/directory'); - - expectMethodCall( - log, - 'getDirectoryPaths', - arguments: { - 'initialDirectory': '/example/directory', - 'confirmButtonText': null, - }, - ); - }); - test('passes confirmButtonText correctly', () async { - await plugin.getDirectoryPaths( - confirmButtonText: 'Select one or more Folders'); - - expectMethodCall( - log, - 'getDirectoryPaths', - arguments: { - 'initialDirectory': null, - 'confirmButtonText': 'Select one or more Folders', - }, - ); - }); - }); }); } From ae9ab80514cadd31463c8d967b016323e7c5b90f Mon Sep 17 00:00:00 2001 From: Alejandro Pinola Date: Tue, 22 Nov 2022 10:46:25 -0300 Subject: [PATCH 4/4] update version to 0.9.1 --- packages/file_selector/file_selector_linux/.gitignore | 4 ---- packages/file_selector/file_selector_linux/CHANGELOG.md | 2 +- .../example/lib/get_multiple_directories_page.dart | 6 +----- packages/file_selector/file_selector_linux/linux/.gitignore | 2 ++ packages/file_selector/file_selector_linux/pubspec.yaml | 2 +- 5 files changed, 5 insertions(+), 11 deletions(-) create mode 100644 packages/file_selector/file_selector_linux/linux/.gitignore diff --git a/packages/file_selector/file_selector_linux/.gitignore b/packages/file_selector/file_selector_linux/.gitignore index f8596437dd77..0393a47ff732 100644 --- a/packages/file_selector/file_selector_linux/.gitignore +++ b/packages/file_selector/file_selector_linux/.gitignore @@ -3,7 +3,3 @@ .flutter-plugins .flutter-plugins-dependencies pubspec.lock - -# Linux specific -linux/CMakeFiles -linux/CMakeCache.txt \ No newline at end of file diff --git a/packages/file_selector/file_selector_linux/CHANGELOG.md b/packages/file_selector/file_selector_linux/CHANGELOG.md index 28c4a7c41e7e..70ce307180d8 100644 --- a/packages/file_selector/file_selector_linux/CHANGELOG.md +++ b/packages/file_selector/file_selector_linux/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.9.0+2 +## 0.9.1 * Adds `getDirectoryPaths` implementation. diff --git a/packages/file_selector/file_selector_linux/example/lib/get_multiple_directories_page.dart b/packages/file_selector/file_selector_linux/example/lib/get_multiple_directories_page.dart index 1b039954f3a9..66ab29cfdd9b 100644 --- a/packages/file_selector/file_selector_linux/example/lib/get_multiple_directories_page.dart +++ b/packages/file_selector/file_selector_linux/example/lib/get_multiple_directories_page.dart @@ -21,13 +21,9 @@ class GetMultipleDirectoriesPage extends StatelessWidget { // Operation was canceled by the user. return; } - String paths = ''; - for (final String? path in directoryPaths) { - paths += '${path!} \n'; - } await showDialog( context: context, - builder: (BuildContext context) => TextDisplay(paths), + builder: (BuildContext context) => TextDisplay(directoryPaths.join('\n')), ); } diff --git a/packages/file_selector/file_selector_linux/linux/.gitignore b/packages/file_selector/file_selector_linux/linux/.gitignore new file mode 100644 index 000000000000..83fee186aa98 --- /dev/null +++ b/packages/file_selector/file_selector_linux/linux/.gitignore @@ -0,0 +1,2 @@ +CMakeCache.txt +CMakeFiles/ \ No newline at end of file diff --git a/packages/file_selector/file_selector_linux/pubspec.yaml b/packages/file_selector/file_selector_linux/pubspec.yaml index 79007e2a6361..5aff9493d28f 100644 --- a/packages/file_selector/file_selector_linux/pubspec.yaml +++ b/packages/file_selector/file_selector_linux/pubspec.yaml @@ -2,7 +2,7 @@ name: file_selector_linux description: Liunx implementation of the file_selector plugin. repository: https://github.com/flutter/plugins/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.0+2 +version: 0.9.1 environment: sdk: ">=2.12.0 <3.0.0"