I am building a web-app using Flutter that needs to read in a local file supplied by the user. However, currently the file needs to be selected and manually added to the web-app each time the user logs in.
I don't believe it is currently possible to get the local directory path (https://github.com/flutter/flutter/issues/45296) for a file selected on Flutter Web.
Although I thought I'd ask anyway - would it be possible to automatically load the file when the web-app starts?
This would obviously only apply if the file is kept in the same on-device location.
CodePudding user response:
Probably the most simple way is to use shared_preferences. The plugin supports all Flutter platforms.
await prefs.setString('path', path);
...
final String? path = prefs.getString('path');
CodePudding user response:
From my own continued research I have concluded that this is not currently possible for two reasons:
When a file is provided to a browser, the browser does not store the file's actual local path. This (I believe) is primary for security reasons. (Absolute path to a local file in the user computer)
Secondly, I do not believe it would be possible for a web-app to automatically access a file in the user's local directory on startup. This is once again for security purposes - as such permissions could be abused for malicious purposes.
If anyone else has any input on this, it would improve my understanding and be very useful for future readers.