-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[file_selector] Add parameter to control whether the new folders button is visible in the file dialog #9965
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[file_selector] Add parameter to control whether the new folders button is visible in the file dialog #9965
Conversation
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.
Thanks for the contribution!
/// | ||
/// [canCreateDirectories] controls whether the user is allowed to create new | ||
/// directories in the dialog (if supported on the platform). | ||
/// Currently only supported on Linux and macOS. |
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.
The app-facing package has no control over this, so it's subject to becoming stale (and misleading about unendorsed implementations). It should just say that it may not be supported on all platforms.
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.
Agree. I changed the doc so that it infers less about the implementations
Let me know what you think
## NEXT | ||
## 1.1.0 | ||
|
||
* Adds `canCreateDirectories` parameter to `FileDialogOptions` to control the visibility of the New Folder button in file dialogs on supported platforms. |
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.
FileDialogOptions
shouldn't be mentioned at this level, since it's not the public API here.
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.
Makes total sense.
Fixed manually all changelogs
Future<String?> getDirectoryPath({ | ||
String? initialDirectory, | ||
String? confirmButtonText, | ||
bool? canCreateDirectories, |
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.
Why is this nullable? If there there is a distinct third state, it needs to be documented.
const String initialDirectory = '/home/flutteruser'; | ||
const String confirmButtonText = 'Use this profile picture'; | ||
const String suggestedName = 'suggested_name'; | ||
const bool canCreateDirectories = true; |
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.
There's no need for this to be stateful in the tests; values should be local.
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.
This file shouldn't be changed; it's for legacy compat, and legacy implementations won't support new features.
/// file dialog. See [FileDialogOptions] for more details. | ||
/// | ||
/// Returns `null` if the user cancels the operation. | ||
Future<String?> getDirectoryPathWithOptions(FileDialogOptions options) { |
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.
These new methods need Dart unit tests.
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
acceptButtonLabel: confirmButtonText, | ||
currentFolderPath: options.initialDirectory, | ||
acceptButtonLabel: options.confirmButtonText, | ||
createFolders: options.canCreateDirectories, |
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.
Why isn't this added to getSaveLocation
as well?
} | ||
|
||
TEST(FileSelectorPlugin, TestGetDirectory) { | ||
gboolean create_folders = true; |
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.
This should be its own test, not added to existing tests of other things (default options, in the case of this test, multi-select specifically in the case of the next test).
Unit tests are very inexpensive; it is much better to have a lot of unit tests of specific things than a soup of tests where it's hard to understand what each one is supposed to be testing.
prompt: confirmButtonText, | ||
directoryPath: options.initialDirectory, | ||
prompt: options.confirmButtonText, | ||
canCreateDirectories: options.canCreateDirectories, |
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.
Why isn't this in getSaveLocation?
} | ||
} | ||
|
||
if let canCreateDirectories = options.canCreateDirectories { |
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.
This should have corresponding tests in RunnerTests.swift.
Adds a new parameter
canCreateDirectories
toFileDialogOptions
to control the visibility of the New Folder button in file dialogs on supported platforms.Currently only configurable on Linux and macOS
This is the "Combined PR"
Let me know if we are okay with this approach so I can open a new PR covering the interface changes
Fixes: flutter/flutter#141339
Pre-Review Checklist
[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or I have commented below to indicate which version change exemption this PR falls under1.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style, or I have commented below to indicate which CHANGELOG exemption this PR falls under1.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assist
bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2 ↩3