flutter_pref
flutter_pref copied to clipboard
Unable to obtain and re-apply defaults used during initialisation
I'd love to be able to conveniently retrieve the defaults provided during initialization so i can "reset to defaults" in my app.
However, it would appear these defaults aren't saved anywhere within the PrefServiceShared
. At first glance i thought no problem, i can just extend PrefServiceShared
, cache my defaults add a getter then i realized PrefServiceShared
is closed for extension. :(
for context:
final service = await PrefServiceShared.init(
defaults: {
'pref_a': 0,
'pref_b': 0,
'pref_c': 5000,
'pref_d': 500,
'pref_e': 4500,
},
);
...
// meanwhile.. in some code far far away..
...
PrefService.of(context).resetToDefaults(); // <<--- new function
// AND/OR
PrefService.of(context).resetToDefault('pref_d'); // <<---- another new function.
...