Last updated:
0 purchases
notified preferences riverpod
notified_preferences_riverpod #
A simple package providing glue methods between notified_preferences and flutter_riverpod.
Usage #
Use it like any other provider. Make sure you provide setup an instance of SharedPreferences on startup of your app.
final preferencesProvider =
Provider<SharedPreferences>((_) => throw UnimplementedError());
final hasSeenTutorialProvider =
createSettingProvider(key: 'hasSeenTutorial', initialValue: false);
void main() {
final preferences = await SharedPreferences.getInstance();
runApp(
ProviderScope(
overrides: [
preferencesProvider.overrideWith((_) => preferences),
],
child: const App(),
),
);
}
class App extends ConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
final hasSeenTutorial = ref.watch(hasSeenTutorialProvider).value;
if (!hasSeenTutorial) return Text("Hello!");
return OutlinedButton(
child: Text("Exit tutorial"),
onPressed: () => ref.read(hasSeenTutorialProvider).value = true,
);
}
}
copied to clipboard
For more guidance, check out notified_preference's page.
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.