riverpod_stateful_service

Last updated:

0 purchases

riverpod_stateful_service Image
riverpod_stateful_service Images
Add to Cart

Description:

riverpod stateful service

Lightweight stateful_service wrapper for riverpod.
Note: If you're using riverpod_generator, have a look at the riverpod_stateful_service_generator package.
Getting started #
See the stateful_service package documentation for more information on how to get started.
Once you have a StatefulService, you can easily create a Riverpod notifier provider for it:
class UserService extends StatefulService<User> {
...
}

final StatefulServiceNotifierProvider<UserService, User> userProvider = StatefulServiceNotifierProvider((ref) {
return StatefulServiceNotifier(UserService(initialState: const User(name: 'John Doe')));
});
copied to clipboard
You can then use the provider as you would any other Riverpod provider:
Widget build(BuildContext context, WidgetRef ref) {
final user = ref.watch(userProvider);
...
}
copied to clipboard
You can also access the service directly using the included Provider extension, e.g:
Widget build(BuildContext context, WidgetRef ref) {
final userService = ref.watch(userProvider.service);
...
}
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.