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
9e0ad9b6
Unverified
Commit
9e0ad9b6
authored
Aug 18, 2020
by
Andre
Committed by
GitHub
Aug 18, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix FittedBox BoxFit.scaleDown sizing (#63668)
parent
654022ae
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
131 additions
and
3 deletions
+131
-3
proxy_box.dart
packages/flutter/lib/src/rendering/proxy_box.dart
+26
-3
fitted_box_test.dart
packages/flutter/test/widgets/fitted_box_test.dart
+105
-0
No files found.
packages/flutter/lib/src/rendering/proxy_box.dart
View file @
9e0ad9b6
...
...
@@ -2352,6 +2352,15 @@ class RenderFittedBox extends RenderProxyBox {
markNeedsPaint
();
}
bool
_fitAffectsLayout
(
BoxFit
fit
)
{
switch
(
fit
)
{
case
BoxFit
.
scaleDown
:
return
true
;
default
:
return
false
;
}
}
/// How to inscribe the child into the space allocated during layout.
BoxFit
get
fit
=>
_fit
;
BoxFit
_fit
;
...
...
@@ -2359,9 +2368,14 @@ class RenderFittedBox extends RenderProxyBox {
assert
(
value
!=
null
);
if
(
_fit
==
value
)
return
;
final
BoxFit
lastFit
=
_fit
;
_fit
=
value
;
_clearPaintData
();
markNeedsPaint
();
if
(
_fitAffectsLayout
(
lastFit
)
||
_fitAffectsLayout
(
value
))
{
markNeedsLayout
();
}
else
{
_clearPaintData
();
markNeedsPaint
();
}
}
/// How to align the child within its parent's bounds.
...
...
@@ -2403,7 +2417,16 @@ class RenderFittedBox extends RenderProxyBox {
void
performLayout
()
{
if
(
child
!=
null
)
{
child
.
layout
(
const
BoxConstraints
(),
parentUsesSize:
true
);
size
=
constraints
.
constrainSizeAndAttemptToPreserveAspectRatio
(
child
.
size
);
switch
(
fit
)
{
case
BoxFit
.
scaleDown
:
final
BoxConstraints
sizeConstraints
=
constraints
.
loosen
();
final
Size
unconstrainedSize
=
sizeConstraints
.
constrainSizeAndAttemptToPreserveAspectRatio
(
child
.
size
);
size
=
constraints
.
constrain
(
unconstrainedSize
);
break
;
default
:
size
=
constraints
.
constrainSizeAndAttemptToPreserveAspectRatio
(
child
.
size
);
break
;
}
_clearPaintData
();
}
else
{
size
=
constraints
.
smallest
;
...
...
packages/flutter/test/widgets/fitted_box_test.dart
View file @
9e0ad9b6
...
...
@@ -486,6 +486,111 @@ void main() {
await
tester
.
pumpWidget
(
FittedBox
(
fit:
BoxFit
.
none
,
child:
Container
(),
clipBehavior:
Clip
.
antiAlias
));
expect
(
renderObject
.
clipBehavior
,
equals
(
Clip
.
antiAlias
));
});
testWidgets
(
'BoxFit.scaleDown matches size of child'
,
(
WidgetTester
tester
)
async
{
final
Key
outside
=
UniqueKey
();
final
Key
inside
=
UniqueKey
();
// Does not scale up when child is smaller than constraints
await
tester
.
pumpWidget
(
Center
(
child:
Container
(
width:
200.0
,
child:
FittedBox
(
key:
outside
,
fit:
BoxFit
.
scaleDown
,
child:
Container
(
key:
inside
,
width:
100.0
,
height:
50.0
,
),
),
),
),
);
final
RenderBox
outsideBox
=
tester
.
firstRenderObject
(
find
.
byKey
(
outside
));
final
RenderBox
insideBox
=
tester
.
firstRenderObject
(
find
.
byKey
(
inside
));
expect
(
outsideBox
.
size
.
width
,
200.0
);
expect
(
outsideBox
.
size
.
height
,
50.0
);
Offset
outsidePoint
=
outsideBox
.
localToGlobal
(
Offset
.
zero
);
Offset
insidePoint
=
insideBox
.
localToGlobal
(
Offset
.
zero
);
expect
(
insidePoint
-
outsidePoint
,
equals
(
const
Offset
(
50.0
,
0.0
)));
// Scales down when child is bigger than constraints
await
tester
.
pumpWidget
(
Center
(
child:
Container
(
width:
200.0
,
child:
FittedBox
(
key:
outside
,
fit:
BoxFit
.
scaleDown
,
child:
Container
(
key:
inside
,
width:
400.0
,
height:
200.0
,
),
),
),
),
);
expect
(
outsideBox
.
size
.
width
,
200.0
);
expect
(
outsideBox
.
size
.
height
,
100.0
);
outsidePoint
=
outsideBox
.
localToGlobal
(
Offset
.
zero
);
insidePoint
=
insideBox
.
localToGlobal
(
Offset
.
zero
);
expect
(
insidePoint
-
outsidePoint
,
equals
(
Offset
.
zero
));
});
testWidgets
(
'Switching to and from BoxFit.scaleDown causes relayout'
,
(
WidgetTester
tester
)
async
{
final
Key
outside
=
UniqueKey
();
final
Widget
scaleDownWidget
=
Center
(
child:
Container
(
width:
200.0
,
child:
FittedBox
(
key:
outside
,
fit:
BoxFit
.
scaleDown
,
child:
Container
(
width:
100.0
,
height:
50.0
,
),
),
),
);
final
Widget
coverWidget
=
Center
(
child:
Container
(
width:
200.0
,
child:
FittedBox
(
key:
outside
,
child:
Container
(
width:
100.0
,
height:
50.0
,
),
),
),
);
await
tester
.
pumpWidget
(
scaleDownWidget
);
final
RenderBox
outsideBox
=
tester
.
firstRenderObject
(
find
.
byKey
(
outside
));
expect
(
outsideBox
.
size
.
height
,
50.0
);
await
tester
.
pumpWidget
(
coverWidget
);
expect
(
outsideBox
.
size
.
height
,
100.0
);
await
tester
.
pumpWidget
(
scaleDownWidget
);
expect
(
outsideBox
.
size
.
height
,
50.0
);
});
}
List
<
Type
>
getLayers
()
{
...
...
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