@@ -4507,10 +4507,6 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
45074507 }
45084508
45094509 /// Returns true if the element has been marked as needing rebuilding.
4510- ///
4511- /// The flag is true when the element is first created and after
4512- /// [markNeedsBuild] has been called. The flag is reset to false in the
4513- /// [performRebuild] implementation.
45144510 bool get dirty => _dirty;
45154511 bool _dirty = true ;
45164512
@@ -4584,14 +4580,10 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
45844580 /// Called by the [BuildOwner] when [BuildOwner.scheduleBuildFor] has been
45854581 /// called to mark this element dirty, by [mount] when the element is first
45864582 /// built, and by [update] when the widget has changed.
4587- ///
4588- /// The method will only rebuild if [dirty] is true. To rebuild irregardless
4589- /// of the [dirty] flag, set `force` to true. Forcing a rebuild is convenient
4590- /// from [update] , during which [dirty] is false.
45914583 @pragma ('vm:prefer-inline' )
4592- void rebuild ({ bool force = false } ) {
4584+ void rebuild () {
45934585 assert (_lifecycleState != _ElementLifecycle .initial);
4594- if (_lifecycleState != _ElementLifecycle .active || ( ! _dirty && ! force) ) {
4586+ if (_lifecycleState != _ElementLifecycle .active || ! _dirty) {
45954587 return ;
45964588 }
45974589 assert (() {
@@ -4626,13 +4618,8 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
46264618 /// Cause the widget to update itself.
46274619 ///
46284620 /// Called by [rebuild] after the appropriate checks have been made.
4629- ///
4630- /// The base implementation only clears the [dirty] flag.
46314621 @protected
4632- @mustCallSuper
4633- void performRebuild () {
4634- _dirty = false ;
4635- }
4622+ void performRebuild ();
46364623}
46374624
46384625class _ElementDiagnosticableTreeNode extends DiagnosticableTreeNode {
@@ -4914,7 +4901,7 @@ abstract class ComponentElement extends Element {
49144901 } finally {
49154902 // We delay marking the element as clean until after calling build() so
49164903 // that attempts to markNeedsBuild() during build() will be ignored.
4917- super . performRebuild (); // clears the "dirty" flag
4904+ _dirty = false ;
49184905 }
49194906 try {
49204907 _child = updateChild (_child, built, slot);
@@ -4968,7 +4955,8 @@ class StatelessElement extends ComponentElement {
49684955 void update (StatelessWidget newWidget) {
49694956 super .update (newWidget);
49704957 assert (widget == newWidget);
4971- rebuild (force: true );
4958+ _dirty = true ;
4959+ rebuild ();
49724960 }
49734961}
49744962
@@ -5065,6 +5053,10 @@ class StatefulElement extends ComponentElement {
50655053 super .update (newWidget);
50665054 assert (widget == newWidget);
50675055 final StatefulWidget oldWidget = state._widget! ;
5056+ // We mark ourselves as dirty before calling didUpdateWidget to
5057+ // let authors call setState from within didUpdateWidget without triggering
5058+ // asserts.
5059+ _dirty = true ;
50685060 state._widget = widget as StatefulWidget ;
50695061 final Object ? debugCheckForReturnedFuture = state.didUpdateWidget (oldWidget) as dynamic ;
50705062 assert (() {
@@ -5080,7 +5072,7 @@ class StatefulElement extends ComponentElement {
50805072 }
50815073 return true ;
50825074 }());
5083- rebuild (force : true );
5075+ rebuild ();
50845076 }
50855077
50865078 @override
@@ -5225,7 +5217,8 @@ abstract class ProxyElement extends ComponentElement {
52255217 super .update (newWidget);
52265218 assert (widget == newWidget);
52275219 updated (oldWidget);
5228- rebuild (force: true );
5220+ _dirty = true ;
5221+ rebuild ();
52295222 }
52305223
52315224 /// Called during build when the [widget] has changed.
@@ -5753,7 +5746,7 @@ abstract class RenderObjectElement extends Element {
57535746 }());
57545747 assert (_slot == newSlot);
57555748 attachRenderObject (newSlot);
5756- super . performRebuild (); // clears the "dirty" flag
5749+ _dirty = false ;
57575750 }
57585751
57595752 @override
@@ -5775,7 +5768,7 @@ abstract class RenderObjectElement extends Element {
57755768 }
57765769
57775770 @override
5778- void performRebuild () { // ignore: must_call_super, _performRebuild calls super.
5771+ void performRebuild () {
57795772 _performRebuild (); // calls widget.updateRenderObject()
57805773 }
57815774
@@ -5790,7 +5783,7 @@ abstract class RenderObjectElement extends Element {
57905783 _debugDoingBuild = false ;
57915784 return true ;
57925785 }());
5793- super . performRebuild (); // clears the "dirty" flag
5786+ _dirty = false ;
57945787 }
57955788
57965789 /// Updates the children of this element to use new widgets.
@@ -6546,6 +6539,9 @@ class _NullElement extends Element {
65466539
65476540 @override
65486541 bool get debugDoingBuild => throw UnimplementedError ();
6542+
6543+ @override
6544+ void performRebuild () => throw UnimplementedError ();
65496545}
65506546
65516547class _NullWidget extends Widget {
0 commit comments