notified_preferences_riverpod 1.0.0 copy "notified_preferences_riverpod: ^1.0.0" to clipboard
notified_preferences_riverpod: ^1.0.0 copied to clipboard

A simple package providing glue methods between notified_preferences and flutter_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,
        );
    }
}

For more guidance, check out notified_preference's page.

0
likes
150
pub points
29%
popularity

Publisher

verified publisherkaiteki.app

A simple package providing glue methods between notified_preferences and flutter_riverpod.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, flutter_riverpod, notified_preferences

More

Packages that depend on notified_preferences_riverpod