BlocSelector

BlocSelector with automatically retrieved Bloc

with selector function

@Composable
inline fun <reified BlocA: BlocBase<BlocAState>,BlocAState:Any,BlockSelectedState : Any>
BlocSelector(
    blocTag:String?=null,
    crossinline selectorFn: @DisallowComposableCalls (BlocAState)->BlockSelectedState,
    content:@Composable (BlockSelectedState)->Unit
    )

with AbstractSelector

@Composable
inline fun <reified BlocA: BlocBase<BlocAState>,BlocAState:Any,BlockSelectedState : Any>
 BlocSelector(
    blocTag:String?=null,
    selector:AbstractSelector<BlocAState,BlockSelectedState>,
    content:@Composable (BlockSelectedState)->Unit
    )

BlocSelector is analogous to BlocBuilder but allows to select parts of the full Bloc state, or in general some value derived from one or more fields of the full Bloc state.

This is the value that will be passed to the content composable, and recomposition will be triggered not by change of the full bloc state but instead of this derived value.

An optional blocTag parameter can be specified in order to identify a specific bloc instance in the case where there is more than one instance of a bloc of the same type registered for the current composable subtree (see BlocProvider)

The blocTag parameter is not present in the original flutter_bloc implementation.

For selecting part of the original Bloc state, it is possible to use a selector function selectorFn

or an AbstractSelector

BlocSelector for externally provided Bloc

with selector function

@Composable
inline fun <reified BlocA:BlocBase<BlocAState>,BlocAState:Any,BlockSelectedState:Any>
BlocSelector(
    externallyProvidedBlock:BlocA,
    crossinline selectorFn:@DisallowComposableCalls (BlocAState)->BlockSelectedState,
    content:@Composable (BlockSelectedState)->Unit
    )

with AbstractSelector

@Composable
inline fun <reified BlocA:BlocBase<BlocAState>,BlocAState:Any,BlockSelectedState:Any>
BlocSelector(
    externallyProvidedBlock:BlocA,
    selector:AbstractSelector<BlocAState,BlockSelectedState>,
    content:@Composable (BlockSelectedState)->Unit
    )

These are the same as the previous methods but with an explicitly specified Bloc instance externallyProvidedBlock , not retrieved implicitly from current registered blocs in the current composable subtree.

Use this method if for example you have retrieved the Bloc already with rememberProvidedBlocOf

Last updated