notifyWillUpdate method

void notifyWillUpdate({
  1. bool isEqual = false,
})

Notify the observers of the cell that the cell's value will change.

This should be called before the value of the cell has actually changed.

If isEqual is true then only the observers, for which CellObserver.shouldNotifyAlways is true, are notified.

Implementation

void notifyWillUpdate({
  bool isEqual = false,
}) {
  assert(!_isDisposed);

  assert(++_notifyCount > 0, 'Notify count is less than zero at the start of the update cycle.\n\n'
    'This indicates that there have been more calls to CellState.notifyUpdate '
      'than CellState.notifyWillUpdate, in the previous update cycle. The number of '
      'calls to notifyUpdate should match exactly the number of calls to notifyWillUpdate.\n\n'
      'This indicates a bug in Live Cells unless the error originates from a'
      'ValueCell subclass provided by a third party, in which case it indicates'
      "a bug in the third party's code."
  );

  for (final observer in _observers.keys.toList(growable: false)) {
    try {
      if (!isEqual || observer.shouldNotifyAlways) {
        observer.willUpdate(cell);
      }
    }
    catch (e, st) {
      debugPrint('Unhandled exception in CellObserver.willUpdate: $e\n$st');
    }
  }
}