当前位置: 首页 > news >正文

北京seo网站设计海珠做网站

北京seo网站设计,海珠做网站,com网站是用什么做的,公司网站模板免费源码下载Flutter开发进阶之瞧瞧BuildOwner 上回说到关于Element Tree的构建还缺最后一块拼图#xff0c;build的重要过程中会调用_element!.markNeedsBuild();#xff0c;而markNeedsBuild会调用owner!.scheduleBuildFor(this);。 在Flutter框架中#xff0c;BuildOwner负责管理构建…Flutter开发进阶之瞧瞧BuildOwner 上回说到关于Element Tree的构建还缺最后一块拼图build的重要过程中会调用_element!.markNeedsBuild();而markNeedsBuild会调用owner!.scheduleBuildFor(this);。 在Flutter框架中BuildOwner负责管理构建过程它持有当前构建周期的所有相关信息并协调Widget到Element的转换过程。 让我们看看BuildOwner在Element中的定义。 /*The object that manages the lifecycle of this element.*/overrideBuildOwner? get owner _owner;BuildOwner? _owner;mustCallSupervoid mount(Element? parent, Object? newSlot) {assert(_lifecycleState _ElementLifecycle.initial);assert(_parent null);assert(parent null || parent._lifecycleState _ElementLifecycle.active);assert(slot null);_parent parent;_slot newSlot;_lifecycleState _ElementLifecycle.active;_depth _parent ! null ? _parent!.depth 1 : 1;if (parent ! null) {_owner parent.owner;}assert(owner ! null);final Key? key widget.key;if (key is GlobalKey) {owner!._registerGlobalKey(key, this);}_updateInheritance();attachNotificationTree();}可知_owner在同一个Element Tree下为唯一。 再来看看BuildOwner的源码。 class BuildOwner {BuildOwner({this.onBuildScheduled, FocusManager? focusManager}): focusManager focusManager ?? (FocusManager()..registerGlobalHandlers());VoidCallback? onBuildScheduled;final _InactiveElements _inactiveElements _InactiveElements();final ListElement _dirtyElements Element[];bool _scheduledFlushDirtyElements false;bool? _dirtyElementsNeedsResorting;bool get _debugIsInBuildScope _dirtyElementsNeedsResorting ! null;FocusManager focusManager;void scheduleBuildFor(Element element) {assert(element.owner this);assert(() {if (debugPrintScheduleBuildForStacks) {debugPrintStack(label:scheduleBuildFor() called for $element${_dirtyElements.contains(element) ? (ALREADY IN LIST) : });}if (!element.dirty) {throw FlutterError.fromParts(DiagnosticsNode[ErrorSummary(scheduleBuildFor() called for a widget that is not marked as dirty.),element.describeElement(The method was called for the following element),ErrorDescription(This element is not current marked as dirty. Make sure to set the dirty flag before calling scheduleBuildFor().,),ErrorHint(If you did not attempt to call scheduleBuildFor() yourself, then this probably indicates a bug in the widgets framework. Please report it:\n https:github.com/flutter/flutter/issues/new?template2_bug.yml,),]);}return true;}());if (element._inDirtyList) {assert(() {if (debugPrintScheduleBuildForStacks) {debugPrintStack(label:BuildOwner.scheduleBuildFor() called; _dirtyElementsNeedsResorting was $_dirtyElementsNeedsResorting (now true); dirty list is: $_dirtyElements);}if (!_debugIsInBuildScope) {throw FlutterError.fromParts(DiagnosticsNode[ErrorSummary(BuildOwner.scheduleBuildFor() called inappropriately.),ErrorHint(The BuildOwner.scheduleBuildFor() method should only be called while the buildScope() method is actively rebuilding the widget tree.,),]);}return true;}());_dirtyElementsNeedsResorting true;return;}if (!_scheduledFlushDirtyElements onBuildScheduled ! null) {_scheduledFlushDirtyElements true;onBuildScheduled!();}_dirtyElements.add(element);element._inDirtyList true;assert(() {if (debugPrintScheduleBuildForStacks) {debugPrint(...dirty list is now: $_dirtyElements);}return true;}());}int _debugStateLockLevel 0;bool get _debugStateLocked _debugStateLockLevel 0;bool get debugBuilding _debugBuilding;bool _debugBuilding false;Element? _debugCurrentBuildTarget;void lockState(VoidCallback callback) {assert(_debugStateLockLevel 0);assert(() {_debugStateLockLevel 1;return true;}());try {callback();} finally {assert(() {_debugStateLockLevel - 1;return true;}());}assert(_debugStateLockLevel 0);}pragma(vm:notify-debugger-on-exception)void buildScope(Element context, [VoidCallback? callback]) {if (callback null _dirtyElements.isEmpty) {return;}assert(_debugStateLockLevel 0);assert(!_debugBuilding);assert(() {if (debugPrintBuildScope) {debugPrint(buildScope called with context $context; dirty list is: $_dirtyElements);}_debugStateLockLevel 1;_debugBuilding true;return true;}());if (!kReleaseMode) {MapString, String? debugTimelineArguments;assert(() {if (debugEnhanceBuildTimelineArguments) {debugTimelineArguments String, String{dirty count: ${_dirtyElements.length},dirty list: $_dirtyElements,lock level: $_debugStateLockLevel,scope context: $context,};}return true;}());FlutterTimeline.startSync(BUILD, arguments: debugTimelineArguments);}try {_scheduledFlushDirtyElements true;if (callback ! null) {assert(_debugStateLocked);Element? debugPreviousBuildTarget;assert(() {debugPreviousBuildTarget _debugCurrentBuildTarget;_debugCurrentBuildTarget context;return true;}());_dirtyElementsNeedsResorting false;try {callback();} finally {assert(() {assert(_debugCurrentBuildTarget context);_debugCurrentBuildTarget debugPreviousBuildTarget;_debugElementWasRebuilt(context);return true;}());}}_dirtyElements.sort(Element._sort);_dirtyElementsNeedsResorting false;int dirtyCount _dirtyElements.length;int index 0;while (index dirtyCount) {final Element element _dirtyElements[index];assert(element._inDirtyList);assert(() {if (element._lifecycleState _ElementLifecycle.active !element._debugIsInScope(context)) {throw FlutterError.fromParts(DiagnosticsNode[ErrorSummary(Tried to build dirty widget in the wrong build scope.),ErrorDescription(A widget which was marked as dirty and is still active was scheduled to be built, but the current build scope unexpectedly does not contain that widget.,),ErrorHint(Sometimes this is detected when an element is removed from the widget tree, but the element somehow did not get marked as inactive. In that case, it might be caused by an ancestor element failing to implement visitChildren correctly, thus preventing some or all of its descendants from being correctly deactivated.,),DiagnosticsPropertyElement(The root of the build scope was,context,style: DiagnosticsTreeStyle.errorProperty,),DiagnosticsPropertyElement(The offending element (which does not appear to be a descendant of the root of the build scope) was,element,style: DiagnosticsTreeStyle.errorProperty,),]);}return true;}());final bool isTimelineTracked !kReleaseMode _isProfileBuildsEnabledFor(element.widget);if (isTimelineTracked) {MapString, String? debugTimelineArguments;assert(() {if (kDebugMode debugEnhanceBuildTimelineArguments) {debugTimelineArguments element.widget.toDiagnosticsNode().toTimelineArguments();}return true;}());FlutterTimeline.startSync(${element.widget.runtimeType},arguments: debugTimelineArguments,);}try {element.rebuild();} catch (e, stack) {_reportException(ErrorDescription(while rebuilding dirty elements),e,stack,informationCollector: () DiagnosticsNode[if (kDebugMode index _dirtyElements.length)DiagnosticsDebugCreator(DebugCreator(element)),if (index _dirtyElements.length)element.describeElement(The element being rebuilt at the time was index $index of $dirtyCount)elseErrorHint(The element being rebuilt at the time was index $index of $dirtyCount, but _dirtyElements only had ${_dirtyElements.length} entries. This suggests some confusion in the framework internals.),],);}if (isTimelineTracked) {FlutterTimeline.finishSync();}index 1;if (dirtyCount _dirtyElements.length ||_dirtyElementsNeedsResorting!) {_dirtyElements.sort(Element._sort);_dirtyElementsNeedsResorting false;dirtyCount _dirtyElements.length;while (index 0 _dirtyElements[index - 1].dirty) {index - 1;}}}assert(() {if (_dirtyElements.any((Element element) element._lifecycleState _ElementLifecycle.active element.dirty)) {throw FlutterError.fromParts(DiagnosticsNode[ErrorSummary(buildScope missed some dirty elements.),ErrorHint(This probably indicates that the dirty list should have been resorted but was not.),Element.describeElements(The list of dirty elements at the end of the buildScope call was,_dirtyElements),]);}return true;}());} finally {for (final Element element in _dirtyElements) {assert(element._inDirtyList);element._inDirtyList false;}_dirtyElements.clear();_scheduledFlushDirtyElements false;_dirtyElementsNeedsResorting null;if (!kReleaseMode) {FlutterTimeline.finishSync();}assert(_debugBuilding);assert(() {_debugBuilding false;_debugStateLockLevel - 1;if (debugPrintBuildScope) {debugPrint(buildScope finished);}return true;}());}assert(_debugStateLockLevel 0);}MapElement, SetGlobalKey?_debugElementsThatWillNeedToBeRebuiltDueToGlobalKeyShenanigans;void _debugTrackElementThatWillNeedToBeRebuiltDueToGlobalKeyShenanigans(Element node, GlobalKey key) {_debugElementsThatWillNeedToBeRebuiltDueToGlobalKeyShenanigans ??HashMapElement, SetGlobalKey();final SetGlobalKey keys _debugElementsThatWillNeedToBeRebuiltDueToGlobalKeyShenanigans!.putIfAbsent(node, () HashSetGlobalKey());keys.add(key);}void _debugElementWasRebuilt(Element node) {_debugElementsThatWillNeedToBeRebuiltDueToGlobalKeyShenanigans?.remove(node);}final MapGlobalKey, Element _globalKeyRegistry GlobalKey, Element{};_debugOnlyfinal SetElement? _debugIllFatedElements kDebugMode ? HashSetElement() : null;_debugOnlyfinal MapElement, MapElement, GlobalKey? _debugGlobalKeyReservations kDebugMode ? Element, MapElement, GlobalKey{} : null;int get globalKeyCount _globalKeyRegistry.length;void _debugRemoveGlobalKeyReservationFor(Element parent, Element child) {assert(() {_debugGlobalKeyReservations?[parent]?.remove(child);return true;}());}void _registerGlobalKey(GlobalKey key, Element element) {assert(() {if (_globalKeyRegistry.containsKey(key)) {final Element oldElement _globalKeyRegistry[key]!;assert(element.widget.runtimeType ! oldElement.widget.runtimeType);_debugIllFatedElements?.add(oldElement);}return true;}());_globalKeyRegistry[key] element;}void _unregisterGlobalKey(GlobalKey key, Element element) {assert(() {if (_globalKeyRegistry.containsKey(key) _globalKeyRegistry[key] ! element) {final Element oldElement _globalKeyRegistry[key]!;assert(element.widget.runtimeType ! oldElement.widget.runtimeType);}return true;}());if (_globalKeyRegistry[key] element) {_globalKeyRegistry.remove(key);}}void _debugReserveGlobalKeyFor(Element parent, Element child, GlobalKey key) {assert(() {_debugGlobalKeyReservations?[parent] ?? Element, GlobalKey{};_debugGlobalKeyReservations?[parent]![child] key;return true;}());}void _debugVerifyGlobalKeyReservation() {assert(() {final MapGlobalKey, Element keyToParent GlobalKey, Element{};_debugGlobalKeyReservations?.forEach((Element parent, MapElement, GlobalKey childToKey) {if (parent._lifecycleState _ElementLifecycle.defunct ||parent.renderObject?.attached false) {return;}childToKey.forEach((Element child, GlobalKey key) {if (child._parent null) {return;}if (keyToParent.containsKey(key) keyToParent[key] ! parent) {final Element older keyToParent[key]!;final Element newer parent;final FlutterError error;if (older.toString() ! newer.toString()) {error FlutterError.fromParts(DiagnosticsNode[ErrorSummary(Multiple widgets used the same GlobalKey.),ErrorDescription(The key $key was used by multiple widgets. The parents of those widgets were:\n- $older\n- $newer\nA GlobalKey can only be specified on one widget at a time in the widget tree.,),]);} else {error FlutterError.fromParts(DiagnosticsNode[ErrorSummary(Multiple widgets used the same GlobalKey.),ErrorDescription(The key $key was used by multiple widgets. The parents of those widgets were different widgets that both had the following description:\n $parent\nA GlobalKey can only be specified on one widget at a time in the widget tree.,),]);}if (child._parent ! older) {older.visitChildren((Element currentChild) {if (currentChild child) {older.forgetChild(child);}});}if (child._parent ! newer) {newer.visitChildren((Element currentChild) {if (currentChild child) {newer.forgetChild(child);}});}throw error;} else {keyToParent[key] parent;}});});_debugGlobalKeyReservations?.clear();return true;}());}void _debugVerifyIllFatedPopulation() {assert(() {MapGlobalKey, SetElement? duplicates;for (final Element elementin _debugIllFatedElements ?? const Element{}) {if (element._lifecycleState ! _ElementLifecycle.defunct) {assert(element.widget.key ! null);final GlobalKey key element.widget.key! as GlobalKey;assert(_globalKeyRegistry.containsKey(key));duplicates ?? GlobalKey, SetElement{};Uses ordered set to produce consistent error message.final SetElement elements duplicates.putIfAbsent(key, () Element{});elements.add(element);elements.add(_globalKeyRegistry[key]!);}}_debugIllFatedElements?.clear();if (duplicates ! null) {final ListDiagnosticsNode information DiagnosticsNode[];information.add(ErrorSummary(Multiple widgets used the same GlobalKey.));for (final GlobalKey key in duplicates.keys) {final SetElement elements duplicates[key]!;information.add(Element.describeElements(The key $key was used by ${elements.length} widgets, elements));}information.add(ErrorDescription(A GlobalKey can only be specified on one widget at a time in the widget tree.));throw FlutterError.fromParts(information);}return true;}());}pragma(vm:notify-debugger-on-exception)void finalizeTree() {if (!kReleaseMode) {FlutterTimeline.startSync(FINALIZE TREE);}try {lockState(_inactiveElements._unmountAll); assert(() {try {_debugVerifyGlobalKeyReservation();_debugVerifyIllFatedPopulation();if (_debugElementsThatWillNeedToBeRebuiltDueToGlobalKeyShenanigans !null _debugElementsThatWillNeedToBeRebuiltDueToGlobalKeyShenanigans!.isNotEmpty) {final SetGlobalKey keys HashSetGlobalKey();for (final Element elementin _debugElementsThatWillNeedToBeRebuiltDueToGlobalKeyShenanigans!.keys) {if (element._lifecycleState ! _ElementLifecycle.defunct) {keys.addAll(_debugElementsThatWillNeedToBeRebuiltDueToGlobalKeyShenanigans![element]!);}}if (keys.isNotEmpty) {final MapString, int keyStringCount HashMapString, int();for (final String keyin keys.mapString((GlobalKey key) key.toString())) {if (keyStringCount.containsKey(key)) {keyStringCount.update(key, (int value) value 1);} else {keyStringCount[key] 1;}}final ListString keyLabels String[];keyStringCount.forEach((String key, int count) {if (count 1) {keyLabels.add(key);} else {keyLabels.add($key ($count different affected keys had this toString representation));}});final IterableElement elements _debugElementsThatWillNeedToBeRebuiltDueToGlobalKeyShenanigans!.keys;final MapString, int elementStringCount HashMapString, int();for (final String element in elements.mapString((Element element) element.toString())) {if (elementStringCount.containsKey(element)) {elementStringCount.update(element, (int value) value 1);} else {elementStringCount[element] 1;}}final ListString elementLabels String[];elementStringCount.forEach((String element, int count) {if (count 1) {elementLabels.add(element);} else {elementLabels.add($element ($count different affected elements had this toString representation));}});assert(keyLabels.isNotEmpty);final String the keys.length 1 ? the : ;final String s keys.length 1 ? : s;final String were keys.length 1 ? was : were;final String their keys.length 1 ? its : their;final String respective elementLabels.length 1 ? : respective;final String those keys.length 1 ? that : those;final String s2 elementLabels.length 1 ? : s;final String those2 elementLabels.length 1 ? that : those;final String they elementLabels.length 1 ? it : they;final String think elementLabels.length 1 ? thinks : think;final String are elementLabels.length 1 ? is : are;throw FlutterError.fromParts(DiagnosticsNode[ErrorSummary(Duplicate GlobalKey$s detected in widget tree.),ErrorDescription(The following GlobalKey$s $were specified multiple times in the widget tree. This will lead to parts of the widget tree being truncated unexpectedly, because the second time a key is seen, the previous instance is moved to the new location. The key$s $were:\n- ${keyLabels.join(\n )}\nThis was determined by noticing that after$the widget$s with the above global key$s $were moved out of $their$respective previous parent$s2, $those2 previous parent$s2 never updated during this frame, meaning that $they either did not update at all or updated before the widget$s $were moved, in either case implying that $they still $think that $they should have a child with $those global key$s.\nThe specific parent$s2 that did not update after having one or more children forcibly removed due to GlobalKey reparenting $are:\n- ${elementLabels.join(\n )}\nA GlobalKey can only be specified on one widget at a time in the widget tree.,),]);}}} finally {_debugElementsThatWillNeedToBeRebuiltDueToGlobalKeyShenanigans?.clear();}return true;}());} catch (e, stack) {_reportException(ErrorSummary(while finalizing the widget tree), e, stack);} finally {if (!kReleaseMode) {FlutterTimeline.finishSync();}}}void reassemble(Element root) {if (!kReleaseMode) {FlutterTimeline.startSync(Preparing Hot Reload (widgets));}try {assert(root._parent null);assert(root.owner this);root.reassemble();} finally {if (!kReleaseMode) {FlutterTimeline.finishSync();}}} }我们忽略debug部分的内容BuildOwner作为一个基类void scheduleBuildFor(Element element)方法会将一个需要重新构建的Element添加进_dirtyElements中然后会Flutter通过调用WidgetsBinding.drawFrame方法内部会调用buildScope完成重新构建。 综合前几篇文章我们了解到Widget本身只存储了UI的结构数据在Widget的初始化过程中会将自身作为参数调用Element的初始化方法创建对应的Element它是持有Widget、State、BuildOwner的实例它可以包含其他子Element形成TreeElement通过State的状态管理去进行对应的生命周期管理同个Tree下Element对应一个根BuildOwner_owner parent.owner;它负责协调构建过程当Element添加进_dirtyElements中时Flutter循环调用的WidgetsBinding.drawFrameWidgetsFlutterBinding.ensureInitialized()或runApp()后会激活的循环会重新构建Tree渲染到屏幕上。 以上完成build闭环。
http://www.w-s-a.com/news/578931/

相关文章:

  • 温州网站运营打开百度一下网页版
  • 网站有情链接怎么做住房公积金个体工商户
  • 内蒙古网站开发网站开发验收资料
  • 温州网站建设首选国鼎网络网络营销方法可分为两类
  • 做张家界旅游网站多少钱企业推广网络营销
  • 代做毕设网站推荐广东手机微信网站制作
  • 福州建设工程质量监督网站专业做公司宣传网站的
  • 百度云建站教程网站工程师是做什么的
  • 手机在线制作网站一级消防工程师考试试题及答案
  • 网站设计的需求网页制作教程和素材
  • 徐州网站建设 网站推广WordPress 文章编辑
  • 做什么网站比较受欢迎软件商店下载安装2023版本最新
  • 做ip资讯的网站怎么在wordpress中套用同行网页
  • 医院网站如何备案东莞优化公司收费
  • 罗村网站开发适合ps做图的素材网站有哪些
  • 网站建设中 油财宝企业网址怎么整
  • asp.net空网站php网站开发要学什么
  • 做可视化的网站微信网站模版下载
  • 包头移动的网站建设茂名建站价格
  • 网站文章内容一键排版功能铜山网站建设
  • cdr可不可做网站对网站建设起到计划和指导的作用
  • 合肥最好的网站建设网页设计心得体会2000字
  • 西安网站品牌建设门户网站类型
  • 网上做调查问卷的网站请人做网站域名和主机
  • 个人网站模板html5找公司网站建设
  • 找最新游戏做视频网站一个做网站的团队需要哪些人员
  • 威海市做网站的做网站很难吗
  • 广州房地产网站建设方案怎么免费申请网站
  • 免费生成网站软件下载影视公司名字取名
  • 网站公司提供程序免费的网页入口