dartway_shared_preferences 0.1.1
dartway_shared_preferences: ^0.1.1 copied to clipboard
Shared-preferences plugin for DartWay: typed riverpod providers over local storage, reached as dw.plugins.prefs. Optional by design.
Example — a reactive preference #
Declare the plugin once:
DwFlutter(
config: DwConfig(/* ... */),
plugins: [DwSharedPreferences()],
);
Then a stored value is a provider the UI watches like any other:
final darkModeProvider = dw.plugins.prefs.provider<bool>(
key: 'darkMode',
defaultValue: false,
);
class DarkModeSwitch extends ConsumerWidget {
const DarkModeSwitch({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final darkMode = ref.watch(darkModeProvider);
return Switch(
value: darkMode,
onChanged: (value) =>
ref.read(darkModeProvider.notifier).update(value),
);
}
}
The switch reflects storage and writes to it; no manual read/write, no reload. For a value that
isn't a primitive, mappedProvider maps it to and from a String; for a one-off read, reach the
underlying store with dw.plugins.prefs.raw.