1. override
void beginFrame()

Pump the build and rendering pipeline to generate a frame.

This method is called by handleBeginFrame, which itself is called automatically by the engine when when it is time to lay out and paint a frame.

Each frame consists of the following phases:

  1. The animation phase: The handleBeginFrame method, which is registeredwith ui.window.onBeginFrame, invokes all the transient frame callbacksregistered with scheduleFrameCallback and addFrameCallback, inregistration order. This includes all the Ticker instances that aredriving AnimationController objects, which means all of the activeAnimation objects tick at this point.

handleBeginFrame then invokes all the persistent frame callbacks, of which the most notable is this method, beginFrame, which proceeds as follows:

  1. The build phase: All the dirty Elements in the widget tree arerebuilt (see State.build). See State.setState for further details onmarking a widget dirty for building. See BuildOwner for more informationon this step.

  2. The layout phase: All the dirty RenderObjects in the system are laidout (see RenderObject.performLayout). See RenderObject.markNeedsLayoutfor further details on marking an object dirty for layout.

  3. The compositing bits phase: The compositing bits on any dirtyRenderObject objects are updated. SeeRenderObject.markNeedsCompositingBitsUpdate.

  4. The paint phase: All the dirty RenderObjects in the system arerepainted (see RenderObject.paint). This generates the Layer tree. SeeRenderObject.markNeedsPaint for further details on marking an objectdirty for paint.

  5. The compositing phase: The layer tree is turned into a ui.Scene andsent to the GPU.

  6. The semantics phase: All the dirty RenderObjects in the system havetheir semantics updated (see RenderObject.SemanticsAnnotator). Thisgenerates the SemanticsNode tree. SeeRenderObject.markNeedsSemanticsUpdate for further details on marking anobject dirty for semantics.

For more details on steps 3-7, see PipelineOwner.

  1. The finalization phase in the widgets layer: The widgets tree isfinalized. This causes State.dispose to be invoked on any objects thatwere removed from the widgets tree this frame. SeeBuildOwner.finalizeTree for more details.

  2. The finalization phase in the scheduler layer: After beginFramereturns, handleBeginFrame then invokes post-frame callbacks (registeredwith addPostFrameCallback.

Source

//
// When editing the above, also update rendering/binding.dart's copy.
@override
void beginFrame() {
  assert(!debugBuildingDirtyElements);
  assert(() {
    debugBuildingDirtyElements = true;
    return true;
  });
  try {
    if (renderViewElement != null)
      buildOwner.buildScope(renderViewElement);
    super.beginFrame();
    buildOwner.finalizeTree();
  } finally {
    assert(() {
      debugBuildingDirtyElements = false;
      return true;
    });
  }
  // TODO(ianh): Following code should not be included in release mode, only profile and debug modes.
  // See https://github.com/dart-lang/sdk/issues/27192
  if (_needToReportFirstFrame) {
    if (_thisFrameWasUseful) {
      developer.Timeline.instantSync('Widgets completed first useful frame');
      developer.postEvent('Flutter.FirstFrame', <String, dynamic>{});
      _needToReportFirstFrame = false;
    } else {
      _thisFrameWasUseful = true;
    }
  }
}