Skip to content

Conversation

danferreira
Copy link

@danferreira danferreira commented Sep 6, 2025

Adds a new parameter canCreateDirectories to FileDialogOptions 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

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

  1. 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

@danferreira danferreira marked this pull request as ready for review September 6, 2025 22:44
Copy link
Collaborator

@stuartmorgan-g stuartmorgan-g left a 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.
Copy link
Collaborator

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.

Copy link
Author

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.
Copy link
Collaborator

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.

Copy link
Author

@danferreira danferreira Sep 11, 2025

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,
Copy link
Collaborator

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;
Copy link
Collaborator

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.

Copy link
Collaborator

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) {
Copy link
Collaborator

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.

Copy link
Author

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,
Copy link
Collaborator

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;
Copy link
Collaborator

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,
Copy link
Collaborator

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 {
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[file_selector] Do not have create directory button at bottom
2 participants