'What's the difference between these two methods of getting the system's temp dir?

From api.flutter.dev:

var systemTempDir = Directory.systemTemp;

From this plugin:

Directory tempDir = await getTemporaryDirectory();
String tempPath = tempDir.path;


Solution 1:[1]

Directory.systemTemp is on iOS at least the more correct path than using path_provider's getTemporaryDirectory() function!

They are very different in how they function.

The Directory.systemTemp; variable returns the /tmp folder for iOS for instance whereas the getTemporaryDirectory() function returns the /Library/Caches value.

If you tried natively in Swift on iOS to get the temporary directory using this code

print(FileManager.default.temporaryDirectory)

You would get the /tmp/ function, which is what the Directory.systemTemp variable returns so this should be the way to go.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vandad Nahavandipoor