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
074ee4b2
Unverified
Commit
074ee4b2
authored
Apr 09, 2022
by
MrBirb
Committed by
GitHub
Apr 09, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow ClipRRect.borderRadius to support BorderRadiusDirectional (#101200)
parent
8ff3640c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
108 additions
and
8 deletions
+108
-8
proxy_box.dart
packages/flutter/lib/src/rendering/proxy_box.dart
+17
-5
basic.dart
packages/flutter/lib/src/widgets/basic.dart
+5
-3
clip_test.dart
packages/flutter/test/widgets/clip_test.dart
+86
-0
No files found.
packages/flutter/lib/src/rendering/proxy_box.dart
View file @
074ee4b2
...
...
@@ -1504,11 +1504,13 @@ class RenderClipRRect extends _RenderCustomClip<RRect> {
/// [Clip.none], no clipping will be applied.
RenderClipRRect
({
RenderBox
?
child
,
BorderRadius
borderRadius
=
BorderRadius
.
zero
,
BorderRadius
Geometry
borderRadius
=
BorderRadius
.
zero
,
CustomClipper
<
RRect
>?
clipper
,
Clip
clipBehavior
=
Clip
.
antiAlias
,
TextDirection
?
textDirection
,
})
:
assert
(
clipBehavior
!=
null
),
_borderRadius
=
borderRadius
,
_textDirection
=
textDirection
,
super
(
child:
child
,
clipper:
clipper
,
clipBehavior:
clipBehavior
)
{
assert
(
_borderRadius
!=
null
||
clipper
!=
null
);
}
...
...
@@ -1519,9 +1521,9 @@ class RenderClipRRect extends _RenderCustomClip<RRect> {
/// exceed width/height.
///
/// This value is ignored if [clipper] is non-null.
BorderRadius
get
borderRadius
=>
_borderRadius
;
BorderRadius
_borderRadius
;
set
borderRadius
(
BorderRadius
value
)
{
BorderRadius
Geometry
get
borderRadius
=>
_borderRadius
;
BorderRadius
Geometry
_borderRadius
;
set
borderRadius
(
BorderRadius
Geometry
value
)
{
assert
(
value
!=
null
);
if
(
_borderRadius
==
value
)
return
;
...
...
@@ -1529,8 +1531,18 @@ class RenderClipRRect extends _RenderCustomClip<RRect> {
_markNeedsClip
();
}
/// The text direction with which to resolve [borderRadius].
TextDirection
?
get
textDirection
=>
_textDirection
;
TextDirection
?
_textDirection
;
set
textDirection
(
TextDirection
?
value
)
{
if
(
_textDirection
==
value
)
return
;
_textDirection
=
value
;
_markNeedsClip
();
}
@override
RRect
get
_defaultClip
=>
_borderRadius
.
toRRect
(
Offset
.
zero
&
size
);
RRect
get
_defaultClip
=>
_borderRadius
.
resolve
(
textDirection
).
toRRect
(
Offset
.
zero
&
size
);
@override
bool
hitTest
(
BoxHitTestResult
result
,
{
required
Offset
position
})
{
...
...
packages/flutter/lib/src/widgets/basic.dart
View file @
074ee4b2
...
...
@@ -743,7 +743,7 @@ class ClipRRect extends SingleChildRenderObjectWidget {
/// exceed width/height.
///
/// This value is ignored if [clipper] is non-null.
final
BorderRadius
?
borderRadius
;
final
BorderRadius
Geometry
?
borderRadius
;
/// If non-null, determines which clip to use.
final
CustomClipper
<
RRect
>?
clipper
;
...
...
@@ -759,6 +759,7 @@ class ClipRRect extends SingleChildRenderObjectWidget {
borderRadius:
borderRadius
!,
clipper:
clipper
,
clipBehavior:
clipBehavior
,
textDirection:
Directionality
.
maybeOf
(
context
),
);
}
...
...
@@ -767,13 +768,14 @@ class ClipRRect extends SingleChildRenderObjectWidget {
renderObject
..
borderRadius
=
borderRadius
!
..
clipBehavior
=
clipBehavior
..
clipper
=
clipper
;
..
clipper
=
clipper
..
textDirection
=
Directionality
.
maybeOf
(
context
);
}
@override
void
debugFillProperties
(
DiagnosticPropertiesBuilder
properties
)
{
super
.
debugFillProperties
(
properties
);
properties
.
add
(
DiagnosticsProperty
<
BorderRadius
>(
'borderRadius'
,
borderRadius
,
showName:
false
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
BorderRadius
Geometry
>(
'borderRadius'
,
borderRadius
,
showName:
false
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
CustomClipper
<
RRect
>>(
'clipper'
,
clipper
,
defaultValue:
null
));
}
}
...
...
packages/flutter/test/widgets/clip_test.dart
View file @
074ee4b2
...
...
@@ -883,4 +883,90 @@ void main() {
..
restore
(),
);
});
testWidgets
(
'ClipRRect supports BorderRadiusDirectional'
,
(
WidgetTester
tester
)
async
{
const
Radius
startRadius
=
Radius
.
circular
(
15.0
);
const
Radius
endRadius
=
Radius
.
circular
(
30.0
);
Widget
buildClipRRect
(
TextDirection
textDirection
)
{
return
Directionality
(
textDirection:
textDirection
,
child:
const
ClipRRect
(
borderRadius:
BorderRadiusDirectional
.
horizontal
(
start:
startRadius
,
end:
endRadius
,
),
),
);
}
for
(
final
TextDirection
textDirection
in
TextDirection
.
values
)
{
await
tester
.
pumpWidget
(
buildClipRRect
(
textDirection
));
final
RenderClipRRect
renderClip
=
tester
.
allRenderObjects
.
whereType
<
RenderClipRRect
>().
first
;
final
bool
isRtl
=
textDirection
==
TextDirection
.
rtl
;
expect
(
renderClip
.
borderRadius
.
resolve
(
textDirection
).
topLeft
,
isRtl
?
endRadius
:
startRadius
);
expect
(
renderClip
.
borderRadius
.
resolve
(
textDirection
).
topRight
,
isRtl
?
startRadius
:
endRadius
);
expect
(
renderClip
.
borderRadius
.
resolve
(
textDirection
).
bottomLeft
,
isRtl
?
endRadius
:
startRadius
);
expect
(
renderClip
.
borderRadius
.
resolve
(
textDirection
).
bottomRight
,
isRtl
?
startRadius
:
endRadius
);
}
});
testWidgets
(
'ClipRRect is direction-aware'
,
(
WidgetTester
tester
)
async
{
const
Radius
startRadius
=
Radius
.
circular
(
15.0
);
const
Radius
endRadius
=
Radius
.
circular
(
30.0
);
TextDirection
textDirection
=
TextDirection
.
ltr
;
Widget
buildClipRRect
(
TextDirection
textDirection
)
{
return
Directionality
(
textDirection:
textDirection
,
child:
const
ClipRRect
(
borderRadius:
BorderRadiusDirectional
.
horizontal
(
start:
startRadius
,
end:
endRadius
,
),
),
);
}
Widget
buildStatefulClipRRect
()
{
return
StatefulBuilder
(
builder:
(
BuildContext
context
,
StateSetter
setState
)
{
return
Directionality
(
textDirection:
textDirection
,
child:
SizedBox
(
width:
100.0
,
height:
100.0
,
child:
ClipRRect
(
borderRadius:
const
BorderRadiusDirectional
.
horizontal
(
start:
startRadius
,
end:
endRadius
,
),
child:
GestureDetector
(
onTap:
()
{
setState
(()
{
textDirection
=
TextDirection
.
rtl
;
});
},
),
),
),
);
},
);
}
for
(
final
TextDirection
textDirection
in
TextDirection
.
values
)
{
await
tester
.
pumpWidget
(
buildClipRRect
(
textDirection
));
final
RenderClipRRect
renderClip
=
tester
.
allRenderObjects
.
whereType
<
RenderClipRRect
>().
first
;
final
bool
isRtl
=
textDirection
==
TextDirection
.
rtl
;
expect
(
renderClip
.
textDirection
,
isRtl
?
TextDirection
.
rtl
:
TextDirection
.
ltr
);
}
await
tester
.
pumpWidget
(
buildStatefulClipRRect
());
final
RenderClipRRect
renderClip
=
tester
.
allRenderObjects
.
whereType
<
RenderClipRRect
>().
first
;
expect
(
renderClip
.
textDirection
,
TextDirection
.
ltr
);
await
tester
.
tapAt
(
Offset
.
zero
);
await
tester
.
pump
();
expect
(
renderClip
.
textDirection
,
TextDirection
.
rtl
);
});
}
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