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
ad2005c4
Unverified
Commit
ad2005c4
authored
Oct 06, 2022
by
Taha Tesser
Committed by
GitHub
Oct 06, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add `overlay` MaterialStateProperty property to `Slider` (#112922)
parent
7e8ddc06
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
592 additions
and
278 deletions
+592
-278
slider.dart
packages/flutter/lib/src/material/slider.dart
+34
-16
slider_test.dart
packages/flutter/test/material/slider_test.dart
+253
-261
slider_theme_test.dart
packages/flutter/test/material/slider_theme_test.dart
+305
-1
No files found.
packages/flutter/lib/src/material/slider.dart
View file @
ad2005c4
...
...
@@ -144,6 +144,7 @@ class Slider extends StatefulWidget {
this
.
inactiveColor
,
this
.
secondaryActiveColor
,
this
.
thumbColor
,
this
.
overlayColor
,
this
.
mouseCursor
,
this
.
semanticFormatterCallback
,
this
.
focusNode
,
...
...
@@ -187,6 +188,7 @@ class Slider extends StatefulWidget {
this
.
inactiveColor
,
this
.
secondaryActiveColor
,
this
.
thumbColor
,
this
.
overlayColor
,
this
.
semanticFormatterCallback
,
this
.
focusNode
,
this
.
autofocus
=
false
,
...
...
@@ -413,6 +415,15 @@ class Slider extends StatefulWidget {
/// (like the native default iOS slider).
final
Color
?
thumbColor
;
/// The highlight color that's typically used to indicate that
/// the slider is focused, hovered, or dragged.
///
/// If this property is null, [Slider] will use [activeColor] with
/// with an opacity of 0.12, If null, [SliderThemeData.overlayColor]
/// will be used, If this is also null, defaults to [ColorScheme.primary]
/// with an opacity of 0.12.
final
MaterialStateProperty
<
Color
?>?
overlayColor
;
/// {@template flutter.material.slider.mouseCursor}
/// The cursor for a mouse pointer when it enters or is hovering over the
/// widget.
...
...
@@ -521,18 +532,18 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
// Keyboard mapping for a focused slider.
static
const
Map
<
ShortcutActivator
,
Intent
>
_traditionalNavShortcutMap
=
<
ShortcutActivator
,
Intent
>{
SingleActivator
(
LogicalKeyboardKey
.
arrowUp
):
_AdjustSliderIntent
.
up
(),
SingleActivator
(
LogicalKeyboardKey
.
arrowDown
):
_AdjustSliderIntent
.
down
(),
SingleActivator
(
LogicalKeyboardKey
.
arrowLeft
):
_AdjustSliderIntent
.
left
(),
SingleActivator
(
LogicalKeyboardKey
.
arrowRight
):
_AdjustSliderIntent
.
right
(),
};
SingleActivator
(
LogicalKeyboardKey
.
arrowUp
):
_AdjustSliderIntent
.
up
(),
SingleActivator
(
LogicalKeyboardKey
.
arrowDown
):
_AdjustSliderIntent
.
down
(),
SingleActivator
(
LogicalKeyboardKey
.
arrowLeft
):
_AdjustSliderIntent
.
left
(),
SingleActivator
(
LogicalKeyboardKey
.
arrowRight
):
_AdjustSliderIntent
.
right
(),
};
// Keyboard mapping for a focused slider when using directional navigation.
// The vertical inputs are not handled to allow navigating out of the slider.
static
const
Map
<
ShortcutActivator
,
Intent
>
_directionalNavShortcutMap
=
<
ShortcutActivator
,
Intent
>{
SingleActivator
(
LogicalKeyboardKey
.
arrowLeft
):
_AdjustSliderIntent
.
left
(),
SingleActivator
(
LogicalKeyboardKey
.
arrowRight
):
_AdjustSliderIntent
.
right
(),
};
SingleActivator
(
LogicalKeyboardKey
.
arrowLeft
):
_AdjustSliderIntent
.
left
(),
SingleActivator
(
LogicalKeyboardKey
.
arrowRight
):
_AdjustSliderIntent
.
right
(),
};
// Action mapping for a focused slider.
late
Map
<
Type
,
Action
<
Intent
>>
_actionMap
;
...
...
@@ -734,6 +745,13 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
const
SliderComponentShape
defaultValueIndicatorShape
=
RectangularSliderValueIndicatorShape
();
const
ShowValueIndicator
defaultShowValueIndicator
=
ShowValueIndicator
.
onlyForDiscrete
;
final
Set
<
MaterialState
>
states
=
<
MaterialState
>{
if
(!
_enabled
)
MaterialState
.
disabled
,
if
(
_hovering
)
MaterialState
.
hovered
,
if
(
_focused
)
MaterialState
.
focused
,
if
(
_dragging
)
MaterialState
.
dragged
,
};
// The value indicator's color is not the same as the thumb and active track
// (which can be defined by activeColor) if the
// RectangularSliderValueIndicatorShape is used. In all other cases, the
...
...
@@ -746,6 +764,13 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
valueIndicatorColor
=
widget
.
activeColor
??
sliderTheme
.
valueIndicatorColor
??
theme
.
colorScheme
.
primary
;
}
Color
?
effectiveOverlayColor
()
{
return
widget
.
overlayColor
?.
resolve
(
states
)
??
widget
.
activeColor
?.
withOpacity
(
0.12
)
??
MaterialStateProperty
.
resolveAs
<
Color
?>(
sliderTheme
.
overlayColor
,
states
)
??
theme
.
colorScheme
.
primary
.
withOpacity
(
0.12
);
}
sliderTheme
=
sliderTheme
.
copyWith
(
trackHeight:
sliderTheme
.
trackHeight
??
defaultTrackHeight
,
activeTrackColor:
widget
.
activeColor
??
sliderTheme
.
activeTrackColor
??
theme
.
colorScheme
.
primary
,
...
...
@@ -760,7 +785,7 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
disabledInactiveTickMarkColor:
sliderTheme
.
disabledInactiveTickMarkColor
??
theme
.
colorScheme
.
onSurface
.
withOpacity
(
0.12
),
thumbColor:
widget
.
thumbColor
??
widget
.
activeColor
??
sliderTheme
.
thumbColor
??
theme
.
colorScheme
.
primary
,
disabledThumbColor:
sliderTheme
.
disabledThumbColor
??
Color
.
alphaBlend
(
theme
.
colorScheme
.
onSurface
.
withOpacity
(.
38
),
theme
.
colorScheme
.
surface
),
overlayColor:
widget
.
activeColor
?.
withOpacity
(
0.12
)
??
sliderTheme
.
overlayColor
??
theme
.
colorScheme
.
primary
.
withOpacity
(
0.12
),
overlayColor:
effectiveOverlayColor
(
),
valueIndicatorColor:
valueIndicatorColor
,
trackShape:
sliderTheme
.
trackShape
??
defaultTrackShape
,
tickMarkShape:
sliderTheme
.
tickMarkShape
??
defaultTickMarkShape
,
...
...
@@ -772,12 +797,6 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
color:
theme
.
colorScheme
.
onPrimary
,
),
);
final
Set
<
MaterialState
>
states
=
<
MaterialState
>{
if
(!
_enabled
)
MaterialState
.
disabled
,
if
(
_hovering
)
MaterialState
.
hovered
,
if
(
_focused
)
MaterialState
.
focused
,
if
(
_dragging
)
MaterialState
.
dragged
,
};
final
MouseCursor
effectiveMouseCursor
=
MaterialStateProperty
.
resolveAs
<
MouseCursor
?>(
widget
.
mouseCursor
,
states
)
??
sliderTheme
.
mouseCursor
?.
resolve
(
states
)
??
MaterialStateMouseCursor
.
clickable
.
resolve
(
states
);
...
...
@@ -892,7 +911,6 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
}
}
class
_SliderRenderObjectWidget
extends
LeafRenderObjectWidget
{
const
_SliderRenderObjectWidget
({
super
.
key
,
...
...
packages/flutter/test/material/slider_test.dart
View file @
ad2005c4
This diff is collapsed.
Click to expand it.
packages/flutter/test/material/slider_theme_test.dart
View file @
ad2005c4
This diff is collapsed.
Click to expand it.
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