Skip to main content

sinew_riverpod 1.1.0 copy "sinew_riverpod: ^1.1.0" to clipboard
sinew_riverpod: ^1.1.0 copied to clipboard

Riverpod notifier mixins, hooks and AsyncValue conversions for Sinew's presentation pattern.

sinew_riverpod #

pub package License Docs

Riverpod notifier mixins, hooks and AsyncValue conversions for Sinew's presentation pattern.

The presentation pattern of sinew_presentation, as mixins on a Riverpod Notifier. The emitter lives as long as the notifier, so a rebuild keeps it and the page keeps receiving effects.

Features #

  • StateEffectNotifier and EventActionNotifier: setState, emitEffect, onEvent, and the pure mapEventToAction split
  • useOnOpened and useEffects: Flutter Hooks that send "the page opened" once, and listen to effects while the page is mounted
  • ViewStateToAsync and AsyncToViewState: convert between ViewState and Riverpod's AsyncValue

Getting started #

flutter pub add sinew_riverpod

Usage #

A list page in a notifier (from the example app):

class OrderList extends Notifier<OrderListState>
    with
        StateEffectNotifier<OrderListState, Never>,
        EventActionNotifier<OrderListState, OrderListEvent, LoadOrders, Never> {
  late final Pager<Order> _pager = Pager.offset(
    (page, _) => ref.read(orderBackendProvider).orders(page),
    itemKey: (order) => order.id,
  );

  @override
  OrderListState build() => const OrderListState();

  @override
  LoadOrders? mapEventToAction(OrderListEvent event) => switch (event) {
    OrderListOpened() => const LoadOrders(LoadType.initial),
    OrderListEndReached() =>
      state.orders.canLoadMore ? const LoadOrders(LoadType.more) : null,
    OrderListRetryTapped() => LoadOrders(state.orders.retryType),
    OrderListRefreshed() => const LoadOrders(LoadType.refresh),
  };

  @override
  Future<void> onAction(LoadOrders action) => _pager.load(
    action.type,
    state.orders,
    update: (next) => setState((_) => OrderListState(orders: next)),
  );
}

The page calls ref.read(orderListProvider.notifier).onEvent(...).

Sinew is one architecture for Flutter and Kotlin, released as a set of packages at one version.

Documentation #

License #

Apache 2.0, see LICENSE.

0
likes
160
points
183
downloads

Documentation

Documentation
API reference

Publisher

verified publishersrctool.com

Weekly Downloads

Riverpod notifier mixins, hooks and AsyncValue conversions for Sinew's presentation pattern.

Repository (GitHub)
View/report issues
Contributing

Topics

#riverpod #state-management #architecture

License

Apache-2.0 (license)

Dependencies

flutter, flutter_hooks, meta, riverpod, sinew_exception, sinew_models, sinew_presentation

More

Packages that depend on sinew_riverpod