createBuilder<S, A> static method

dynamic createBuilder<S, A>(
  1. Widget builder(
    1. BuildContext context,
    2. Store<S, A> store
    ),
  2. Widget orElse(
    1. BuildContext context
    )?,
  3. Store<S?, A> store
)

Creates the internal builder that handles null/non-null branching.

Implementation

static createBuilder<S, A>(
  Widget Function(BuildContext context, Store<S, A> store) builder,
  final Widget Function(BuildContext context)? orElse,
  Store<S?, A> store,
) {
  return (state, send, context) {
    if (state == null) {
      return orElse?.call(context) ?? const SizedBox.shrink();
    } else {
      return builder(
        context,
        store.scopeState(toLocalState: (s) => s ?? state),
      );
    }
  };
}