flutter_pref icon indicating copy to clipboard operation
flutter_pref copied to clipboard

Unable to obtain and re-apply defaults used during initialisation

Open dylanhillier opened this issue 7 months ago • 0 comments

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.
...

dylanhillier avatar Jul 07 '24 11:07 dylanhillier