Flutter源码流程
2022-06-03 18:32:13 0 举报
AI智能生成
Flutter源码流程
作者其他创作
大纲/内容
WidgetsFlutterBinding.ensureInitialized()
_parent = parent;_slot = newSlot;_lifecycleState = _ElementLifecycle.active;_depth = _parent != null ? _parent!.depth + 1 : 1;
if (parent != null) { _owner = parent.owner;}
_inheritedWidgets = _parent?._inheritedWidgets
_updateInheritance();
_renderObject = widget.createRenderObject(this)
_slot = newSlot;
_ancestorRenderObjectElement = _findAncestorRenderObjectElement();
parentDataWidget.applyParentData(renderObject)
if (_findAncestorParentDataElement() != null) _updateParentData(parentDataElement.widget);
attachRenderObject(newSlot)
_dirty = false
if (newWidget == null) { if (child != null) deactivateChild(child); return null; }
_parent = parent
_updateDepth(_parent!.depth)
_updateInheritance()
didChangeDependencies()
state.activate()markNeedsBuild()
element.activate()
element.visitChildren(_activateRecursively)
_activateRecursively(this)
return updatedChild!;
if (newChild != null)
if (newWidget.key is GlobalKey)
Element newChild = newWidget.createElement()
Element.mount
RenderObjectElement.mount
StatelessElement._firstBuild()
state.initState()
state.didChangeDependencies()
if (_didChangeDependencies) { state.didChangeDependencies(); _didChangeDependencies = false;}
_dirty = false;
rebuild()>> performRebuild()
StatefulElement._firstBuild()
return newChild
else
newChild = child
if (child.widget == newWidget)
super.update(newWidget)
notifyClients(oldWidget)
updated(oldWidget)
_dirty = true
rebuild()
ProxyElement.update(ProxyWidget newWidget)
state._widget = widget
state.didUpdateWidget(oldWidget)
StatefulElement.update(StatefulWidget newWidget)
Element.update(covariant Widget newWidget)>> _widget = newWidget
child.update(newWidget)
child._parent = null
visitChildren((Element child) { child.detachRenderObject(); });
_slot = null
child.detachRenderObject()
state.deactivate()
for (final InheritedElement dependency in _dependencies!) dependency._dependents.remove(this)
_inheritedWidgets = null
_lifecycleState = _ElementLifecycle.inactive
element.deactivate()
element.visitChildren(_deactivateRecursively)
_deactivateRecursively(element)
_elements.add(element)
owner!._inactiveElements.add(child)
deactivateChild(child)
if (child != null)
WidgetsFlutterBinding.scheduleAttachRootWidget(app)
TRANSIENT FRAME CALLBACKS
handleBeginFrame()
if (_dirtyElements.isEmpty) return;
ComponentElement.performRebuild()
RenderObjectElement.performRebuild()
Element.rebuild()
element.rebuild()
element._inDirtyList = false
buildOwner!.buildScope(renderViewElement!)
WidgetsBinding.drawFrame()
_size = configuration.size;
if (!parentUsesSize || sizedByParent || constraints.isTight || parent is! RenderObject) { relayoutBoundary = this; } else { relayoutBoundary = (parent! as RenderObject)._relayoutBoundary; }
if (!_needsLayout && constraints == _constraints && relayoutBoundary == _relayoutBoundary) { return; }
_constraints = constraints;
_relayoutBoundary = relayoutBoundary;
if (_relayoutBoundary != this) { _relayoutBoundary = null; _needsLayout = true; visitChildren(_cleanChildRelayoutBoundary); }
if (_relayoutBoundary != null && relayoutBoundary != _relayoutBoundary) { visitChildren(_cleanChildRelayoutBoundary); }
if (sizedByParent) { performResize();}
performLayout()
_needsLayout = false;
markNeedsPaint();
RenderView.performLayout()
RenderObject._layoutWithoutResize()
pipelineOwner.flushLayout();
pipelineOwner.flushCompositingBits();
OffsetLayer? childLayer = child._layerHandle.layer as OffsetLayer?;
if (childLayer == null) { final OffsetLayer layer = OffsetLayer(); child._layerHandle.layer = childLayer = layer;} else { childLayer.removeAllChildren();}
if (_needsLayout) return;
_needsPaint = false;
stopRecordingIfNeeded();
final OffsetLayer childOffsetLayer = child._layerHandle.layer! as OffsetLayer;childOffsetLayer.offset = offset;appendLayer(childOffsetLayer);
if (child.isRepaintBoundary)
_currentLayer = PictureLayer(estimatedBounds); _recorder = ui.PictureRecorder(); _canvas = Canvas(_recorder!); // 将pictureLayer添加到_containerLayer(绘制边界节点的Layer)中 _containerLayer.append(_currentLayer!);
if (_canvas == null) _startRecording(); return _canvas!;
Canvas get canvas
childContext.stopRecordingIfNeeded();
PaintingContext.repaintCompositedChild(node)
pipelineOwner.flushPaint();
if (sendFramesToEngine) { renderView.compositeFrame(); // this sends the bits to the GPU pipelineOwner.flushSemantics(); // this also sends the semantics to the OS. _firstFrameSent = true;}
RendererBinding.drawFrame()
_widget = null
_dependencies = null
_lifecycleState = _ElementLifecycle.defunct
Element.unmount()
buildOwner!.finalizeTree()
RendererBinding._handlePersistentFrameCallback
PERSISTENT FRAME CALLBACKS
POST-FRAME CALLBACKS
handleDrawFrame()
ensureFrameCallbacksRegistered()
window.scheduleFrame()
_hasScheduledFrame = true
if (hadScheduledFrame) scheduleFrame()
WidgetsFlutterBinding.scheduleWarmUpFrame()
fn()
if (dirty) return;
SchedulerBinding.ensureVisualUpdate()
_dirtyElements.add(element)
element._inDirtyList = true
owner!.scheduleBuildFor(this)
_element!.markNeedsBuild()
setState(VoidCallback fn)
if (_needsLayout) return;
_needsLayout = true;
parent.markNeedsLayout();
if (_relayoutBoundary != this) { markParentNeedsLayout();}
else { _needsLayout = true; if (owner != null) { owner!._nodesNeedingLayout.add(this); owner!.requestVisualUpdate(); } }
RenderObject.markNeedsLayout()
if (_needsPaint) return;
_needsPaint = true;
if (isRepaintBoundary) { if (owner != null) { owner!._nodesNeedingPaint.add(this); owner!.requestVisualUpdate(); } }
else if (parent is RenderObject) { (this.parent! as RenderObject).markNeedsPaint(); }
else { if (owner != null) owner!.requestVisualUpdate(); }
RenderObject.markNeedsPaint()
Flutter源码流程
0 条评论
回复 删除
下一页