sinew_riverpod 1.1.0
sinew_riverpod: ^1.1.0 copied to clipboard
Riverpod notifier mixins, hooks and AsyncValue conversions for Sinew's presentation pattern.
sinew_riverpod #
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 #
StateEffectNotifierandEventActionNotifier:setState,emitEffect,onEvent, and the puremapEventToActionsplituseOnOpenedanduseEffects: Flutter Hooks that send "the page opened" once, and listen to effects while the page is mountedViewStateToAsyncandAsyncToViewState: convert betweenViewStateand Riverpod'sAsyncValue
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(...).
Related packages #
Sinew is one architecture for Flutter and Kotlin, released as a set of packages at one version.
Documentation #
- Usage docs: sinew.srctool.com
- API reference: pub.dev/documentation/sinew_riverpod
- Source and issues: srctool/sinew-dart
- Design and decisions: the Guide
License #
Apache 2.0, see LICENSE.