New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce new Slider
shapes
#147783
base: master
Are you sure you want to change the base?
Introduce new Slider
shapes
#147783
Conversation
3fc68e1
to
dc1178f
Compare
dc1178f
to
b1710e7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work, just a general comment, I think we should make it easier to use the new shapes, since they will become the new default. Rather than manually specifying them, developers could flip a flag on ThemeData
.
Size? get barThumbSize => const Size(4.0, 44.0); | ||
|
||
@override | ||
double? get trackGapSize => 6.0; | ||
} | ||
|
||
// TODO(quncheng): Update M3 defaults to match the latest specs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can remove this TODO?
Interesting idea, tho this is only specific to |
Perhaps |
Added |
b1710e7
to
bb9d19d
Compare
final SliderThemeData defaultsM3 = _SliderDefaultsM3( | ||
context: context, | ||
sliderTheme: sliderTheme.copyWith( | ||
trackShape: trackShape, | ||
thumbShape: thumbShape, | ||
valueIndicatorShape: valueIndicatorShape, | ||
), | ||
); | ||
final SliderThemeData defaultsM2 = _SliderDefaultsM2( | ||
context: context, | ||
sliderTheme: sliderTheme.copyWith( | ||
trackShape: trackShape, | ||
thumbShape: thumbShape, | ||
valueIndicatorShape: valueIndicatorShape, | ||
), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's avoid creating both defaults every time since we know we'll only use one
@@ -3536,3 +3601,413 @@ class _DropSliderValueIndicatorPathPainter { | |||
canvas.restore(); | |||
} | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for each of these new shapes, please provide context about when they were introduced, and mention the new flag
/// A temporary flag that can be used to opt-in to the new 2024 slider shapes. | ||
/// | ||
/// This flag is _false_ by default. If true, then the [Slider]'s will use the | ||
/// new 2024 slider shapes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explicit that this flag will be defaulted to true in the future, and then deprecated
/// * trackShape: [RoundedRectSliderTrackShape] is replaced with [ExpressiveRoundedRectSliderTrackShape]. | ||
/// * thumbShape: [RoundSliderThumbShape] is replaced with [BarSliderThumbShape]. | ||
/// * valueIndicatorShape: [PaddleRangeSliderValueIndicatorShape] is replaced with [RoundedRectSliderValueIndicatorShape]. | ||
final bool? use2024SliderShapes; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please link to code sample
/// This flag effects the following shapes if [ThemeData.useMaterial3] is set to false: | ||
/// * trackShape: [RoundedRectSliderTrackShape] is replaced with [ExpressiveRoundedRectSliderTrackShape]. | ||
/// * thumbShape: [RoundSliderThumbShape] is replaced with [BarSliderThumbShape]. | ||
/// * valueIndicatorShape: [PaddleRangeSliderValueIndicatorShape] is replaced with [RoundedRectSliderValueIndicatorShape]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is overkill, in the sense that useMaterial3
and this flag both being true should not be a valid combination that we support
/// * [Slider], which includes an overlay defined by this shape. | ||
/// * [SliderTheme], which can be used to configure the overlay shape of all | ||
/// sliders in a widget subtree. | ||
class ExpressiveRoundedRectSliderTrackShape extends SliderTrackShape with BaseSliderTrackShape { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this the term used in guidelines?
tickMarkShape: sliderTheme.tickMarkShape ?? defaultTickMarkShape, | ||
thumbShape: sliderTheme.thumbShape ?? defaultThumbShape, | ||
overlayShape: sliderTheme.overlayShape ?? defaultOverlayShape, | ||
trackShape: trackShape, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for consistency with other properties, please keep the ?? defaults.X
here
overlayShape: sliderTheme.overlayShape ?? defaultOverlayShape, | ||
trackShape: trackShape, | ||
tickMarkShape: sliderTheme.tickMarkShape ?? defaults.tickMarkShape, | ||
thumbShape: thumbShape, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for consistency with other properties, please keep the ?? defaults.X
here
final bool newShapes = sliderTheme.use2024SliderShapes ?? false; | ||
final SliderTrackShape trackShape = sliderTheme.trackShape ?? | ||
(newShapes ? const ExpressiveRoundedRectSliderTrackShape() as SliderTrackShape : const RoundedRectSliderTrackShape()); | ||
final SliderComponentShape thumbShape = sliderTheme.thumbShape ?? | ||
(newShapes ? const BarSliderThumbShape() : const RoundSliderThumbShape()); | ||
final SliderComponentShape valueIndicatorShape = sliderTheme.valueIndicatorShape ?? | ||
(newShapes | ||
? const RoundedRectSliderValueIndicatorShape() | ||
: theme.useMaterial3 ? const DropSliderValueIndicatorShape() : const RectangularSliderValueIndicatorShape()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this code be in the defaults and computed once, rather than every build, here?
SliderComponentShape? get valueIndicatorShape => const DropSliderValueIndicatorShape(); | ||
Color? get valueIndicatorColor { | ||
if (_sliderTheme.valueIndicatorShape is RoundedRectSliderValueIndicatorShape) { | ||
return _colors.inverseSurface; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a TODO to use tokens
@guidezpl |
fixes Update
Slider
for Material 3 redesignDescription
This PR adds new
Slider
shapesBarSliderThumbShape
,ExpressiveRoundedRectSliderTrackShape
, andRoundedRectSliderValueIndicatorShape
.When these shapes are applied in the
SliderTheme
, the sliders uses the new Material Design Slider elements.Preview
New shapes when dragged
Record_2024-05-03-17-12-14.mp4
Record_2024-05-03-17-12-28.mp4
Stop indicator in the
RoundedRectSliderValueIndicatorShape
track shapestop_indicator.mov
trackGapSize
set to0
trackGapSize
&barThumbSize
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.