@@ -4507,10 +4507,6 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
4507
4507
}
4508
4508
4509
4509
/// 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.
4514
4510
bool get dirty => _dirty;
4515
4511
bool _dirty = true ;
4516
4512
@@ -4584,14 +4580,10 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
4584
4580
/// Called by the [BuildOwner] when [BuildOwner.scheduleBuildFor] has been
4585
4581
/// called to mark this element dirty, by [mount] when the element is first
4586
4582
/// 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.
4591
4583
@pragma ('vm:prefer-inline' )
4592
- void rebuild ({ bool force = false } ) {
4584
+ void rebuild () {
4593
4585
assert (_lifecycleState != _ElementLifecycle .initial);
4594
- if (_lifecycleState != _ElementLifecycle .active || ( ! _dirty && ! force) ) {
4586
+ if (_lifecycleState != _ElementLifecycle .active || ! _dirty) {
4595
4587
return ;
4596
4588
}
4597
4589
assert (() {
@@ -4626,13 +4618,8 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
4626
4618
/// Cause the widget to update itself.
4627
4619
///
4628
4620
/// Called by [rebuild] after the appropriate checks have been made.
4629
- ///
4630
- /// The base implementation only clears the [dirty] flag.
4631
4621
@protected
4632
- @mustCallSuper
4633
- void performRebuild () {
4634
- _dirty = false ;
4635
- }
4622
+ void performRebuild ();
4636
4623
}
4637
4624
4638
4625
class _ElementDiagnosticableTreeNode extends DiagnosticableTreeNode {
@@ -4914,7 +4901,7 @@ abstract class ComponentElement extends Element {
4914
4901
} finally {
4915
4902
// We delay marking the element as clean until after calling build() so
4916
4903
// that attempts to markNeedsBuild() during build() will be ignored.
4917
- super . performRebuild (); // clears the "dirty" flag
4904
+ _dirty = false ;
4918
4905
}
4919
4906
try {
4920
4907
_child = updateChild (_child, built, slot);
@@ -4968,7 +4955,8 @@ class StatelessElement extends ComponentElement {
4968
4955
void update (StatelessWidget newWidget) {
4969
4956
super .update (newWidget);
4970
4957
assert (widget == newWidget);
4971
- rebuild (force: true );
4958
+ _dirty = true ;
4959
+ rebuild ();
4972
4960
}
4973
4961
}
4974
4962
@@ -5065,6 +5053,10 @@ class StatefulElement extends ComponentElement {
5065
5053
super .update (newWidget);
5066
5054
assert (widget == newWidget);
5067
5055
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 ;
5068
5060
state._widget = widget as StatefulWidget ;
5069
5061
final Object ? debugCheckForReturnedFuture = state.didUpdateWidget (oldWidget) as dynamic ;
5070
5062
assert (() {
@@ -5080,7 +5072,7 @@ class StatefulElement extends ComponentElement {
5080
5072
}
5081
5073
return true ;
5082
5074
}());
5083
- rebuild (force : true );
5075
+ rebuild ();
5084
5076
}
5085
5077
5086
5078
@override
@@ -5225,7 +5217,8 @@ abstract class ProxyElement extends ComponentElement {
5225
5217
super .update (newWidget);
5226
5218
assert (widget == newWidget);
5227
5219
updated (oldWidget);
5228
- rebuild (force: true );
5220
+ _dirty = true ;
5221
+ rebuild ();
5229
5222
}
5230
5223
5231
5224
/// Called during build when the [widget] has changed.
@@ -5753,7 +5746,7 @@ abstract class RenderObjectElement extends Element {
5753
5746
}());
5754
5747
assert (_slot == newSlot);
5755
5748
attachRenderObject (newSlot);
5756
- super . performRebuild (); // clears the "dirty" flag
5749
+ _dirty = false ;
5757
5750
}
5758
5751
5759
5752
@override
@@ -5775,7 +5768,7 @@ abstract class RenderObjectElement extends Element {
5775
5768
}
5776
5769
5777
5770
@override
5778
- void performRebuild () { // ignore: must_call_super, _performRebuild calls super.
5771
+ void performRebuild () {
5779
5772
_performRebuild (); // calls widget.updateRenderObject()
5780
5773
}
5781
5774
@@ -5790,7 +5783,7 @@ abstract class RenderObjectElement extends Element {
5790
5783
_debugDoingBuild = false ;
5791
5784
return true ;
5792
5785
}());
5793
- super . performRebuild (); // clears the "dirty" flag
5786
+ _dirty = false ;
5794
5787
}
5795
5788
5796
5789
/// Updates the children of this element to use new widgets.
@@ -6546,6 +6539,9 @@ class _NullElement extends Element {
6546
6539
6547
6540
@override
6548
6541
bool get debugDoingBuild => throw UnimplementedError ();
6542
+
6543
+ @override
6544
+ void performRebuild () => throw UnimplementedError ();
6549
6545
}
6550
6546
6551
6547
class _NullWidget extends Widget {
0 commit comments