🧊
compose bloc
  • Overview
  • Setup
  • Differences from adrielcafe/voyager
  • Navigator documentation
    • Navigator Overview
      • Screen
      • ScreenModel
      • Navigator
  • Router and path-based navigation
  • Bloc documentation
    • Bloc and Cubit Overview
      • Cubit
      • Bloc
    • Blocs and Compose Overview
      • BlocProvider
      • MultiBlocProvider
      • BlocBuilder
      • BlocSelector
      • BlocListener
      • BlocConsumer
      • SelectorFor
Powered by GitBook
On this page
  • BlocSelector with automatically retrieved Bloc
  • BlocSelector for externally provided Bloc

Was this helpful?

  1. Bloc documentation
  2. Blocs and Compose Overview

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
    )

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.

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

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.

PreviousBlocBuilderNextBlocListener

Last updated 2 years ago

Was this helpful?

BlocSelector is analogous to 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.

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 )

or an

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

BlocBuilder
BlocProvider
AbstractSelector
rememberProvidedBlocOf