This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[file_selector] Add macOS support #4381
Merged
stuartmorgan-g
merged 27 commits into
flutter-team-archive:main
from
stuartmorgan-g:file-selector-macos
Mar 4, 2022
Merged
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
1e97cd4
Initial package import, unchanged
stuartmorgan-g 24d59c5
Initial example import; just paths adjusted
stuartmorgan-g 33a2bd3
Recreate example macOS directory
stuartmorgan-g 3db8122
Metadata and copyright format fixes
stuartmorgan-g 58fda87
Rename plugin class, initial unit test setup
stuartmorgan-g 7ec8b83
Build out test coverage
stuartmorgan-g 662da25
Fix podspec
stuartmorgan-g 5467ffc
Translate to Swift
stuartmorgan-g 9db6ce7
CHANGELOG
stuartmorgan-g c055be9
Exclude from integration tests
stuartmorgan-g 4398038
Fix pubspec order
stuartmorgan-g 72e3357
Change homepage to a path that already exists
stuartmorgan-g a140955
Resync example for changes since forking
stuartmorgan-g daa11d0
README tweak
stuartmorgan-g fb64d05
Merge branch 'master' into file-selector-macos
stuartmorgan-g 36118a3
Fix for new analysis
stuartmorgan-g 8812e88
Merge branch 'flutter:master' into file-selector-macos
stuartmorgan d37ba06
Merge branch 'main' into file-selector-macos
stuartmorgan-g 9e64991
Apply example fixes from Windows review
stuartmorgan-g 0e742ae
Update native test fakes for changes on master
stuartmorgan-g c7f483a
Add in-package platform channel
stuartmorgan-g 3983750
Rework test fakes so they aren't fragile to engine changes
stuartmorgan-g 44d5470
Merge branch 'flutter:main' into file-selector-macos
stuartmorgan e822ac7
Remove pointless test group
stuartmorgan-g a7ed104
Move flattening of allowed types from Swift to Dart
stuartmorgan-g b850177
Merge branch 'main' into file-selector-macos
stuartmorgan-g e867e7e
Review fixes
stuartmorgan-g File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| .dart_tool | ||
| .packages | ||
| .flutter-plugins | ||
| .flutter-plugins-dependencies | ||
| pubspec.lock |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # This file tracks properties of this Flutter project. | ||
| # Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
| # | ||
| # This file should be version controlled and should not be manually edited. | ||
|
|
||
| version: | ||
| revision: 6d1c244b79f3a2747281f718297ce248bd5ad099 | ||
| channel: master | ||
|
|
||
| project_type: plugin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # Below is a list of people and organizations that have contributed | ||
| # to the Flutter project. Names should be added to the list like so: | ||
| # | ||
| # Name/Organization <email address> | ||
|
|
||
| Google Inc. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| ## 0.8.2 | ||
|
|
||
| * Moves source to flutter/plugins. | ||
| * Adds native unit tests. | ||
| * Converts native implementation to Swift. | ||
| * Switches to an internal method channel implementation. | ||
|
|
||
| ## 0.0.4+1 | ||
|
|
||
| * Update README | ||
|
|
||
| ## 0.0.4 | ||
|
|
||
| * Treat empty filter lists the same as null. | ||
|
|
||
| ## 0.0.3 | ||
|
|
||
| * Fix README | ||
|
|
||
| ## 0.0.2 | ||
|
|
||
| * Update SDK constraint to signal compatibility with null safety. | ||
|
|
||
| ## 0.0.1 | ||
|
|
||
| * Initial macOS implementation of `file_selector`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| Copyright 2013 The Flutter Authors. All rights reserved. | ||
|
|
||
| Redistribution and use in source and binary forms, with or without modification, | ||
| are permitted provided that the following conditions are met: | ||
|
|
||
| * Redistributions of source code must retain the above copyright | ||
| notice, this list of conditions and the following disclaimer. | ||
| * Redistributions in binary form must reproduce the above | ||
| copyright notice, this list of conditions and the following | ||
| disclaimer in the documentation and/or other materials provided | ||
| with the distribution. | ||
| * Neither the name of Google Inc. nor the names of its | ||
| contributors may be used to endorse or promote products derived | ||
| from this software without specific prior written permission. | ||
|
|
||
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
| ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
| WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
| ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
| (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
| ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # file\_selector\_macos | ||
|
|
||
| The macOS implementation of [`file_selector`][1]. | ||
|
|
||
| ## Usage | ||
|
|
||
| ### Importing the package | ||
|
|
||
| This implementation has not yet been endorsed, meaning that you need to | ||
| [depend on `file_selector_macos`][2] in addition to | ||
| [depending on `file_selector`][3]. | ||
|
|
||
| Once your pubspec includes the macOS implementation, you can use the | ||
| `file_selector` APIs normally. You should not use the `file_selector_macos` | ||
| APIs directly. | ||
|
|
||
| ### Entitlements | ||
|
|
||
| You will need to [add an entitlement][4] for either read-only access: | ||
| ``` | ||
| <key>com.apple.security.files.user-selected.read-only</key> | ||
| <true/> | ||
| ``` | ||
| or read/write access: | ||
| ``` | ||
| <key>com.apple.security.files.user-selected.read-write</key> | ||
| <true/> | ||
| ``` | ||
| depending on your use case. | ||
|
|
||
| [1]: https://pub.dev/packages/file_selector | ||
| [2]: https://pub.dev/packages/file_selector_macos/install | ||
| [3]: https://pub.dev/packages/file_selector/install | ||
| [4]: https://flutter.dev/desktop#entitlements-and-the-app-sandbox |
48 changes: 48 additions & 0 deletions
48
packages/file_selector/file_selector_macos/example/.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # Miscellaneous | ||
| *.class | ||
| *.log | ||
| *.pyc | ||
| *.swp | ||
| .DS_Store | ||
| .atom/ | ||
| .buildlog/ | ||
| .history | ||
| .svn/ | ||
|
|
||
| # IntelliJ related | ||
| *.iml | ||
| *.ipr | ||
| *.iws | ||
| .idea/ | ||
|
|
||
| # The .vscode folder contains launch configuration and tasks you configure in | ||
| # VS Code which you may wish to be included in version control, so this line | ||
| # is commented out by default. | ||
| #.vscode/ | ||
|
|
||
| # Flutter/Dart/Pub related | ||
| **/doc/api/ | ||
| **/ios/Flutter/.last_build_id | ||
| .dart_tool/ | ||
| .flutter-plugins | ||
| .flutter-plugins-dependencies | ||
| .packages | ||
| .pub-cache/ | ||
| .pub/ | ||
| /build/ | ||
|
|
||
| # Web related | ||
| lib/generated_plugin_registrant.dart | ||
|
|
||
| # Symbolication related | ||
| app.*.symbols | ||
|
|
||
| # Obfuscation related | ||
| app.*.map.json | ||
|
|
||
| # Currently only web supported | ||
| android/ | ||
| ios/ | ||
|
|
||
| # Exceptions to above rules. | ||
| !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages |
10 changes: 10 additions & 0 deletions
10
packages/file_selector/file_selector_macos/example/.metadata
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # This file tracks properties of this Flutter project. | ||
| # Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
| # | ||
| # This file should be version controlled and should not be manually edited. | ||
|
|
||
| version: | ||
| revision: 7736f3bc90270dcb0480db2ccffbf1d13c28db85 | ||
| channel: dev | ||
|
|
||
| project_type: app |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # `file_selector_macos` example | ||
|
|
||
| Demonstrates macOS implementation of the | ||
| [`file_selector` plugin](https://pub.dev/packages/file_selector). |
77 changes: 77 additions & 0 deletions
77
packages/file_selector/file_selector_macos/example/lib/get_directory_page.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| // 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 a directory using `getDirectoryPath`, | ||
| /// then displays the selected directory in a dialog. | ||
| class GetDirectoryPage extends StatelessWidget { | ||
| Future<void> _getDirectoryPath(BuildContext context) async { | ||
| const String confirmButtonText = 'Choose'; | ||
| final String? directoryPath = | ||
| await FileSelectorPlatform.instance.getDirectoryPath( | ||
| confirmButtonText: confirmButtonText, | ||
| ); | ||
| if (directoryPath == null) { | ||
| // Operation was canceled by the user. | ||
| return; | ||
| } | ||
| await showDialog<void>( | ||
| context: context, | ||
| builder: (BuildContext context) => TextDisplay(directoryPath), | ||
| ); | ||
| } | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return Scaffold( | ||
| appBar: AppBar( | ||
| title: const Text('Open a text file'), | ||
| ), | ||
| body: Center( | ||
| child: Column( | ||
| mainAxisAlignment: MainAxisAlignment.center, | ||
| children: <Widget>[ | ||
| ElevatedButton( | ||
| style: ElevatedButton.styleFrom( | ||
| primary: Colors.blue, | ||
| onPrimary: Colors.white, | ||
| ), | ||
| child: const Text('Press to ask user to choose a directory'), | ||
| onPressed: () => _getDirectoryPath(context), | ||
| ), | ||
| ], | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| /// Widget that displays a text file in a dialog. | ||
| class TextDisplay extends StatelessWidget { | ||
| /// Creates a `TextDisplay`. | ||
| const TextDisplay(this.directoryPath); | ||
|
|
||
| /// The path selected in the dialog. | ||
| final String directoryPath; | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return AlertDialog( | ||
| title: const Text('Selected Directory'), | ||
| content: Scrollbar( | ||
| child: SingleChildScrollView( | ||
| child: Text(directoryPath), | ||
| ), | ||
| ), | ||
| actions: <Widget>[ | ||
| TextButton( | ||
| child: const Text('Close'), | ||
| onPressed: () => Navigator.pop(context), | ||
| ), | ||
| ], | ||
| ); | ||
| } | ||
| } | ||
57 changes: 57 additions & 0 deletions
57
packages/file_selector/file_selector_macos/example/lib/home_page.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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. | ||
|
|
||
| import 'package:flutter/material.dart'; | ||
|
|
||
| /// Home Page of the application. | ||
| class HomePage extends StatelessWidget { | ||
| @override | ||
| Widget build(BuildContext context) { | ||
| final ButtonStyle style = ElevatedButton.styleFrom( | ||
| primary: Colors.blue, | ||
| onPrimary: Colors.white, | ||
| ); | ||
| return Scaffold( | ||
| appBar: AppBar( | ||
| title: const Text('File Selector Demo Home Page'), | ||
| ), | ||
| body: Center( | ||
| child: Column( | ||
| mainAxisAlignment: MainAxisAlignment.center, | ||
| children: <Widget>[ | ||
| ElevatedButton( | ||
| style: style, | ||
| child: const Text('Open a text file'), | ||
| onPressed: () => Navigator.pushNamed(context, '/open/text'), | ||
| ), | ||
| const SizedBox(height: 10), | ||
| ElevatedButton( | ||
| style: style, | ||
| child: const Text('Open an image'), | ||
| onPressed: () => Navigator.pushNamed(context, '/open/image'), | ||
| ), | ||
| const SizedBox(height: 10), | ||
| ElevatedButton( | ||
| style: style, | ||
| child: const Text('Open multiple images'), | ||
| onPressed: () => Navigator.pushNamed(context, '/open/images'), | ||
| ), | ||
| const SizedBox(height: 10), | ||
| ElevatedButton( | ||
| style: style, | ||
| child: const Text('Save a file'), | ||
| onPressed: () => Navigator.pushNamed(context, '/save/text'), | ||
| ), | ||
| const SizedBox(height: 10), | ||
| ElevatedButton( | ||
| style: style, | ||
| child: const Text('Open a get directory dialog'), | ||
| onPressed: () => Navigator.pushNamed(context, '/directory'), | ||
| ), | ||
| ], | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
packages/file_selector/file_selector_macos/example/lib/main.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| // 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: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'; | ||
|
|
||
| void main() { | ||
| runApp(MyApp()); | ||
| } | ||
|
|
||
| /// MyApp is the Main Application. | ||
| class MyApp extends StatelessWidget { | ||
| @override | ||
| Widget build(BuildContext context) { | ||
| return MaterialApp( | ||
| title: 'File Selector Demo', | ||
| theme: ThemeData( | ||
| primarySwatch: Colors.blue, | ||
| visualDensity: VisualDensity.adaptivePlatformDensity, | ||
| ), | ||
| home: HomePage(), | ||
| routes: <String, WidgetBuilder>{ | ||
| '/open/image': (BuildContext context) => OpenImagePage(), | ||
| '/open/images': (BuildContext context) => OpenMultipleImagesPage(), | ||
| '/open/text': (BuildContext context) => OpenTextPage(), | ||
| '/save/text': (BuildContext context) => SaveTextPage(), | ||
| '/directory': (BuildContext context) => GetDirectoryPage(), | ||
| }, | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pedantic nit:
s/ then/then/There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.