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
5766cdac
Commit
5766cdac
authored
Jun 15, 2016
by
Hans Muller
Committed by
GitHub
Jun 15, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Define LayoutWidgetBuilder in terms of BoxConstraints instead of Size (#4578)
parent
661740d2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
91 additions
and
72 deletions
+91
-72
pesto_demo.dart
examples/flutter_gallery/lib/demo/pesto_demo.dart
+29
-22
app_bar.dart
packages/flutter/lib/src/material/app_bar.dart
+5
-2
layout_builder.dart
packages/flutter/lib/src/widgets/layout_builder.dart
+12
-15
layout_builder_test.dart
packages/flutter/test/widget/layout_builder_test.dart
+45
-33
No files found.
examples/flutter_gallery/lib/demo/pesto_demo.dart
View file @
5766cdac
...
...
@@ -90,7 +90,8 @@ class _PestoDemoState extends State<PestoDemo> {
)
],
flexibleSpace:
new
LayoutBuilder
(
builder:
(
BuildContext
context
,
Size
size
)
{
builder:
(
BuildContext
context
,
BoxConstraints
constraints
)
{
final
Size
size
=
constraints
.
biggest
;
double
appBarHeight
=
size
.
height
-
statusBarHeight
;
double
bestHeight
=
_kLogoImages
.
keys
.
lastWhere
(
(
double
height
)
=>
appBarHeight
>=
height
...
...
@@ -293,27 +294,33 @@ class _RecipePageState extends State<_RecipePage> {
return
new
Stack
(
children:
<
Widget
>[
_buildContainer
(
context
),
new
Padding
(
padding:
new
EdgeInsets
.
only
(
top:
statusBarHeight
),
child:
new
AppBar
(
backgroundColor:
Colors
.
transparent
,
elevation:
0
,
leading:
new
IconButton
(
icon:
Icons
.
arrow_back
,
onPressed:
()
=>
Navigator
.
pop
(
context
),
tooltip:
'Back'
),
actions:
<
Widget
>[
new
PopupMenuButton
<
String
>(
onSelected:
(
String
item
)
{},
itemBuilder:
(
BuildContext
context
)
=>
<
PopupMenuItem
<
String
>>[
_buildMenuItem
(
Icons
.
share
,
'Tweet recipe'
),
_buildMenuItem
(
Icons
.
email
,
'Email recipe'
),
_buildMenuItem
(
Icons
.
message
,
'Message recipe'
),
_buildMenuItem
(
Icons
.
people
,
'Share on Facebook'
),
]
)
]
new
Positioned
(
top:
0.0
,
left:
0.0
,
right:
0.0
,
child:
new
Container
(
height:
kToolBarHeight
+
statusBarHeight
,
padding:
new
EdgeInsets
.
only
(
top:
statusBarHeight
),
child:
new
AppBar
(
backgroundColor:
Colors
.
transparent
,
elevation:
0
,
leading:
new
IconButton
(
icon:
Icons
.
arrow_back
,
onPressed:
()
=>
Navigator
.
pop
(
context
),
tooltip:
'Back'
),
actions:
<
Widget
>[
new
PopupMenuButton
<
String
>(
onSelected:
(
String
item
)
{},
itemBuilder:
(
BuildContext
context
)
=>
<
PopupMenuItem
<
String
>>[
_buildMenuItem
(
Icons
.
share
,
'Tweet recipe'
),
_buildMenuItem
(
Icons
.
email
,
'Email recipe'
),
_buildMenuItem
(
Icons
.
message
,
'Message recipe'
),
_buildMenuItem
(
Icons
.
people
,
'Share on Facebook'
),
]
)
]
)
)
)
]
...
...
packages/flutter/lib/src/material/app_bar.dart
View file @
5766cdac
...
...
@@ -178,8 +178,9 @@ class AppBar extends StatelessWidget {
return
((
appBarHeight
-
statusBarHeight
)
/
tabBarHeight
).
clamp
(
0.0
,
1.0
);
}
Widget
_buildForSize
(
BuildContext
context
,
Size
size
)
{
assert
(
size
.
height
<
double
.
INFINITY
);
Widget
_buildForSize
(
BuildContext
context
,
BoxConstraints
constraints
)
{
assert
(
constraints
.
maxHeight
<
double
.
INFINITY
);
final
Size
size
=
constraints
.
biggest
;
final
double
statusBarHeight
=
MediaQuery
.
of
(
context
).
padding
.
top
;
final
ThemeData
theme
=
Theme
.
of
(
context
);
...
...
@@ -274,6 +275,8 @@ class AppBar extends StatelessWidget {
child:
appBar
)
);
}
else
if
(
flexibleSpace
!=
null
)
{
appBar
=
new
Positioned
(
top:
0.0
,
left:
0.0
,
right:
0.0
,
child:
appBar
);
}
if
(
flexibleSpace
!=
null
)
{
...
...
packages/flutter/lib/src/widgets/layout_builder.dart
View file @
5766cdac
...
...
@@ -9,14 +9,15 @@ import 'package:flutter/rendering.dart';
import
'package:meta/meta.dart'
;
/// The signature of the [LayoutBuilder] builder function.
typedef
Widget
LayoutWidgetBuilder
(
BuildContext
context
,
Size
size
);
typedef
Widget
LayoutWidgetBuilder
(
BuildContext
context
,
BoxConstraints
constraints
);
/// Builds a widget tree that can depend on the parent widget's size.
///
/// Similar to the [Builder] widget except that the framework calls the [builder]
/// function at layout time and provides the parent widget's size. This is useful
/// when the parent constrains the child's size and doesn't depend on the child's
/// intrinsic size.
/// function at layout time and provides the parent widget's constraints. This
/// is useful when the parent constrains the child's size and doesn't depend on
/// the child's intrinsic size. The LayoutBuilder's final size will match its
/// child's size.
class
LayoutBuilder
extends
RenderObjectWidget
{
/// Creates a widget that defers its building until layout.
///
...
...
@@ -89,20 +90,16 @@ class _RenderLayoutBuilder extends RenderBox with RenderObjectWithChildMixin<Ren
return
0.0
;
}
@override
bool
get
sizedByParent
=>
true
;
@override
void
performResize
()
{
size
=
constraints
.
biggest
;
}
@override
void
performLayout
()
{
if
(
callback
!=
null
)
invokeLayoutCallback
(
callback
);
if
(
child
!=
null
)
child
.
layout
(
constraints
.
loosen
());
if
(
child
!=
null
)
{
child
.
layout
(
constraints
,
parentUsesSize:
true
);
size
=
constraints
.
constrain
(
child
.
size
);
}
else
{
size
=
constraints
.
biggest
;
}
}
@override
...
...
@@ -169,7 +166,7 @@ class _LayoutBuilderElement extends RenderObjectElement {
owner
.
lockState
(()
{
Widget
built
;
try
{
built
=
widget
.
builder
(
this
,
constraints
.
biggest
);
built
=
widget
.
builder
(
this
,
constraints
);
debugWidgetBuilderValue
(
widget
,
built
);
}
catch
(
e
,
stack
)
{
_debugReportException
(
'building
$widget
'
,
e
,
stack
);
...
...
packages/flutter/test/widget/layout_builder_test.dart
View file @
5766cdac
...
...
@@ -10,19 +10,20 @@ void main() {
testWidgets
(
'LayoutBuilder parent size'
,
(
WidgetTester
tester
)
async
{
Size
layoutBuilderSize
;
Key
childKey
=
new
UniqueKey
();
Key
parentKey
=
new
UniqueKey
();
await
tester
.
pumpWidget
(
new
Center
(
child:
new
SizedBox
(
width:
100.0
,
height:
200.0
,
child:
new
ConstrainedBox
(
constraints:
const
BoxConstraints
(
maxWidth:
100.0
,
maxHeight:
200.0
),
child:
new
LayoutBuilder
(
builder:
(
BuildContext
context
,
Size
size
)
{
layoutBuilderSize
=
size
;
key:
parentKey
,
builder:
(
BuildContext
context
,
BoxConstraints
constraints
)
{
layoutBuilderSize
=
constraints
.
biggest
;
return
new
SizedBox
(
key:
childKey
,
width:
s
ize
.
width
/
2.0
,
height:
s
ize
.
height
/
2.0
width:
layoutBuilderS
ize
.
width
/
2.0
,
height:
layoutBuilderS
ize
.
height
/
2.0
);
}
)
...
...
@@ -31,46 +32,56 @@ void main() {
);
expect
(
layoutBuilderSize
,
const
Size
(
100.0
,
200.0
));
RenderBox
box
=
tester
.
renderObject
(
find
.
byKey
(
childKey
));
expect
(
box
.
size
,
equals
(
const
Size
(
50.0
,
100.0
)));
RenderBox
parentBox
=
tester
.
renderObject
(
find
.
byKey
(
parentKey
));
expect
(
parentBox
.
size
,
equals
(
const
Size
(
50.0
,
100.0
)));
RenderBox
childBox
=
tester
.
renderObject
(
find
.
byKey
(
childKey
));
expect
(
childBox
.
size
,
equals
(
const
Size
(
50.0
,
100.0
)));
});
testWidgets
(
'LayoutBuilder stateful child'
,
(
WidgetTester
tester
)
async
{
Size
layoutBuilderSize
;
StateSetter
setState
;
Key
childKey
=
new
UniqueKey
();
Key
parentKey
=
new
UniqueKey
();
double
childWidth
=
10.0
;
double
childHeight
=
20.0
;
await
tester
.
pumpWidget
(
new
LayoutBuilder
(
builder:
(
BuildContext
context
,
Size
size
)
{
layoutBuilderSize
=
size
;
return
new
StatefulBuilder
(
builder:
(
BuildContext
context
,
StateSetter
setter
)
{
setState
=
setter
;
return
new
SizedBox
(
key:
childKey
,
width:
childWidth
,
height:
childHeight
);
}
);
}
new
Center
(
child:
new
LayoutBuilder
(
key:
parentKey
,
builder:
(
BuildContext
context
,
BoxConstraints
constraints
)
{
layoutBuilderSize
=
constraints
.
biggest
;
return
new
StatefulBuilder
(
builder:
(
BuildContext
context
,
StateSetter
setter
)
{
setState
=
setter
;
return
new
SizedBox
(
key:
childKey
,
width:
childWidth
,
height:
childHeight
);
}
);
}
)
)
);
expect
(
layoutBuilderSize
,
equals
(
const
Size
(
800.0
,
600.0
)));
RenderBox
box
=
tester
.
renderObject
(
find
.
byKey
(
childKey
));
expect
(
box
.
size
,
equals
(
const
Size
(
10.0
,
20.0
)));
RenderBox
parentBox
=
tester
.
renderObject
(
find
.
byKey
(
parentKey
));
expect
(
parentBox
.
size
,
equals
(
const
Size
(
10.0
,
20.0
)));
RenderBox
childBox
=
tester
.
renderObject
(
find
.
byKey
(
childKey
));
expect
(
childBox
.
size
,
equals
(
const
Size
(
10.0
,
20.0
)));
setState
(()
{
childWidth
=
100.0
;
childHeight
=
200.0
;
});
await
tester
.
pump
();
box
=
tester
.
renderObject
(
find
.
byKey
(
childKey
));
expect
(
box
.
size
,
equals
(
const
Size
(
100.0
,
200.0
)));
parentBox
=
tester
.
renderObject
(
find
.
byKey
(
parentKey
));
expect
(
parentBox
.
size
,
equals
(
const
Size
(
100.0
,
200.0
)));
childBox
=
tester
.
renderObject
(
find
.
byKey
(
childKey
));
expect
(
childBox
.
size
,
equals
(
const
Size
(
100.0
,
200.0
)));
});
testWidgets
(
'LayoutBuilder stateful parent'
,
(
WidgetTester
tester
)
async
{
...
...
@@ -89,12 +100,12 @@ void main() {
width:
childWidth
,
height:
childHeight
,
child:
new
LayoutBuilder
(
builder:
(
BuildContext
context
,
Size
size
)
{
layoutBuilderSize
=
size
;
builder:
(
BuildContext
context
,
BoxConstraints
constraints
)
{
layoutBuilderSize
=
constraints
.
biggest
;
return
new
SizedBox
(
key:
childKey
,
width:
s
ize
.
width
,
height:
s
ize
.
height
width:
layoutBuilderS
ize
.
width
,
height:
layoutBuilderS
ize
.
height
);
}
)
...
...
@@ -117,10 +128,11 @@ void main() {
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
)
{
builder:
(
BuildContext
context
,
BoxConstraints
constraints
)
{
built
+=
1
;
return
new
Container
();
}
...
...
@@ -143,7 +155,7 @@ void main() {
testWidgets
(
'LayoutBuilder and Inherited -- do rebuild when using inherited'
,
(
WidgetTester
tester
)
async
{
int
built
=
0
;
Widget
target
=
new
LayoutBuilder
(
builder:
(
BuildContext
context
,
Size
size
)
{
builder:
(
BuildContext
context
,
BoxConstraints
constraints
)
{
built
+=
1
;
MediaQuery
.
of
(
context
);
return
new
Container
();
...
...
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