MultiBlocProvider

@Composable fun Screen.MultiBlocProvider()

or

@Composable fun Screen.BlocProviders()

define multiple BlocProviders to make multiple Blocs available to some composable subtree

The syntax for defining the list of BlocProviders is as follows:

MultiBlocProvider()
    .BlocProvider { scope -> BlocA() }
    .BlocProvider { scope -> BlocB() }
    .forContent { content() }

where content() is a composable function. for which we want the blocs made available

Any number of BlocProviders definitions is supported

The syntax of each BlocProvider in the list is the same as the syntax of a single BlocProvider, that is there are two options:

inline fun <reified BlocA: BlocBase<*>> BlocProvider(
        crossinline create: @DisallowComposableCalls (cscope: CoroutineScope) -> BlocA
    ) 

for creating a Bloc bound the lifecycle of the current Screen, or

inline fun <reified BlocA: BlocBase<*>> BlocProviderExt(
        externallyProvidedBlock:BlocA,
    )

for specifying a Bloc whose lifecycle is managed by some other Screen.

Last updated