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
3b3db78f
Commit
3b3db78f
authored
May 23, 2016
by
Ian Hickson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Teach LayoutBuilder about Inherited widgets. (#4140)
parent
390c7ce2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
2 deletions
+57
-2
framework.dart
packages/flutter/lib/src/widgets/framework.dart
+1
-1
layout_builder.dart
packages/flutter/lib/src/widgets/layout_builder.dart
+9
-1
layout_builder_test.dart
packages/flutter/test/widget/layout_builder_test.dart
+47
-0
No files found.
packages/flutter/lib/src/widgets/framework.dart
View file @
3b3db78f
...
...
@@ -1825,7 +1825,6 @@ class InheritedElement extends _ProxyElement {
/// the build phase.
void
dispatchDependenciesChanged
()
{
for
(
Element
dependent
in
_dependents
)
{
dependent
.
dependenciesChanged
();
assert
(()
{
// check that it really is our descendant
Element
ancestor
=
dependent
.
_parent
;
...
...
@@ -1835,6 +1834,7 @@ class InheritedElement extends _ProxyElement {
});
// check that it really deepends on us
assert
(
dependent
.
_dependencies
.
contains
(
this
));
dependent
.
dependenciesChanged
();
}
}
}
...
...
packages/flutter/lib/src/widgets/layout_builder.dart
View file @
3b3db78f
...
...
@@ -119,7 +119,7 @@ class _LayoutBuilderElement extends RenderObjectElement {
@override
void
mount
(
Element
parent
,
dynamic
newSlot
)
{
super
.
mount
(
parent
,
newSlot
);
// Creates the renderObject.
super
.
mount
(
parent
,
newSlot
);
// Creates the renderObject.
renderObject
.
callback
=
_layout
;
// The _child will be built during layout.
}
...
...
@@ -132,6 +132,14 @@ class _LayoutBuilderElement extends RenderObjectElement {
renderObject
.
markNeedsLayout
();
}
@override
void
performRebuild
()
{
// This gets called if markNeedsBuild() is called on us.
// That might happen if, e.g., our builder uses Inherited widgets.
renderObject
.
markNeedsLayout
();
super
.
performRebuild
();
// calls widget.updateRenderObject
}
@override
void
unmount
()
{
renderObject
.
callback
=
null
;
...
...
packages/flutter/test/widget/layout_builder_test.dart
View file @
3b3db78f
...
...
@@ -116,4 +116,51 @@ void main() {
box
=
tester
.
renderObject
(
find
.
byKey
(
childKey
));
expect
(
box
.
size
,
equals
(
const
Size
(
100.0
,
200.0
)));
});
testWidgets
(
'LayoutBuilder and Inherited -- do not rebuild when not using inherited'
,
(
WidgetTester
tester
)
async
{
int
built
=
0
;
Widget
target
=
new
LayoutBuilder
(
builder:
(
BuildContext
context
,
Size
size
)
{
built
+=
1
;
return
new
Container
();
}
);
expect
(
built
,
0
);
await
tester
.
pumpWidget
(
new
MediaQuery
(
data:
new
MediaQueryData
(
size:
const
Size
(
400.0
,
300.0
)),
child:
target
));
expect
(
built
,
1
);
await
tester
.
pumpWidget
(
new
MediaQuery
(
data:
new
MediaQueryData
(
size:
const
Size
(
300.0
,
400.0
)),
child:
target
));
expect
(
built
,
1
);
});
testWidgets
(
'LayoutBuilder and Inherited -- do rebuild when using inherited'
,
(
WidgetTester
tester
)
async
{
int
built
=
0
;
Widget
target
=
new
LayoutBuilder
(
builder:
(
BuildContext
context
,
Size
size
)
{
built
+=
1
;
MediaQuery
.
of
(
context
);
return
new
Container
();
}
);
expect
(
built
,
0
);
await
tester
.
pumpWidget
(
new
MediaQuery
(
data:
new
MediaQueryData
(
size:
const
Size
(
400.0
,
300.0
)),
child:
target
));
expect
(
built
,
1
);
await
tester
.
pumpWidget
(
new
MediaQuery
(
data:
new
MediaQueryData
(
size:
const
Size
(
300.0
,
400.0
)),
child:
target
));
expect
(
built
,
2
);
});
}
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