Skip to content
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

Migration to shared_preferences 2.3 #5534

Open
g123k opened this issue Aug 13, 2024 · 0 comments
Open

Migration to shared_preferences 2.3 #5534

g123k opened this issue Aug 13, 2024 · 0 comments

Comments

@g123k
Copy link
Collaborator

g123k commented Aug 13, 2024

Hi everyone!

With the release of Flutter 3.24, the team also released a new version of the shared_preferences lib.
There's no migration required now, but if I quote the README: Consider migrating existing code to one of the new APIs.

We now have two APIs:

  • SharedPreferencesAsync: a fully async version of the preferences
  • SharedPreferencesWithCache : shared preferences that are loaded on memory
[SharedPreferences] and [SharedPreferencesWithCache] both use a local cache to store preferences. This allows for synchronous get calls after the initial setup call fetches the preferences from the platform.
[...]
[SharedPreferencesAsync] does not utilize a local cache which causes all calls to be asynchronous calls to the host platforms storage solution. This can be less performant, but should always provide the latest data stored on the native platform regardless of what process was used to store it.

I don't fully agree with the less performant statement, as the current implementation will copy all values on memory (even unimportant ones).

Currently, the code mainly relies on a cache-oriented version, as getters are not async (eg: String getImportance(final String attributeId)).

This is an opportunity to optimize the code and split important data that needs to be cached VS non-important one (eg: are crash reports enabled = only used at startup).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 💬 To discuss and validate
Development

No branches or pull requests

2 participants