How can a Flutter desktop app properly access the native operating system's own file system, such as letting a user open or save an actual local file, using the file_picker or similar dedicated packages?
Short answer
Unlike a typical mobile app which is generally quite heavily sandboxed with only fairly limited direct file system access, a genuine desktop application often needs to interact considerably more directly and freely with the actual native file system, and the file_picker package…
Advertisement
AModel answer
Unlike a typical mobile app which is generally quite heavily sandboxed with only fairly limited direct file system access, a genuine desktop application often needs to interact considerably more directly and freely with the actual native file system, and the file_picker package provides a consistent Flutter interface for displaying the operating system's own native file open or save dialog, letting a user genuinely browse their own actual computer's file system to select an existing file to open or to properly choose exactly where a new file should actually be saved to.
final result = await FilePicker.platform.pickFiles();
if (result != null) {
final filePath = result.files.single.path;
final content = await File(filePath!).readAsString();
}Real-world example
A desktop note taking app uses file_picker to let a user open an existing text file directly from anywhere on their own actual computer, and also to properly choose exactly where a newly created note should actually be saved.
Likely follow-ups
- How does file system access actually differ between the more heavily sandboxed macOS App Store version of an app compared to a directly distributed version?
- What genuinely additional permissions might actually be required specifically on macOS for broader file system access?
Related topics