onInputsChange property
This callback will be called when ever the inputs change.
This will receive the current BlocType
, the previous inputs and the new inputs.
Use this callback to update the BLoC (e.g. call some method) instead of the default behavior of creating a new BLoC instance.
The returned bool signals whether the BLoC has been updated successfully with the new inputs,
or whether a new instance should be created from scratch.
Return true
for not recreating the BLoC, so you have handled the change of inputs.
For recreating the BLoC, return false
.
This allows you to handle different input changes differently, e.g.: {@tool sample}
WithBloc(
createBloc: () => Bloc(),
inputs: [locale, isVip],
onInputsChange: (bloc, {previousInputs, newInputs}) {
if (previousInputs.first != newInputs.first) {
return true;
}
bloc.updateVip(isVip);
return false
}
),
{@end-tool}
Implementation
final bool Function(
BlocType bloc, {
List previousInputs,
List newInputs,
})? onInputsChange;