triggerPostBuildCallbacks method

  1. @protected
void triggerPostBuildCallbacks()

Triggers all callbacks registered in the previous build.

This method must be called once after every build, even if the build threw an exception. Implementations can decide whether call this method immediately after wrapBuild, or schedule it for later. This method will catch any exceptions thrown by the callbacks.

Implementation

@protected
void triggerPostBuildCallbacks() {
  assert(() {
    if (!_debugPostBuildCallbacksDirty) {
      throw FlutterError.fromParts([
        ErrorSummary("triggerPostBuildCallbacks has been called more than once"),
        ErrorDescription("triggerPostBuildCallbacks must be called exactly once after every build"),
        DiagnosticableTreeNode(name: "context", value: this, style: null),
      ]);
    }
    _debugPostBuildCallbacksDirty = false;
    return true;
  }());

  for (final callback in _postBuildCallbacks) {
    try {
      callback();
    } catch (e, s) {
      final error = FlutterErrorDetails(
        exception: e,
        stack: s,
        library: 'utopia_hooks',
        context: DiagnosticsBlock(
          children: [
            ErrorSummary("Exception thrown by a post-build callback"),
            DiagnosticsProperty("callback", callback),
            DiagnosticableTreeNode(name: "context", value: this, style: null),
          ],
        ),
      );
      FlutterError.reportError(error);
    }
  }
  _postBuildCallbacks.clear();
}