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() {
  ReactterNestedWidget? nestedHook;
  var nextNode = parent?.injectedChild ??
      Builder(
        builder: (context) => widget.build(context),
      );

  for (final child in widget.providers.reversed) {
    nextNode = nestedHook = ReactterNestedWidget<ReactterProviders>(
      owner: this,
      wrappedWidget: child,
      injectedChild: nextNode,
    );
  }

  if (nestedHook != null) {
    // We manually update ReactterNestedProviderElement instead of letter widgets do their thing
    // because an item N may be constant but N+1 not. So, if we used widgets
    // then N+1 wouldn't rebuild because N didn't change
    for (final node in nodes) {
      node
        ..wrappedChild = nestedHook!.wrappedWidget
        ..injectedChild = nestedHook.injectedChild;

      final next = nestedHook.injectedChild;
      if (next is ReactterNestedWidget) {
        nestedHook = next;
      } else {
        break;
      }
    }
  }

  return nextNode;
}