rivertion 2.0.0 copy "rivertion: ^2.0.0" to clipboard
rivertion: ^2.0.0 copied to clipboard

Extends riverpod by adding the ability to manipulate data via asynchronous mutations / actions.

Rivertion #

Extends riverpod by adding the ability to manipulate data via asynchronous mutations / actions.

Features #

  • Perform asynchronous data mutations
  • Refresh a provider's when mutation complete

Usage #

Define your mutation:

final addTodo = MutationProvider((ref) {
  return MutationBloc((todo) async {
    await Future.delayed(const Duration(seconds: 2));

    // Call api and add a todo
    _todos = [..._todos, todo];
  });
});

Launch your mutation:

final addTodoState = ref.read(addTodo);

ElevatedButton(
  onPressed: addTodoState.isMutating
      ? null
      : () => ref.read(addTodo.bloc).mutate("New Todo!"),
  child: Text('Add Todo'),
),

Additional information #

Refresh a provider

You can refresh a provider when a mutation ends:

final removeTodo = MutationProvider<String, void>((ref) {
  return MutationBloc((todo) async {
    await Future.delayed(const Duration(seconds: 2)); // Api call
  }, onSuccess: (_, __) async {
    await ref.refresh(todos.future);
  });
});
1
likes
130
pub points
24%
popularity

Publisher

unverified uploader

Extends riverpod by adding the ability to manipulate data via asynchronous mutations / actions.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

bloc, mek_data_class, meta, riverbloc, riverpod, rxdart

More

Packages that depend on rivertion