-
Notifications
You must be signed in to change notification settings - Fork 27.7k
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
[shared_preferences] On Web, exception on initialization when a stored value is not valid JSON #156574
Comments
Hi @gdurandrexel, please provide a complete minimal reproducible code sample so that we can properly investigate this. Please also provide the version of Thank you |
I use version 2.2.2. As for a reproducer:
The problem is obvious in the code of |
Is there a reason you are not passing an That said, we do filter unsupported types on iOS/macOS, so silent filtering would be consistent, and from discussion in flutter/packages#5813 I think there's consensus that it's the better option. Anyone interested in completing flutter/packages#5813 is welcome to contribute a new PR. |
Using allowList is cumbersome: I have to track all the keys I use with no real benefit for me. A more general thought: if the package uses a shared storage and does not support all the data types of the storage, it should probably handle gracefully the unsupported data types by default. Asking the user to setup this mechanism explicitly with allowList or prefix or try/catch does not seem right. Also, if for whatever reason a value is not in the expected format, then the whole initialisation fails. In my case I prefer having some of the values (which should be all the ones I created with this package) than none at all. |
@gdurandrexel you found a workaround? |
In one project I just used SharedPreferences instead of SecureStorage (which was creating a plain text entry) to avoid having plain text entries. |
To go futher with this, the meaning of a null
In any case, the initialization must not fail. |
The reason the new APIs don't do that is that there was significant feedback over the years with the old API that people wanted to be able to access values that were not stored by the plugin, especially in add-to-app or migration-from-non-Flutter use cases. The lack of automatic prefixing is an intentional change. |
As I said in my earlier comment:
|
@stuartmorgan I plan to create a PR in the near future. To do this, I need to figure out how to write integration tests. |
@stuartmorgan I did it. If you don't mind, could you take a look, please? |
Steps to reproduce
Create a web project.
In my case, use secure_storage to store some value. It is stored as plain text.
Expected results
The value that cannot be decoded should be ignored.
Actual results
When trying to initialize from this local storage:
I get this exception:
Code sample
Code sample
Screenshots or Video
Screenshots / Video demonstration
[Upload media here]
Logs
Logs
[Paste your logs here]
Flutter Doctor output
Doctor output
The text was updated successfully, but these errors were encountered: