Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
7887ca5b
Unverified
Commit
7887ca5b
authored
Aug 13, 2022
by
Greg Spencer
Committed by
GitHub
Aug 13, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Keep `dirty` manipulations private to `Element` base class (#109401)" (#109481)
Landing on red to green the build.
parent
dce82f7e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
38 additions
and
95 deletions
+38
-95
text_selection_toolbar.dart
...ges/flutter/lib/src/cupertino/text_selection_toolbar.dart
+3
-0
framework.dart
packages/flutter/lib/src/widgets/framework.dart
+19
-23
colors_test.dart
packages/flutter/test/cupertino/colors_test.dart
+3
-0
diagnostics_json_test.dart
packages/flutter/test/foundation/diagnostics_json_test.dart
+5
-0
did_update_widget_test.dart
packages/flutter/test/widgets/did_update_widget_test.dart
+0
-70
framework_test.dart
packages/flutter/test/widgets/framework_test.dart
+8
-2
No files found.
packages/flutter/lib/src/cupertino/text_selection_toolbar.dart
View file @
7887ca5b
...
@@ -1016,6 +1016,9 @@ class _NullElement extends Element {
...
@@ -1016,6 +1016,9 @@ class _NullElement extends Element {
@override
@override
bool
get
debugDoingBuild
=>
throw
UnimplementedError
();
bool
get
debugDoingBuild
=>
throw
UnimplementedError
();
@override
void
performRebuild
()
{
}
}
}
class
_NullWidget
extends
Widget
{
class
_NullWidget
extends
Widget
{
...
...
packages/flutter/lib/src/widgets/framework.dart
View file @
7887ca5b
...
@@ -4507,10 +4507,6 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
...
@@ -4507,10 +4507,6 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
}
}
/// Returns true if the element has been marked as needing rebuilding.
/// Returns true if the element has been marked as needing rebuilding.
///
/// The flag is true when the element is first created and after
/// [markNeedsBuild] has been called. The flag is reset to false in the
/// [performRebuild] implementation.
bool
get
dirty
=>
_dirty
;
bool
get
dirty
=>
_dirty
;
bool
_dirty
=
true
;
bool
_dirty
=
true
;
...
@@ -4584,14 +4580,10 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
...
@@ -4584,14 +4580,10 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
/// Called by the [BuildOwner] when [BuildOwner.scheduleBuildFor] has been
/// Called by the [BuildOwner] when [BuildOwner.scheduleBuildFor] has been
/// called to mark this element dirty, by [mount] when the element is first
/// called to mark this element dirty, by [mount] when the element is first
/// built, and by [update] when the widget has changed.
/// built, and by [update] when the widget has changed.
///
/// The method will only rebuild if [dirty] is true. To rebuild irregardless
/// of the [dirty] flag, set `force` to true. Forcing a rebuild is convenient
/// from [update], during which [dirty] is false.
@pragma
(
'vm:prefer-inline'
)
@pragma
(
'vm:prefer-inline'
)
void
rebuild
(
{
bool
force
=
false
}
)
{
void
rebuild
()
{
assert
(
_lifecycleState
!=
_ElementLifecycle
.
initial
);
assert
(
_lifecycleState
!=
_ElementLifecycle
.
initial
);
if
(
_lifecycleState
!=
_ElementLifecycle
.
active
||
(!
_dirty
&&
!
force
)
)
{
if
(
_lifecycleState
!=
_ElementLifecycle
.
active
||
!
_dirty
)
{
return
;
return
;
}
}
assert
(()
{
assert
(()
{
...
@@ -4626,13 +4618,8 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
...
@@ -4626,13 +4618,8 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
/// Cause the widget to update itself.
/// Cause the widget to update itself.
///
///
/// Called by [rebuild] after the appropriate checks have been made.
/// Called by [rebuild] after the appropriate checks have been made.
///
/// The base implementation only clears the [dirty] flag.
@protected
@protected
@mustCallSuper
void
performRebuild
();
void
performRebuild
()
{
_dirty
=
false
;
}
}
}
class
_ElementDiagnosticableTreeNode
extends
DiagnosticableTreeNode
{
class
_ElementDiagnosticableTreeNode
extends
DiagnosticableTreeNode
{
...
@@ -4914,7 +4901,7 @@ abstract class ComponentElement extends Element {
...
@@ -4914,7 +4901,7 @@ abstract class ComponentElement extends Element {
}
finally
{
}
finally
{
// We delay marking the element as clean until after calling build() so
// We delay marking the element as clean until after calling build() so
// that attempts to markNeedsBuild() during build() will be ignored.
// that attempts to markNeedsBuild() during build() will be ignored.
super
.
performRebuild
();
// clears the "dirty" flag
_dirty
=
false
;
}
}
try
{
try
{
_child
=
updateChild
(
_child
,
built
,
slot
);
_child
=
updateChild
(
_child
,
built
,
slot
);
...
@@ -4968,7 +4955,8 @@ class StatelessElement extends ComponentElement {
...
@@ -4968,7 +4955,8 @@ class StatelessElement extends ComponentElement {
void
update
(
StatelessWidget
newWidget
)
{
void
update
(
StatelessWidget
newWidget
)
{
super
.
update
(
newWidget
);
super
.
update
(
newWidget
);
assert
(
widget
==
newWidget
);
assert
(
widget
==
newWidget
);
rebuild
(
force:
true
);
_dirty
=
true
;
rebuild
();
}
}
}
}
...
@@ -5065,6 +5053,10 @@ class StatefulElement extends ComponentElement {
...
@@ -5065,6 +5053,10 @@ class StatefulElement extends ComponentElement {
super
.
update
(
newWidget
);
super
.
update
(
newWidget
);
assert
(
widget
==
newWidget
);
assert
(
widget
==
newWidget
);
final
StatefulWidget
oldWidget
=
state
.
_widget
!;
final
StatefulWidget
oldWidget
=
state
.
_widget
!;
// We mark ourselves as dirty before calling didUpdateWidget to
// let authors call setState from within didUpdateWidget without triggering
// asserts.
_dirty
=
true
;
state
.
_widget
=
widget
as
StatefulWidget
;
state
.
_widget
=
widget
as
StatefulWidget
;
final
Object
?
debugCheckForReturnedFuture
=
state
.
didUpdateWidget
(
oldWidget
)
as
dynamic
;
final
Object
?
debugCheckForReturnedFuture
=
state
.
didUpdateWidget
(
oldWidget
)
as
dynamic
;
assert
(()
{
assert
(()
{
...
@@ -5080,7 +5072,7 @@ class StatefulElement extends ComponentElement {
...
@@ -5080,7 +5072,7 @@ class StatefulElement extends ComponentElement {
}
}
return
true
;
return
true
;
}());
}());
rebuild
(
force:
true
);
rebuild
();
}
}
@override
@override
...
@@ -5225,7 +5217,8 @@ abstract class ProxyElement extends ComponentElement {
...
@@ -5225,7 +5217,8 @@ abstract class ProxyElement extends ComponentElement {
super
.
update
(
newWidget
);
super
.
update
(
newWidget
);
assert
(
widget
==
newWidget
);
assert
(
widget
==
newWidget
);
updated
(
oldWidget
);
updated
(
oldWidget
);
rebuild
(
force:
true
);
_dirty
=
true
;
rebuild
();
}
}
/// Called during build when the [widget] has changed.
/// Called during build when the [widget] has changed.
...
@@ -5753,7 +5746,7 @@ abstract class RenderObjectElement extends Element {
...
@@ -5753,7 +5746,7 @@ abstract class RenderObjectElement extends Element {
}());
}());
assert
(
_slot
==
newSlot
);
assert
(
_slot
==
newSlot
);
attachRenderObject
(
newSlot
);
attachRenderObject
(
newSlot
);
super
.
performRebuild
();
// clears the "dirty" flag
_dirty
=
false
;
}
}
@override
@override
...
@@ -5775,7 +5768,7 @@ abstract class RenderObjectElement extends Element {
...
@@ -5775,7 +5768,7 @@ abstract class RenderObjectElement extends Element {
}
}
@override
@override
void
performRebuild
()
{
// ignore: must_call_super, _performRebuild calls super.
void
performRebuild
()
{
_performRebuild
();
// calls widget.updateRenderObject()
_performRebuild
();
// calls widget.updateRenderObject()
}
}
...
@@ -5790,7 +5783,7 @@ abstract class RenderObjectElement extends Element {
...
@@ -5790,7 +5783,7 @@ abstract class RenderObjectElement extends Element {
_debugDoingBuild
=
false
;
_debugDoingBuild
=
false
;
return
true
;
return
true
;
}());
}());
super
.
performRebuild
();
// clears the "dirty" flag
_dirty
=
false
;
}
}
/// Updates the children of this element to use new widgets.
/// Updates the children of this element to use new widgets.
...
@@ -6546,6 +6539,9 @@ class _NullElement extends Element {
...
@@ -6546,6 +6539,9 @@ class _NullElement extends Element {
@override
@override
bool
get
debugDoingBuild
=>
throw
UnimplementedError
();
bool
get
debugDoingBuild
=>
throw
UnimplementedError
();
@override
void
performRebuild
()
=>
throw
UnimplementedError
();
}
}
class
_NullWidget
extends
Widget
{
class
_NullWidget
extends
Widget
{
...
...
packages/flutter/test/cupertino/colors_test.dart
View file @
7887ca5b
...
@@ -591,6 +591,9 @@ class _NullElement extends Element {
...
@@ -591,6 +591,9 @@ class _NullElement extends Element {
@override
@override
bool
get
debugDoingBuild
=>
throw
UnimplementedError
();
bool
get
debugDoingBuild
=>
throw
UnimplementedError
();
@override
void
performRebuild
()
{
}
}
}
class
_NullWidget
extends
Widget
{
class
_NullWidget
extends
Widget
{
...
...
packages/flutter/test/foundation/diagnostics_json_test.dart
View file @
7887ca5b
...
@@ -220,6 +220,11 @@ void main() {
...
@@ -220,6 +220,11 @@ void main() {
class
_TestElement
extends
Element
{
class
_TestElement
extends
Element
{
_TestElement
()
:
super
(
const
Placeholder
());
_TestElement
()
:
super
(
const
Placeholder
());
@override
void
performRebuild
()
{
// Intentionally left empty.
}
@override
@override
bool
get
debugDoingBuild
=>
throw
UnimplementedError
();
bool
get
debugDoingBuild
=>
throw
UnimplementedError
();
}
}
...
...
packages/flutter/test/widgets/did_update_widget_test.dart
deleted
100644 → 0
View file @
dce82f7e
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:flutter/widgets.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
void
main
(
)
{
testWidgets
(
'Can call setState from didUpdateWidget'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
const
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
WidgetUnderTest
(
text:
'hello'
),
));
expect
(
find
.
text
(
'hello'
),
findsOneWidget
);
expect
(
find
.
text
(
'world'
),
findsNothing
);
final
_WidgetUnderTestState
state
=
tester
.
state
<
_WidgetUnderTestState
>(
find
.
byType
(
WidgetUnderTest
));
expect
(
state
.
setStateCalled
,
0
);
expect
(
state
.
didUpdateWidgetCalled
,
0
);
await
tester
.
pumpWidget
(
const
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
WidgetUnderTest
(
text:
'world'
),
));
expect
(
find
.
text
(
'world'
),
findsOneWidget
);
expect
(
find
.
text
(
'hello'
),
findsNothing
);
expect
(
state
.
setStateCalled
,
1
);
expect
(
state
.
didUpdateWidgetCalled
,
1
);
});
}
class
WidgetUnderTest
extends
StatefulWidget
{
const
WidgetUnderTest
({
super
.
key
,
required
this
.
text
});
final
String
text
;
@override
State
<
WidgetUnderTest
>
createState
()
=>
_WidgetUnderTestState
();
}
class
_WidgetUnderTestState
extends
State
<
WidgetUnderTest
>
{
late
String
text
=
widget
.
text
;
int
setStateCalled
=
0
;
int
didUpdateWidgetCalled
=
0
;
@override
void
didUpdateWidget
(
WidgetUnderTest
oldWidget
)
{
super
.
didUpdateWidget
(
oldWidget
);
didUpdateWidgetCalled
+=
1
;
if
(
oldWidget
.
text
!=
widget
.
text
)
{
// This setState is load bearing for the test.
setState
(()
{
text
=
widget
.
text
;
});
}
}
@override
void
setState
(
VoidCallback
fn
)
{
super
.
setState
(
fn
);
setStateCalled
+=
1
;
}
@override
Widget
build
(
BuildContext
context
)
{
return
Text
(
text
);
}
}
packages/flutter/test/widgets/framework_test.dart
View file @
7887ca5b
...
@@ -1861,6 +1861,9 @@ class DirtyElementWithCustomBuildOwner extends Element {
...
@@ -1861,6 +1861,9 @@ class DirtyElementWithCustomBuildOwner extends Element {
final
BuildOwner
_owner
;
final
BuildOwner
_owner
;
@override
void
performRebuild
()
{}
@override
@override
BuildOwner
get
owner
=>
_owner
;
BuildOwner
get
owner
=>
_owner
;
...
@@ -1965,9 +1968,9 @@ class StatefulElementSpy extends StatefulElement {
...
@@ -1965,9 +1968,9 @@ class StatefulElementSpy extends StatefulElement {
_Stateful
get
_statefulWidget
=>
widget
as
_Stateful
;
_Stateful
get
_statefulWidget
=>
widget
as
_Stateful
;
@override
@override
void
rebuild
(
{
bool
force
=
false
}
)
{
void
rebuild
()
{
_statefulWidget
.
onElementRebuild
?.
call
(
this
);
_statefulWidget
.
onElementRebuild
?.
call
(
this
);
super
.
rebuild
(
force:
force
);
super
.
rebuild
();
}
}
}
}
...
@@ -2112,6 +2115,9 @@ class _EmptyElement extends Element {
...
@@ -2112,6 +2115,9 @@ class _EmptyElement extends Element {
@override
@override
bool
get
debugDoingBuild
=>
false
;
bool
get
debugDoingBuild
=>
false
;
@override
void
performRebuild
()
{}
}
}
class
_TestLeaderLayerWidget
extends
SingleChildRenderObjectWidget
{
class
_TestLeaderLayerWidget
extends
SingleChildRenderObjectWidget
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment