Skip to content
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

Allow allowedExtensions to Support Any Custom File Format Without Predefined Restrictions #1658

Open
vicajilau opened this issue Dec 28, 2024 · 3 comments
Labels
suggestion New feature or request

Comments

@vicajilau
Copy link

vicajilau commented Dec 28, 2024

Problem Statement

Currently, the allowedExtensions parameter in flutter_file_picker is subject to a predefined list of supported file formats. This restricts the ability of developers to handle completely custom file types that may not be included in the predefined list, such as proprietary formats (e.g., .maso).

This limitation forces developers to either:

  • Work around the library by post-filtering the files after selection.
  • Fork the library to support their specific needs.

Proposed Solution

Make allowedExtensions fully customizable by allowing any string as an extension. Instead of validating against a predefined list, the package could directly pass the provided extensions to the underlying platform implementation.


Expected Behavior

Developers should be able to provide any valid string as an extension in the allowedExtensions parameter, such as:

FilePickerResult? result = await FilePicker.platform.pickFiles(
  type: FileType.custom,
  allowedExtensions: ['maso', 'xyz', 'customformat'],
);

This should enable filtering for the specified custom file types without restrictions.


Benefits

  • Supports proprietary and less common file types.
  • Enhances flexibility for diverse application scenarios.
  • Reduces the need for workarounds or modifications to the library.
@vicajilau vicajilau added the suggestion New feature or request label Dec 28, 2024
@MrCsabaToth
Copy link

I had problems before where I wanted to only import CSV and had to resort to let everything fly: TrackMyIndoorWorkout/TrackMyIndoorWorkout@6157af1
Now I realize that I cannot pick any file whatsoever with that file picker either from my Google Drive or my local Download of my phone.

@vicajilau
Copy link
Author

vicajilau commented Jan 8, 2025

Yes @MrCsabaToth, I have applied the same solution. Letting the users can select any type of file and handle in Dart to search in the path if it is correct or not.

if (!filePath.endsWith(".csv")) {
      throw FileInvalidException("The loaded file is not a CSV file.");
}

But in my opinion this is an avoidable boilerplate. I don't see why there should be a list of supported file formats instead of supporting a custom format that can be dynamically configured by the developer.

@MrCsabaToth
Copy link

Yes @MrCsabaToth, I have applied the same solution. Letting the users can select any type of file and handle in Dart to search in the path if it is correct or not.

if (!filePath.endsWith(".csv")) {
      throw FileInvalidException("The loaded file is not a CSV file.");
}

But in my opinion this is an avoidable boilerplate. I don't see why there should be a list of supported file formats instead of supporting a custom format that can be dynamically configured by the developer.

My problem is that now no matter what I do I don't get back any file which was selected. Nada. Nuku. Zilch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
suggestion New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants