wrapBuild<T> method

  1. @protected
T wrapBuild<T>(
  1. T build()
)

Performs build in this HookContext.

Implementation

@protected
T wrapBuild<T>(T Function() build) {
  return HookContext.wrap(this, () {
    try {
      assert(() {
        if (_debugPostBuildCallbacksDirty) {
          throw FlutterError.fromParts([
            ErrorSummary("triggerPostBuildCallbacks has not been called after the previous build"),
            DiagnosticableTreeNode(name: "context", value: this, style: null),
          ]);
        }
        _debugPostBuildCallbacksDirty = true;
        return true;
      }());

      final result = build();

      assert(() {
        if (_index < _hooks.length) {
          if (_debugWillReassemble) {
            while (_index++ < _hooks.length) {
              _hooks.removeLast().dispose();
            }
          } else {
            throw FlutterError.fromParts([
              ErrorSummary("Hooks have been removed during build"),
              ErrorDescription("Hooks that were called during the first build must be called in every other build"),
              ErrorHint("To dynamically change hooks during build, use control flow hooks"), // TODO add article link
              DiagnosticsBlock(
                name: "removed hooks",
                children: _hooks.skip(_index).map((it) => it.toDiagnosticsNode()).toList(),
              ),
              DiagnosticableTreeNode(name: "context", value: this, style: null),
            ]);
          }
        }
        return true;
      }());

      return result;
    } finally {
      assert(() {
        _debugWillReassemble = false;
        return true;
      }());
      _isFirstBuild = false;
      _index = 0;
    }
  });
}