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

What is the difference between Directory.systemTemp and getTemporaryDirectory from the path_provider (Flutter package), and in what situations should each be used? #59841

Open
stephane-archer opened this issue Jan 4, 2025 · 4 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-io type-question A question about expected behavior or functionality

Comments

@stephane-archer
Copy link

Both Directory.systemTemp and getTemporaryDirectory are commonly used to access temporary directories in Flutter applications, but they return different paths on some platforms.

This inconsistency can cause confusion for developers trying to decide which one to use.

Understanding why these methods behave differently and in which contexts they are appropriate is crucial for choosing the right tool for temporary file handling in a cross-platform environment.

Witch one should I pick and when?

@stephane-archer stephane-archer changed the title What is the difference between Directory.systemTemp and getTemporaryDirectory from the path_provider Flutter package, and in what situations should each be used? What is the difference between Directory.systemTemp and getTemporaryDirectory from the path_provider (Flutter package), and in what situations should each be used? Jan 4, 2025
@dart-github-bot
Copy link
Collaborator

Summary: User asks about Directory.systemTemp vs. path_provider's getTemporaryDirectory. They want to know the differences and appropriate usage scenarios for each.

@dart-github-bot dart-github-bot added area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-question A question about expected behavior or functionality labels Jan 4, 2025
@lrhn lrhn added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-io and removed area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. labels Jan 4, 2025
@lrhn
Copy link
Member

lrhn commented Jan 6, 2025

The obvious answer is that dart:io's Directory.systemTemp is whatever directory the authors of the VM considers the system tmp-directory on any given supported platform, and path_provider's getTemporaryDirectory is whatever that package's authors consider the tmp-directory on any supported platform.
(It's also non-idiomatically named).

Maybe reasonable people can disagree on what a "tmp-directory" means. Maybe one of them is "more right" than the other where they disagree.

The VM authors here can (maybe) tell what the dart:io design choices were. (Or those choices may predate the current dart:io maintainers.) They may not be able to explain where and why it differs from path_provider.
Might need to ask in both places to get the full story.

I think the biggest difference might be that path_provider is mockable. (But Directory.systemTemp can also be overridden using IOOverrides if you really want to.)

A very quick look does suggest that the VM treats Android as a Linux, with a very small difference, whereas path_provider use the Android cache directory, which is presumably more configurable than "/data/local/tmp".

(My guess is you should use path_provider for everything when writing Flutter apps, and use dart:io only if you're writing stand-alone Dart scripts.)

@stephane-archer
Copy link
Author

Thank @lrhn for looking at this question. Do you know who are the current VM authors? Is this the right repository? More importantly, what was the motivation for path_provider authors to add getTemporaryDirectory? Is this only to be able to mock it easily? I see there are some other (minor?) differences.

@lrhn
Copy link
Member

lrhn commented Jan 6, 2025

You'll have to ask the path_provider authors about their motivation.

The current owners of dart:io should be summoned by the library-io tag 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-io type-question A question about expected behavior or functionality
Projects
None yet
Development

No branches or pull requests

3 participants