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
c7353bc4
Unverified
Commit
c7353bc4
authored
Sep 02, 2020
by
xubaolin
Committed by
GitHub
Sep 02, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Slider and RangeSlider can be painted in a narrower constraint like other Material Wi… (#64627)
parent
484f3f26
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
134 additions
and
20 deletions
+134
-20
slider_theme.dart
packages/flutter/lib/src/material/slider_theme.dart
+15
-18
range_slider_test.dart
packages/flutter/test/material/range_slider_test.dart
+82
-0
slider_test.dart
packages/flutter/test/material/slider_test.dart
+37
-2
No files found.
packages/flutter/lib/src/material/slider_theme.dart
View file @
c7353bc4
...
...
@@ -1453,13 +1453,13 @@ abstract class BaseSliderTrackShape {
final
double
trackHeight
=
sliderTheme
.
trackHeight
;
assert
(
overlayWidth
>=
0
);
assert
(
trackHeight
>=
0
);
assert
(
parentBox
.
size
.
width
>=
overlayWidth
);
assert
(
parentBox
.
size
.
height
>=
trackHeight
);
final
double
trackLeft
=
offset
.
dx
+
overlayWidth
/
2
;
final
double
trackTop
=
offset
.
dy
+
(
parentBox
.
size
.
height
-
trackHeight
)
/
2
;
final
double
trackWidth
=
parentBox
.
size
.
width
-
math
.
max
(
thumbWidth
,
overlayWidth
);
return
Rect
.
fromLTWH
(
trackLeft
,
trackTop
,
trackWidth
,
trackHeight
);
final
double
trackRight
=
trackLeft
+
parentBox
.
size
.
width
-
math
.
max
(
thumbWidth
,
overlayWidth
);
final
double
trackBottom
=
trackTop
+
trackHeight
;
// If the parentBox'size less than slider's size the trackRight will be less than trackLeft, so switch them.
return
Rect
.
fromLTRB
(
math
.
min
(
trackLeft
,
trackRight
),
trackTop
,
math
.
max
(
trackLeft
,
trackRight
),
trackBottom
);
}
}
...
...
@@ -1735,13 +1735,13 @@ class RectangularRangeSliderTrackShape extends RangeSliderTrackShape {
final
double
trackHeight
=
sliderTheme
.
trackHeight
;
assert
(
overlayWidth
>=
0
);
assert
(
trackHeight
>=
0
);
assert
(
parentBox
.
size
.
width
>=
overlayWidth
);
assert
(
parentBox
.
size
.
height
>=
trackHeight
);
final
double
trackLeft
=
offset
.
dx
+
overlayWidth
/
2
;
final
double
trackTop
=
offset
.
dy
+
(
parentBox
.
size
.
height
-
trackHeight
)
/
2
;
final
double
trackWidth
=
parentBox
.
size
.
width
-
overlayWidth
;
return
Rect
.
fromLTWH
(
trackLeft
,
trackTop
,
trackWidth
,
trackHeight
);
final
double
trackRight
=
trackLeft
+
parentBox
.
size
.
width
-
overlayWidth
;
final
double
trackBottom
=
trackTop
+
trackHeight
;
// If the parentBox'size less than slider's size the trackRight will be less than trackLeft, so switch them.
return
Rect
.
fromLTRB
(
math
.
min
(
trackLeft
,
trackRight
),
trackTop
,
math
.
max
(
trackLeft
,
trackRight
),
trackBottom
);
}
@override
...
...
@@ -1791,8 +1791,6 @@ class RectangularRangeSliderTrackShape extends RangeSliderTrackShape {
rightThumbOffset
=
startThumbCenter
;
break
;
}
final
Size
thumbSize
=
sliderTheme
.
rangeThumbShape
.
getPreferredSize
(
isEnabled
,
isDiscrete
);
final
double
thumbRadius
=
thumbSize
.
width
/
2
;
final
Rect
trackRect
=
getPreferredRect
(
parentBox:
parentBox
,
...
...
@@ -1801,13 +1799,13 @@ class RectangularRangeSliderTrackShape extends RangeSliderTrackShape {
isEnabled:
isEnabled
,
isDiscrete:
isDiscrete
,
);
final
Rect
leftTrackSegment
=
Rect
.
fromLTRB
(
trackRect
.
left
,
trackRect
.
top
,
leftThumbOffset
.
dx
-
thumbRadius
,
trackRect
.
bottom
);
final
Rect
leftTrackSegment
=
Rect
.
fromLTRB
(
trackRect
.
left
,
trackRect
.
top
,
leftThumbOffset
.
dx
,
trackRect
.
bottom
);
if
(!
leftTrackSegment
.
isEmpty
)
context
.
canvas
.
drawRect
(
leftTrackSegment
,
inactivePaint
);
final
Rect
middleTrackSegment
=
Rect
.
fromLTRB
(
leftThumbOffset
.
dx
+
thumbRadius
,
trackRect
.
top
,
rightThumbOffset
.
dx
-
thumbRadius
,
trackRect
.
bottom
);
final
Rect
middleTrackSegment
=
Rect
.
fromLTRB
(
leftThumbOffset
.
dx
,
trackRect
.
top
,
rightThumbOffset
.
dx
,
trackRect
.
bottom
);
if
(!
middleTrackSegment
.
isEmpty
)
context
.
canvas
.
drawRect
(
middleTrackSegment
,
activePaint
);
final
Rect
rightTrackSegment
=
Rect
.
fromLTRB
(
rightThumbOffset
.
dx
+
thumbRadius
,
trackRect
.
top
,
trackRect
.
right
,
trackRect
.
bottom
);
final
Rect
rightTrackSegment
=
Rect
.
fromLTRB
(
rightThumbOffset
.
dx
,
trackRect
.
top
,
trackRect
.
right
,
trackRect
.
bottom
);
if
(!
rightTrackSegment
.
isEmpty
)
context
.
canvas
.
drawRect
(
rightTrackSegment
,
inactivePaint
);
}
...
...
@@ -1865,13 +1863,13 @@ class RoundedRectRangeSliderTrackShape extends RangeSliderTrackShape {
final
double
trackHeight
=
sliderTheme
.
trackHeight
;
assert
(
overlayWidth
>=
0
);
assert
(
trackHeight
>=
0
);
assert
(
parentBox
.
size
.
width
>=
overlayWidth
);
assert
(
parentBox
.
size
.
height
>=
trackHeight
);
final
double
trackLeft
=
offset
.
dx
+
overlayWidth
/
2
;
final
double
trackTop
=
offset
.
dy
+
(
parentBox
.
size
.
height
-
trackHeight
)
/
2
;
final
double
trackWidth
=
parentBox
.
size
.
width
-
overlayWidth
;
return
Rect
.
fromLTWH
(
trackLeft
,
trackTop
,
trackWidth
,
trackHeight
);
final
double
trackRight
=
trackLeft
+
parentBox
.
size
.
width
-
overlayWidth
;
final
double
trackBottom
=
trackTop
+
trackHeight
;
// If the parentBox'size less than slider's size the trackRight will be less than trackLeft, so switch them.
return
Rect
.
fromLTRB
(
math
.
min
(
trackLeft
,
trackRight
),
trackTop
,
math
.
max
(
trackLeft
,
trackRight
),
trackBottom
);
}
@override
...
...
@@ -2311,7 +2309,6 @@ class RoundSliderThumbShape extends SliderComponentShape {
assert
(
sliderTheme
!=
null
);
assert
(
sliderTheme
.
disabledThumbColor
!=
null
);
assert
(
sliderTheme
.
thumbColor
!=
null
);
assert
(!
sizeWithOverflow
.
isEmpty
);
final
Canvas
canvas
=
context
.
canvas
;
final
Tween
<
double
>
radiusTween
=
Tween
<
double
>(
...
...
packages/flutter/test/material/range_slider_test.dart
View file @
c7353bc4
...
...
@@ -1833,4 +1833,86 @@ void main() {
'inactiveColor: MaterialColor(primary value: Color(0xff9e9e9e))'
,
]);
});
testWidgets
(
'Range Slider can be painted in a narrower constraint when track shape is RoundedRectRange'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Material
(
child:
Center
(
child:
SizedBox
(
height:
10.0
,
width:
0.0
,
child:
RangeSlider
(
values:
const
RangeValues
(
0.25
,
0.5
),
onChanged:
null
,
),
),
),
),
),
),
);
// _RenderRangeSlider is the last render object in the tree.
final
RenderObject
renderObject
=
tester
.
allRenderObjects
.
last
;
expect
(
renderObject
,
paints
// left inactive track RRect
..
rrect
(
rrect:
RRect
.
fromLTRBAndCorners
(-
24.0
,
3.0
,
-
12.0
,
7.0
,
topLeft:
const
Radius
.
circular
(
2.0
),
bottomLeft:
const
Radius
.
circular
(
2.0
)))
// active track RRect
..
rect
(
rect:
const
Rect
.
fromLTRB
(-
12.0
,
2.0
,
0.0
,
8.0
))
// right inactive track RRect
..
rrect
(
rrect:
RRect
.
fromLTRBAndCorners
(
0.0
,
3.0
,
24.0
,
7.0
,
topRight:
const
Radius
.
circular
(
2.0
),
bottomRight:
const
Radius
.
circular
(
2.0
)))
// thumbs
..
circle
(
x:
-
12.0
,
y:
5.0
,
radius:
10.0
,)
..
circle
(
x:
0.0
,
y:
5.0
,
radius:
10.0
,)
);
});
testWidgets
(
'Range Slider can be painted in a narrower constraint when track shape is Rectangular'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
ThemeData
(
sliderTheme:
const
SliderThemeData
(
rangeTrackShape:
RectangularRangeSliderTrackShape
(),
)
),
home:
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Material
(
child:
Center
(
child:
SizedBox
(
height:
10.0
,
width:
0.0
,
child:
RangeSlider
(
values:
const
RangeValues
(
0.25
,
0.5
),
onChanged:
null
,
),
),
),
),
),
),
);
// _RenderRangeSlider is the last render object in the tree.
final
RenderObject
renderObject
=
tester
.
allRenderObjects
.
last
;
//There should no gap between the inactive track and active track.
expect
(
renderObject
,
paints
// left inactive track RRect
..
rect
(
rect:
const
Rect
.
fromLTRB
(-
24.0
,
3.0
,
-
12.0
,
7.0
))
// active track RRect
..
rect
(
rect:
const
Rect
.
fromLTRB
(-
12.0
,
3.0
,
0.0
,
7.0
))
// right inactive track RRect
..
rect
(
rect:
const
Rect
.
fromLTRB
(
0.0
,
3.0
,
24.0
,
7.0
))
// thumbs
..
circle
(
x:
-
12.0
,
y:
5.0
,
radius:
10.0
,)
..
circle
(
x:
0.0
,
y:
5.0
,
radius:
10.0
,)
);
});
}
packages/flutter/test/material/slider_test.dart
View file @
c7353bc4
...
...
@@ -2360,13 +2360,13 @@ void main() {
]);
});
testWidgets
(
'Slider
paint correctly when the track
shape is rectangular'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'Slider
track paints correctly when the
shape is rectangular'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
ThemeData
(
sliderTheme:
const
SliderThemeData
(
trackShape:
RectangularSliderTrackShape
(),
)
)
,
),
home:
Directionality
(
textDirection:
TextDirection
.
ltr
,
...
...
@@ -2396,4 +2396,39 @@ void main() {
..
rect
(
rect:
const
Rect
.
fromLTRB
(
400.0
,
298.0
,
776.0
,
302.0
))
// inactive track Rect.
);
});
testWidgets
(
'Slider can be painted in a narrower constraint'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
const
MaterialApp
(
home:
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Material
(
child:
Center
(
child:
SizedBox
(
height:
10.0
,
width:
10.0
,
child:
Slider
(
value:
0.5
,
onChanged:
null
,
),
),
),
),
),
),
);
// _RenderSlider is the last render object in the tree.
final
RenderObject
renderObject
=
tester
.
allRenderObjects
.
last
;
expect
(
renderObject
,
paints
// active track RRect
..
rrect
(
rrect:
RRect
.
fromLTRBAndCorners
(-
14.0
,
2.0
,
5.0
,
8.0
,
topLeft:
const
Radius
.
circular
(
3.0
),
bottomLeft:
const
Radius
.
circular
(
3.0
)))
// inactive track RRect
..
rrect
(
rrect:
RRect
.
fromLTRBAndCorners
(
5.0
,
3.0
,
24.0
,
7.0
,
topRight:
const
Radius
.
circular
(
2.0
),
bottomRight:
const
Radius
.
circular
(
2.0
)))
// thumb
..
circle
(
x:
5.0
,
y:
5.0
,
radius:
10.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