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
fbe4cdf5
Commit
fbe4cdf5
authored
Feb 24, 2016
by
Eric Seidel
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2129 from eseidelGoogle/space_per_flex
Don't give children negative sizes when overconstrained
parents
2514d8a6
4e7a9de5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
3 deletions
+64
-3
flex.dart
packages/flutter/lib/src/rendering/flex.dart
+5
-3
flex_test.dart
packages/flutter/test/rendering/flex_test.dart
+59
-0
No files found.
packages/flutter/lib/src/rendering/flex.dart
View file @
fbe4cdf5
...
...
@@ -197,11 +197,11 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
BoxConstraints
childConstraints
;
switch
(
_direction
)
{
case
FlexDirection
.
horizontal
:
childConstraints
=
new
BoxConstraints
(
max
Width:
constraints
.
maxWidth
);
childConstraints
=
new
BoxConstraints
(
max
Height:
constraints
.
maxHeight
);
availableMainSpace
=
constraints
.
maxWidth
;
break
;
case
FlexDirection
.
vertical
:
childConstraints
=
new
BoxConstraints
(
max
Height:
constraints
.
maxHeight
);
childConstraints
=
new
BoxConstraints
(
max
Width:
constraints
.
maxWidth
);
availableMainSpace
=
constraints
.
maxHeight
;
break
;
}
...
...
@@ -239,7 +239,9 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
}
// Determine the spacePerFlex by allocating the remaining available space
double
spacePerFlex
=
(
availableMainSpace
-
inflexibleSpace
)
/
totalFlex
;
// When you're overconstrained spacePerFlex can be negative.
double
spacePerFlex
=
math
.
max
(
0.0
,
(
availableMainSpace
-
inflexibleSpace
)
/
totalFlex
);
// Size remaining items, find the maximum cross size
child
=
firstChild
;
...
...
packages/flutter/test/rendering/flex_test.dart
View file @
fbe4cdf5
...
...
@@ -19,6 +19,65 @@ void main() {
expect
(
flex
.
size
.
height
,
equals
(
200.0
),
reason:
"flex height"
);
});
test
(
'Vertical Overflow'
,
()
{
RenderConstrainedBox
flexible
=
new
RenderConstrainedBox
(
additionalConstraints:
const
BoxConstraints
.
expand
()
);
RenderFlex
flex
=
new
RenderFlex
(
direction:
FlexDirection
.
vertical
,
children:
<
RenderBox
>[
new
RenderConstrainedBox
(
additionalConstraints:
new
BoxConstraints
.
tightFor
(
height:
200.0
)),
flexible
,
]
);
FlexParentData
flexParentData
=
flexible
.
parentData
;
flexParentData
.
flex
=
1
;
BoxConstraints
viewport
=
new
BoxConstraints
(
maxHeight:
100.0
,
maxWidth:
100.0
);
layout
(
flex
,
constraints:
viewport
);
expect
(
flexible
.
size
.
height
,
equals
(
0.0
));
expect
(
flex
.
getMinIntrinsicHeight
(
viewport
),
equals
(
100.0
));
expect
(
flex
.
getMaxIntrinsicHeight
(
viewport
),
equals
(
100.0
));
expect
(
flex
.
getMinIntrinsicWidth
(
viewport
),
equals
(
100.0
));
expect
(
flex
.
getMaxIntrinsicWidth
(
viewport
),
equals
(
100.0
));
});
test
(
'Horizontal Overflow'
,
()
{
RenderConstrainedBox
flexible
=
new
RenderConstrainedBox
(
additionalConstraints:
const
BoxConstraints
.
expand
()
);
RenderFlex
flex
=
new
RenderFlex
(
direction:
FlexDirection
.
horizontal
,
children:
<
RenderBox
>[
new
RenderConstrainedBox
(
additionalConstraints:
new
BoxConstraints
.
tightFor
(
width:
200.0
)),
flexible
,
]
);
FlexParentData
flexParentData
=
flexible
.
parentData
;
flexParentData
.
flex
=
1
;
BoxConstraints
viewport
=
new
BoxConstraints
(
maxHeight:
100.0
,
maxWidth:
100.0
);
layout
(
flex
,
constraints:
viewport
);
expect
(
flexible
.
size
.
width
,
equals
(
0.0
));
expect
(
flex
.
getMinIntrinsicHeight
(
viewport
),
equals
(
100.0
));
expect
(
flex
.
getMaxIntrinsicHeight
(
viewport
),
equals
(
100.0
));
expect
(
flex
.
getMinIntrinsicWidth
(
viewport
),
equals
(
100.0
));
expect
(
flex
.
getMaxIntrinsicWidth
(
viewport
),
equals
(
100.0
));
});
test
(
'Vertical Flipped Constraints'
,
()
{
RenderFlex
flex
=
new
RenderFlex
(
direction:
FlexDirection
.
vertical
,
children:
<
RenderBox
>[
new
RenderAspectRatio
(
aspectRatio:
1.0
),
]
);
BoxConstraints
viewport
=
new
BoxConstraints
(
maxHeight:
200.0
,
maxWidth:
1000.0
);
layout
(
flex
,
constraints:
viewport
);
expect
(
flex
.
getMaxIntrinsicWidth
(
viewport
)
,
equals
(
1000.0
));
});
// We can't right a horizontal version of the above test due to
// RenderAspectRatio being height-in, width-out.
test
(
'Defaults'
,
()
{
RenderFlex
flex
=
new
RenderFlex
();
expect
(
flex
.
alignItems
,
equals
(
FlexAlignItems
.
center
));
...
...
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