feat(bloc_helper): add wrap feature

This commit is contained in:
Malo Léon 2022-07-14 11:45:47 +01:00
parent e00f4f55b7
commit efda077f4b

View File

@ -36,6 +36,11 @@ abstract class BlocBaseConsumerScreen<B extends BlocBase<S>, S extends Object>
/// must return a widget. /// must return a widget.
Widget onBuild(BuildContext context, S state); Widget onBuild(BuildContext context, S state);
/// The [onWrap] function which will be invoked on each widget build.
/// The [onWrap] takes the `BuildContext`
/// Used to wrap which depends on the state.
Widget onWrap(BuildContext context, Widget child) => child;
/// Takes the `BuildContext` along with the `state` /// Takes the `BuildContext` along with the `state`
/// and is responsible for executing in response to `state` changes. /// and is responsible for executing in response to `state` changes.
void onListen(BuildContext context, S state) {} void onListen(BuildContext context, S state) {}
@ -45,6 +50,6 @@ abstract class BlocBaseConsumerScreen<B extends BlocBase<S>, S extends Object>
listenWhen: shouldListenWhen, listenWhen: shouldListenWhen,
listener: onListen, listener: onListen,
buildWhen: shouldBuildWhen, buildWhen: shouldBuildWhen,
builder: onBuild, builder: (context, state) => onWrap(context, onBuild(context, state)),
); );
} }