build method

  1. @override
Widget build()
override

Subclasses should override this function to actually call the appropriate build function (e.g., StatelessWidget.build or State.build) for their widget.

Implementation

@override
Widget build() {
  final notifyData = NotifyData(
    updater: getUpdate,
    unmountDisposers: _unmountDisposers,
    throwException: true,
  );

  final result = Notifier.instance.append(notifyData, super.build);

  final currentNotifiers = notifyData.readNotifiers;

  // Unsubscribe from notifiers that are no longer read
  _subscriptions.removeWhere((notifier, disposer) {
    if (!currentNotifiers.contains(notifier)) {
      disposer();
      return true;
    }
    return false;
  });

  // Subscribe to newly read notifiers
  for (final notifier in currentNotifiers) {
    if (!_subscriptions.containsKey(notifier)) {
      notifier.addListener(getUpdate);
      _subscriptions[notifier] = () => notifier.removeListener(getUpdate);
    }
  }

  return result;
}