createWhenListener function

void createWhenListener(
  1. Target target
)

create the listener for provider.when filter

Implementation

void createWhenListener(Target target) {
  final cb = target.callback;
  final notifier = target.notifier as StateNotifier;
  target.selectValue = cb(notifier.state, notifier.state);

  // ignore: prefer_function_declarations_over_variables
  final listener = (newState) {
    // rebuild the Consumer using the boolean returned by the callback
    final allowRebuild = cb(notifier.oldState, newState);
    target.selectValue = allowRebuild;
    if (allowRebuild) {
      if (target.rebuild != null) {
        target.rebuild!();
      }
    }
  };
  target.listener = listener;
}