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
f777ead1
Unverified
Commit
f777ead1
authored
Aug 21, 2020
by
timekone
Committed by
GitHub
Aug 21, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clip image of BoxDecoration to circle when shape is BoxShape.circle (#63352)
parent
a1de2a22
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
3 deletions
+23
-3
box_decoration.dart
packages/flutter/lib/src/painting/box_decoration.dart
+9
-2
box_decoration_test.dart
packages/flutter/test/painting/box_decoration_test.dart
+14
-1
No files found.
packages/flutter/lib/src/painting/box_decoration.dart
View file @
f777ead1
...
...
@@ -219,7 +219,10 @@ class BoxDecoration extends Decoration {
Path
?
clipPath
;
switch
(
shape
)
{
case
BoxShape
.
circle
:
clipPath
=
Path
()..
addOval
(
rect
);
final
Offset
center
=
rect
.
center
;
final
double
radius
=
rect
.
shortestSide
/
2.0
;
final
Rect
square
=
Rect
.
fromCircle
(
center:
center
,
radius:
radius
);
clipPath
=
Path
()..
addOval
(
square
);
break
;
case
BoxShape
.
rectangle
:
if
(
borderRadius
!=
null
)
...
...
@@ -452,7 +455,11 @@ class _BoxDecorationPainter extends BoxPainter {
Path
?
clipPath
;
switch
(
_decoration
.
shape
)
{
case
BoxShape
.
circle
:
clipPath
=
Path
()..
addOval
(
rect
);
assert
(
_decoration
.
borderRadius
==
null
);
final
Offset
center
=
rect
.
center
;
final
double
radius
=
rect
.
shortestSide
/
2.0
;
final
Rect
square
=
Rect
.
fromCircle
(
center:
center
,
radius:
radius
);
clipPath
=
Path
()..
addOval
(
square
);
break
;
case
BoxShape
.
rectangle
:
if
(
_decoration
.
borderRadius
!=
null
)
...
...
packages/flutter/test/painting/box_decoration_test.dart
View file @
f777ead1
...
...
@@ -71,7 +71,7 @@ void main() {
);
});
test
(
'BoxDecoration.getClipPath'
,
()
{
test
(
'BoxDecoration.getClipPath
with borderRadius
'
,
()
{
const
double
radius
=
10
;
final
BoxDecoration
decoration
=
BoxDecoration
(
borderRadius:
BorderRadius
.
circular
(
radius
),
...
...
@@ -84,4 +84,17 @@ void main() {
);
expect
(
clipPath
,
isLookLikeExpectedPath
);
});
test
(
'BoxDecoration.getClipPath with shape BoxShape.circle'
,
()
{
const
BoxDecoration
decoration
=
BoxDecoration
(
shape:
BoxShape
.
circle
,
);
const
Rect
rect
=
Rect
.
fromLTWH
(
0.0
,
0.0
,
100.0
,
20.0
);
final
Path
clipPath
=
decoration
.
getClipPath
(
rect
,
TextDirection
.
ltr
);
final
Matcher
isLookLikeExpectedPath
=
isPathThat
(
includes:
const
<
Offset
>[
Offset
(
50.0
,
0.0
),
Offset
(
40.0
,
10.0
),
],
excludes:
const
<
Offset
>[
Offset
(
40.0
,
0.0
),
Offset
(
10.0
,
10.0
),
],
);
expect
(
clipPath
,
isLookLikeExpectedPath
);
});
}
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