addPage<TBloc> method

void addPage<TBloc>({
  1. required IocContainer container,
  2. required String name,
  3. required TBloc initialState(
    1. Object? arguments
    ),
  4. required Widget pageBody(
    1. BuildContext context
    ),
  5. required void buildBloc(
    1. BlocBuilder<TBloc> blocBuilder,
    2. IocContainer container
    ),
  6. bool onPopPage(
    1. Route route,
    2. dynamic result,
    3. PageArgs pageArgs
    )?,
  7. BlocEvent? initialEvent,
})

Add a page for routing. initialEvent allows you to send an event to the Bloc when the page first loads. Use onPop to cancel pops or clean up the pageScope. Use the blocBuilder to add async and sync bloc handlers to deal with UI changes

Implementation

//ignore: long-parameter-list
void addPage<TBloc>({
  required IocContainer container,
  required String name,
  required TBloc Function(Object? arguments) initialState,
  required Widget Function(BuildContext context) pageBody,
  required void Function(
    BlocBuilder<TBloc> blocBuilder,
    IocContainer container,
  )
      buildBloc,
  bool Function(
    Route<dynamic> route,
    // ignore: avoid_annotating_with_dynamic
    dynamic result,
    PageArgs<dynamic> pageArgs,
  )?
      onPopPage,
  BlocEvent? initialEvent,
}) {
  _addPage(
    name,
    PageBuilder(
      initialEvent: initialEvent,
      builder: pageBody,
      onPopPage: onPopPage,
      blocBuilder: () {
        final blocBuilder = BlocBuilder<TBloc>(initialState);
        buildBloc(blocBuilder, container);

        return blocBuilder;
      },
    ),
  );
}