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
468471bf
Unverified
Commit
468471bf
authored
May 18, 2021
by
YeungKC
Committed by
GitHub
May 18, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix wrap compute max intrinsic width/height with spacing (#82609)
parent
d27a9427
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
2 deletions
+91
-2
wrap.dart
packages/flutter/lib/src/rendering/wrap.dart
+2
-2
wrap_test.dart
packages/flutter/test/rendering/wrap_test.dart
+89
-0
No files found.
packages/flutter/lib/src/rendering/wrap.dart
View file @
468471bf
...
...
@@ -421,7 +421,7 @@ class RenderWrap extends RenderBox
double
computeMaxIntrinsicWidth
(
double
height
)
{
switch
(
direction
)
{
case
Axis
.
horizontal
:
double
width
=
0.0
;
double
width
=
math
.
max
(
childCount
-
1
,
0
)
*
spacing
;
RenderBox
?
child
=
firstChild
;
while
(
child
!=
null
)
{
width
+=
child
.
getMaxIntrinsicWidth
(
double
.
infinity
);
...
...
@@ -455,7 +455,7 @@ class RenderWrap extends RenderBox
case
Axis
.
horizontal
:
return
computeDryLayout
(
BoxConstraints
(
maxWidth:
width
)).
height
;
case
Axis
.
vertical
:
double
height
=
0.0
;
double
height
=
math
.
max
(
childCount
-
1
,
0
)
*
spacing
;
RenderBox
?
child
=
firstChild
;
while
(
child
!=
null
)
{
height
+=
child
.
getMaxIntrinsicHeight
(
double
.
infinity
);
...
...
packages/flutter/test/rendering/wrap_test.dart
View file @
468471bf
...
...
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:math'
as
math
;
import
'package:flutter/rendering.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
...
...
@@ -219,4 +221,91 @@ void main() {
expect
(
context
.
clipBehavior
,
equals
(
clip
));
}
});
test
(
'Compute max intrinsic height with spacing'
,
()
{
const
double
itemWidth
=
64
;
const
double
itemHeight
=
32
;
final
RenderBox
child
=
RenderConstrainedBox
(
additionalConstraints:
const
BoxConstraints
.
tightFor
(
width:
itemWidth
,
height:
itemHeight
,
),
);
final
RenderWrap
renderWrap
=
RenderWrap
();
renderWrap
.
add
(
child
);
renderWrap
.
spacing
=
5
;
renderWrap
.
direction
=
Axis
.
vertical
;
expect
(
renderWrap
.
computeMaxIntrinsicHeight
(
double
.
infinity
),
itemHeight
);
final
List
<
RenderBox
>
children
=
<
RenderBox
>[
RenderConstrainedBox
(
additionalConstraints:
const
BoxConstraints
.
tightFor
(
width:
itemWidth
,
height:
itemHeight
,
),
),
RenderConstrainedBox
(
additionalConstraints:
const
BoxConstraints
.
tightFor
(
width:
itemWidth
,
height:
itemHeight
,
),
),
];
children
.
forEach
(
renderWrap
.
add
);
final
double
childrenHeight
=
renderWrap
.
childCount
*
itemHeight
;
final
double
spacingHeight
=
math
.
max
(
renderWrap
.
childCount
-
1
,
0
)
*
renderWrap
.
spacing
;
expect
(
renderWrap
.
computeMaxIntrinsicHeight
(
double
.
infinity
),
childrenHeight
+
spacingHeight
);
});
test
(
'Compute max intrinsic width with spacing'
,
()
{
const
double
itemWidth
=
64
;
const
double
itemHeight
=
32
;
final
RenderBox
child
=
RenderConstrainedBox
(
additionalConstraints:
const
BoxConstraints
.
tightFor
(
width:
itemWidth
,
height:
itemHeight
,
),
);
final
RenderWrap
renderWrap
=
RenderWrap
();
renderWrap
.
add
(
child
);
renderWrap
.
spacing
=
5
;
renderWrap
.
direction
=
Axis
.
horizontal
;
expect
(
renderWrap
.
computeMaxIntrinsicWidth
(
double
.
infinity
),
itemWidth
);
final
List
<
RenderBox
>
children
=
<
RenderBox
>[
RenderConstrainedBox
(
additionalConstraints:
const
BoxConstraints
.
tightFor
(
width:
itemWidth
,
height:
itemHeight
,
),
),
RenderConstrainedBox
(
additionalConstraints:
const
BoxConstraints
.
tightFor
(
width:
itemWidth
,
height:
itemHeight
,
),
),
];
children
.
forEach
(
renderWrap
.
add
);
final
double
childrenWidth
=
renderWrap
.
childCount
*
itemWidth
;
final
double
spacingWidth
=
math
.
max
(
renderWrap
.
childCount
-
1
,
0
)
*
renderWrap
.
spacing
;
expect
(
renderWrap
.
computeMaxIntrinsicWidth
(
double
.
infinity
),
childrenWidth
+
spacingWidth
);
});
}
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