Closed MostHated closed 3 years ago
The reason why it is able to return data but also throws an error is that data is persisted both in memory and file system. So in your case data was set to in-memory map, but failed to persist. As of windows – you can initialize localstorage with the 2nd argument:
final storage = new LocalStorage('appdata', '/path/to/app/folder');
Make sure your app has write permission to '/path/to/app/folder'
@MostHated let me know if my suggestion helped
Heya, I have not had a chance to give it a try yet. I will try soon and let you know.
Thanks, -MH
I am actually having kind of similar problem.
final LocalStorage localStorage = LocalStorage('key'); await localStorage.setItem('key', 'string');
The error message is
ERROR: Instance of 'PlatformNotSupportedError' package:localstorage/src/directory/io.dart 104:7 DirUtils._getDocumentDir
Can someone please tell me what can I do? I'm totally lost. I've also tried:
final LocalStorage localStorage = LocalStorage('key'); await localStorage.ready; localStorage.setItem('key', 'string');
Because I've seen it done on some sample projects.
But then the error message is:
ERROR: Instance of 'PlatformNotSupportedError' package:localstorage/src/directory/io.dart 104:7 DirUtils._getDocumentDir ===== asynchronous gap =========================== dart:async _asyncErrorWrapperHelper
It seem like it has been fixed in flutter. If your run:
print(await getApplicationDocumentsDirectory());
it will return with your document folder. And storing data in the localStorage will no longer result in an error.
LocalStorage storage = new LocalStorage('yourPageName');
await storage.setItem('key', 'value');
print(storage.getItem('key'));
This has been tested in flutter version: 1.24.0-3.0.pre. I don't know if it has been fixed in release versions.
PlatformNotSupportedError
is raised whenever getApplicationDocumentsDirectory
fails to execute (usually means path_provider
package doesn't support your platform yet)
as a workaround, you can pass a path to the app documents folder as a second argument on your own (it will prevent getApplicationDocumentsDirectory
from being called):
final storage = LocalStorage('storage', '/path/to/app/specific/folder')
Please also avoid creating and using the storage outside of the widget tree (e.g. in void main
).
I recommend creating instances of localstorage inside initState
of any stateful widget)
Hey there,
I was just trying this out today and got the error of:
At the same time, though, I was running this code below: (Don't mind the extra stuff, I was trying to test out FireStoreClient as well to see what kind of data things contained)
So, I am not sure if there actually was an issue, or if it works because it returned the data?
If it doesn't support Windows, is it possible, or worth the effort to somehow use a 3rd party path library along with this? I saw that this one (https://github.com/dart-lang/path) says it has solid support for Windows/Mac/Linux. I am quite new to Dart/Flutter, though (but with a C#/Go background, so picking this up was pretty easy) so I am unfortunately not quite sure if libraries that do not specifically say they are for Flutter will work with it as they should.
(Though, now looking back through that Path repo, it looks like it might now actually allow access to the system, and may only allow you to deal with the path as a string, so that may not be helpful, or an option to begin with)
I do see that this says to have a working Windows implementation https://github.com/google/flutter-desktop-embedding/tree/master/plugins/flutter_plugins/path_provider_fde
Thanks, -MH