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
c6942c99
Commit
c6942c99
authored
Apr 26, 2016
by
Adam Barth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement MainAxisAlignment.spaceEvenly (#3550)
Fixes #3289
parent
2047c70e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
12 deletions
+58
-12
flex.dart
packages/flutter/lib/src/rendering/flex.dart
+28
-12
flex_test.dart
packages/flutter/test/rendering/flex_test.dart
+30
-0
No files found.
packages/flutter/lib/src/rendering/flex.dart
View file @
c6942c99
...
...
@@ -29,33 +29,45 @@ enum FlexDirection {
vertical
}
/// How the children should be placed along the main axis in a flex layout
/// How the children should be placed along the main axis in a flex layout
.
enum
MainAxisAlignment
{
/// Place the children as close to the start of the main axis as possible
/// Place the children as close to the start of the main axis as possible
.
start
,
/// Place the children as close to the end of the main axis as possible
/// Place the children as close to the end of the main axis as possible.
end
,
/// Place the children as close to the middle of the main axis as possible
/// Place the children as close to the middle of the main axis as possible.
center
,
/// Place the free space evenly between the children
/// Place the free space evenly between the children.
spaceBetween
,
/// Place the free space evenly between the children as well as before and after the first and last child
/// Place the free space evenly between the children as well as half of that space before and after the first and last child.
spaceAround
,
/// Place the free space evenly between the children as well as before and after the first and last child.
spaceEvenly
,
/// Do not expand to fill the free space. None of the children may specify a flex factor.
collapse
,
}
/// How the children should be placed along the cross axis in a flex layout
/// How the children should be placed along the cross axis in a flex layout
.
enum
CrossAxisAlignment
{
/// Place the children as close to the start of the cross axis as possible
/// Place the children as close to the start of the cross axis as possible
.
start
,
/// Place the children as close to the end of the cross axis as possible
/// Place the children as close to the end of the cross axis as possible.
end
,
/// Place the children as close to the middle of the cross axis as possible
/// Place the children as close to the middle of the cross axis as possible.
center
,
/// Require the children to fill the cross axis
/// Require the children to fill the cross axis.
stretch
,
/// Place the children along the cross axis such that their baselines match
/// Place the children along the cross axis such that their baselines match.
baseline
,
}
...
...
@@ -562,6 +574,10 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
betweenSpace
=
totalChildren
>
0
?
remainingSpace
/
totalChildren
:
0.0
;
leadingSpace
=
betweenSpace
/
2.0
;
break
;
case
MainAxisAlignment
.
spaceEvenly
:
betweenSpace
=
totalChildren
>
0
?
remainingSpace
/
(
totalChildren
+
1
)
:
0.0
;
leadingSpace
=
betweenSpace
;
break
;
}
// Position elements
...
...
packages/flutter/test/rendering/flex_test.dart
View file @
c6942c99
...
...
@@ -136,4 +136,34 @@ void main() {
expect
(
box2
.
size
.
width
,
equals
(
100.0
));
expect
(
box2
.
size
.
height
,
equals
(
100.0
));
});
test
(
'Space evenly'
,
()
{
RenderConstrainedBox
box1
=
new
RenderConstrainedBox
(
additionalConstraints:
new
BoxConstraints
.
tightFor
(
width:
100.0
,
height:
100.0
));
RenderConstrainedBox
box2
=
new
RenderConstrainedBox
(
additionalConstraints:
new
BoxConstraints
.
tightFor
(
width:
100.0
,
height:
100.0
));
RenderConstrainedBox
box3
=
new
RenderConstrainedBox
(
additionalConstraints:
new
BoxConstraints
.
tightFor
(
width:
100.0
,
height:
100.0
));
RenderFlex
flex
=
new
RenderFlex
(
mainAxisAlignment:
MainAxisAlignment
.
spaceEvenly
);
flex
.
addAll
(<
RenderBox
>[
box1
,
box2
,
box3
]);
layout
(
flex
,
constraints:
const
BoxConstraints
(
minWidth:
0.0
,
maxWidth:
500.0
,
minHeight:
0.0
,
maxHeight:
400.0
)
);
Offset
getOffset
(
RenderBox
box
)
{
FlexParentData
parentData
=
box
.
parentData
;
return
parentData
.
offset
;
}
expect
(
getOffset
(
box1
).
dx
,
equals
(
50.0
));
expect
(
box1
.
size
.
width
,
equals
(
100.0
));
expect
(
getOffset
(
box2
).
dx
,
equals
(
200.0
));
expect
(
box2
.
size
.
width
,
equals
(
100.0
));
expect
(
getOffset
(
box3
).
dx
,
equals
(
350.0
));
expect
(
box3
.
size
.
width
,
equals
(
100.0
));
flex
.
direction
=
FlexDirection
.
vertical
;
pumpFrame
();
expect
(
getOffset
(
box1
).
dy
,
equals
(
25.0
));
expect
(
box1
.
size
.
height
,
equals
(
100.0
));
expect
(
getOffset
(
box2
).
dy
,
equals
(
150.0
));
expect
(
box2
.
size
.
height
,
equals
(
100.0
));
expect
(
getOffset
(
box3
).
dy
,
equals
(
275.0
));
expect
(
box3
.
size
.
height
,
equals
(
100.0
));
});
}
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