packages
packages copied to clipboard
[shared_preferences] full api redesign with DataStore and cache-less interface
Full rework for shared_preferences, allows user to decide whether to use cache or be fully async and pull direct from the platform.
fixes https://github.com/flutter/flutter/issues/123078 fixes https://github.com/flutter/flutter/issues/133098 fixes https://github.com/flutter/flutter/issues/65145 fixes https://github.com/flutter/flutter/issues/64739
Can I please add to this that support for preferences separated by namespace would be very useful. My app supports multiple accounts and I want the preferences to be distinct for each account.
I could achieve this be prefixing every key but that is awkward and error prone. I then looked into using setPrefix()
but I can't overwrite the prefix after getInstance()
had been called which I need for my app.
If calling setPrefix()
instead rebuilt (or switched) the cache then I think I would be able to use shared_preferences
.
As it stands I have no choice but to roll my own preference handling which is a shame when shared_preferences
is very nearly there for my requirements.
Can I please add to this that support for preferences separated by namespace would be very useful. My app supports multiple accounts and I want the preferences to be distinct for each account.
Please file a new issue to propose new functionality, so that discussion here can remain focused on the review.
Can I please add to this that support for preferences separated by namespace would be very useful. My app supports multiple accounts and I want the preferences to be distinct for each account.
Please file a new issue to propose new functionality, so that discussion here can remain focused on the review.
@stuartmorgan issues are not enabled for this repository, should I open the issue on the main flutter repository?
@stuartmorgan issues are not enabled for this repository, should I open the issue on the main flutter repository?
https://github.com/flutter/packages#issues
@tarrinneal do you have a design doc that I can take a look before reviewing it?
@tarrinneal do you have a design doc that I can take a look before reviewing it?
https://docs.google.com/document/d/1DNhUYIJaDA10g2cOqipKyPuPkgL_FYPfgkF9Coqcc6k/edit
Might have changed the design a bit since I wrote it.
We should probably start brainstorming actual names in parallel with the rest of the review. Maybe AsyncSharedPreferences and CachedSharedPreferences?
CachedSharedPreferences seems incorrect. SharedPreferencesWithCache? I'm fine with either.
(triage): I spoke to @tarrinneal last week and he said this is still on his radar.
It looks like there was a force-push since my last review, so GitHub won't show me the incremental diffs.
There hasn't, probably just a github bug. I think the things that needed review were pretty clear though, since you'd already covered everything
I was able to coax it into showing me some of the recent diffs if I selected them by hand.
@stuartmorgan last chance if you want to do another pass on this now that it's just the front end.
Looks like tests are passing (besides mac flake), going to mark as auto merge!
auto label is removed for flutter/packages/5210, due to - The status or check suite Mac_arm64 ios_platform_tests_shard_1 master has failed. Please fix the issues identified (or deflake) before re-applying this label.
setMockInitialValues
is missing for SharedPreferencesWithCache
setMockInitialValues
is missing for SharedPreferencesWithCache
You can set the cache manually when instantiating SharedPreferencesWithCache
so there is no need for that method.