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
dd8413c6
Commit
dd8413c6
authored
Mar 15, 2016
by
Adam Barth
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2695 from abarth/inherit_render_object_widget
Let RenderObjectWidgets use inherited properties
parents
2eb26565
3ebd4c58
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
11 deletions
+59
-11
framework.dart
packages/flutter/lib/src/widgets/framework.dart
+14
-11
render_object_widget_test.dart
packages/flutter/test/widget/render_object_widget_test.dart
+45
-0
No files found.
packages/flutter/lib/src/widgets/framework.dart
View file @
dd8413c6
...
...
@@ -1165,6 +1165,13 @@ abstract class BuildableElement extends Element {
assert
(
_debugLifecycleState
==
_ElementLifecycle
.
active
);
assert
(()
{
if
(
_debugBuilding
)
{
if
(
_debugCurrentBuildTarget
==
null
)
{
// If _debugCurrentBuildTarget is null, we're not actually building a
// widget but instead building the root of the tree via runApp.
// TODO(abarth): Remove these cases and ensure that we always have
// a current build target when we're building.
return
true
;
}
bool
foundTarget
=
false
;
visitAncestorElements
((
Element
element
)
{
if
(
element
==
_debugCurrentBuildTarget
)
{
...
...
@@ -1214,17 +1221,12 @@ abstract class BuildableElement extends Element {
_debugCurrentBuildTarget
=
this
;
return
true
;
});
try
{
performRebuild
();
}
catch
(
e
,
stack
)
{
_debugReportException
(
'rebuilding
$this
'
,
e
,
stack
);
}
finally
{
assert
(()
{
assert
(
_debugCurrentBuildTarget
==
this
);
_debugCurrentBuildTarget
=
debugPreviousBuildTarget
;
return
true
;
});
}
assert
(!
_dirty
);
}
...
...
@@ -1618,6 +1620,7 @@ abstract class RenderObjectElement extends BuildableElement {
@override
void
performRebuild
()
{
widget
.
updateRenderObject
(
this
,
renderObject
);
_dirty
=
false
;
}
...
...
packages/flutter/test/widget/render_object_widget_test.dart
View file @
dd8413c6
...
...
@@ -20,6 +20,27 @@ class TestWidget extends StatelessWidget {
Widget
build
(
BuildContext
context
)
=>
child
;
}
class
TestOrientedBox
extends
SingleChildRenderObjectWidget
{
TestOrientedBox
({
Key
key
,
Widget
child
})
:
super
(
key:
key
,
child:
child
);
Decoration
_getDecoration
(
BuildContext
context
)
{
switch
(
MediaQuery
.
of
(
context
).
orientation
)
{
case
Orientation
.
landscape
:
return
new
BoxDecoration
(
backgroundColor:
const
Color
(
0xFF00FF00
));
case
Orientation
.
portrait
:
return
new
BoxDecoration
(
backgroundColor:
const
Color
(
0xFF0000FF
));
}
}
@override
RenderDecoratedBox
createRenderObject
(
BuildContext
context
)
=>
new
RenderDecoratedBox
(
decoration:
_getDecoration
(
context
));
@override
void
updateRenderObject
(
BuildContext
context
,
RenderDecoratedBox
renderObject
)
{
renderObject
.
decoration
=
_getDecoration
(
context
);
}
}
void
main
(
)
{
test
(
'RenderObjectWidget smoke test'
,
()
{
testWidgets
((
WidgetTester
tester
)
{
...
...
@@ -171,4 +192,28 @@ void main() {
expect
(
grandChild
.
child
,
isNull
);
});
});
test
(
'Can watch inherited widgets'
,
()
{
testWidgets
((
WidgetTester
tester
)
{
Key
boxKey
=
new
UniqueKey
();
TestOrientedBox
box
=
new
TestOrientedBox
(
key:
boxKey
);
tester
.
pumpWidget
(
new
MediaQuery
(
data:
new
MediaQueryData
(
size:
const
Size
(
400.0
,
300.0
)),
child:
box
));
RenderDecoratedBox
renderBox
=
tester
.
findElementByKey
(
boxKey
).
renderObject
;
BoxDecoration
decoration
=
renderBox
.
decoration
;
expect
(
decoration
.
backgroundColor
,
equals
(
new
Color
(
0xFF00FF00
)));
tester
.
pumpWidget
(
new
MediaQuery
(
data:
new
MediaQueryData
(
size:
const
Size
(
300.0
,
400.0
)),
child:
box
));
decoration
=
renderBox
.
decoration
;
expect
(
decoration
.
backgroundColor
,
equals
(
new
Color
(
0xFF0000FF
)));
});
});
}
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