Skip to content

path_provider getDownloadsDirectory documentation doesn't say when it might return null #143238

Closed
flutter/packages
#11793

Description

@Hixie

The getDownloadsDirectory function is defined as potentially returning null. The documentation talks about it potentially throwing an UnsupportedError if this is not supported on the current platform, and talks about the returned Directory maybe not existing, but doesn't say when it might return null. So it's not clear if this is a failure mode that one should handle, or what to do when it happens.

https://pub.dev/documentation/path_provider/latest/path_provider/getDownloadsDirectory.html

Activity

  1. added
    p: path_providerPlugin that provides resolved paths to some platform directories
    on Feb 9, 2024
  2. added
    packageflutter/packages repository. See also p: labels.
    P2Important issues not at the top of the work list
    on Feb 9, 2024
  3. stuartmorgan-g commented on Feb 9, 2024

    @stuartmorgan-g
    Contributor

    The intent is that UnsupportedError is for platforms that don't implement this at all (e.g., a platform that has no concept of a download directory), while null would mean that the implementation understands the concept, but that there's no such directory available.

    That distinction is probably not worth handling two different ways, especially since the null case should be very rare, so we could consider changing all the currently nullable methods to be non-nullable, and convert nulls from the platform interface to MissingPlatformDirectoryException (and then documenting that).

  4. Hixie commented on Feb 9, 2024

    @Hixie
    ContributorAuthor

    The docs also refer to the possibility of the path being valid but not existing, that's distinct from the case of the path not being available?

  5. stuartmorgan-g commented on Feb 9, 2024

    @stuartmorgan-g
    Contributor

    Yes; for instance on Linux you could configure your XDG settings to say your Download directory is ~/thisdirectoryhasneverexisted, and then path_provider would return that valid but non-existent path.

  6. Hixie commented on Feb 10, 2024

    @Hixie
    ContributorAuthor

    What's an example of the path not being available? Something like Linux when no downloads directory has been configured at all?

  7. stuartmorgan-g commented on Feb 10, 2024

    @stuartmorgan-g
    Contributor

    Right now you could get it by running on a Linux without xdg-user-dir, or where that exists but fails when called.

    In theory iOS/macOS could return an empty array from the search, but I would be pretty surprised if that's possible in practice.

  8. Hixie commented on Feb 10, 2024

    @Hixie
    ContributorAuthor

    Cool. Those details would be great to include in the docs. Thanks for the explanations!

  9. familan commented on May 1, 2025

    @familan
  10. stuartmorgan-g commented on May 1, 2025

    @stuartmorgan-g
    Contributor

    @familan Please file a new issue; the example is separate from the Dart docs.

  11. theprantadutta commented on May 15, 2026

    @theprantadutta
    Contributor

    Hi @stuartmorgan-g @Hixie — would it be useful if I took this on? The maintainer responses upthread already lay out exactly what to add. My plan:

    1. Update the dartdoc on getDownloadsDirectory in path_provider/lib/path_provider.dart and the matching method on PathProviderPlatform in path_provider_platform_interface to explain:
      • UnsupportedError is thrown when the platform has no concept of a "downloads directory"
      • null is returned when the platform supports the concept but no such directory is available (concrete example: Linux without xdg-user-dir configured, or where it fails when called)
      • the returned Directory may not exist (the existing case, e.g. an XDG-configured directory pointing somewhere non-existent)
    2. Skip the README/example tangent — that's tracked separately per @stuartmorgan-g's earlier note.

    Happy to defer if someone's already on this. Otherwise I'll open a PR and link back here.

  12. added a commit that references this issue on Jun 15, 2026
    aa964a3
  13. github-actions commented on Jul 14, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  14. locked as resolved and limited conversation to collaborators on Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listp: path_providerPlugin that provides resolved paths to some platform directoriespackageflutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions