From 0549ab239009e6f76f95881364e935cd345a4da7 Mon Sep 17 00:00:00 2001 From: Jose Alba Date: Thu, 30 Apr 2020 18:19:01 -0400 Subject: [PATCH] Removed useV2 Slider flag (#55857) --- .../lib/src/material/range_slider.dart | 52 +- packages/flutter/lib/src/material/slider.dart | 54 +- .../lib/src/material/slider_theme.dart | 277 +++------ .../test/material/inherited_theme_test.dart | 6 +- .../test/material/range_slider_test.dart | 581 +---------------- .../flutter/test/material/slider_test.dart | 586 ++---------------- .../test/material/slider_theme_test.dart | 329 ++++------ 7 files changed, 292 insertions(+), 1593 deletions(-) diff --git a/packages/flutter/lib/src/material/range_slider.dart b/packages/flutter/lib/src/material/range_slider.dart index 4d838fed7b..d988bd9a76 100644 --- a/packages/flutter/lib/src/material/range_slider.dart +++ b/packages/flutter/lib/src/material/range_slider.dart @@ -132,12 +132,6 @@ class RangeSlider extends StatefulWidget { this.activeColor, this.inactiveColor, this.semanticFormatterCallback, - @Deprecated( - 'This flag has changed to true by default and no longer needed. ' - 'This feature was deprecated after v1.18.0.' - ) - // ignore: deprecated_member_use_from_same_package - this.useV2Slider = true, }) : assert(values != null), assert(min != null), assert(max != null), @@ -146,8 +140,6 @@ class RangeSlider extends StatefulWidget { assert(values.start >= min && values.start <= max), assert(values.end >= min && values.end <= max), assert(divisions == null || divisions > 0), - // ignore: deprecated_member_use_from_same_package - assert(useV2Slider != null), super(key: key); /// The currently selected values for this range slider. @@ -346,23 +338,6 @@ class RangeSlider extends StatefulWidget { /// {@end-tool} final RangeSemanticFormatterCallback semanticFormatterCallback; - /// Whether to use the updated Material spec version of the [RangeSlider]. - /// * The v2 [RangeSlider] has an updated value indicator that matches the latest specs. - /// * The value indicator is painted on the Overlay. - /// * The active track is bigger than the inactive track. - /// * The thumb that is activated has elevation. - /// * Updated value indicators in case they overlap with each other. - /// * - /// - /// This is a temporary flag for migrating the slider from v1 to v2. Currently - /// this defaults to false, because the changes may break existing tests. This - /// value will be defaulted to true in the future. - @Deprecated( - 'This flag has changed to true by default and no longer needed. ' - 'This feature was deprecated after v1.18.0.' - ) - final bool useV2Slider; - // Touch width for the tap boundary of the slider thumbs. static const double _minTouchTargetWidth = kMinInteractiveDimension; @@ -384,8 +359,6 @@ class RangeSlider extends StatefulWidget { properties.add(StringProperty('labelEnd', labels?.end)); properties.add(ColorProperty('activeColor', activeColor)); properties.add(ColorProperty('inactiveColor', inactiveColor)); - // ignore: deprecated_member_use_from_same_package - properties.add(FlagProperty('useV2Slider', value: useV2Slider, ifFalse: 'useV1Slider')); properties.add(ObjectFlagProperty>.has('semanticFormatterCallback', semanticFormatterCallback)); } } @@ -573,14 +546,12 @@ class _RangeSliderState extends State with TickerProviderStateMixin // the default shapes and text styles are aligned to the Material // Guidelines. - // ignore: deprecated_member_use_from_same_package - final bool useV2Slider = widget.useV2Slider; - final double _defaultTrackHeight = useV2Slider ? 4 : 2; - final RangeSliderTrackShape _defaultTrackShape = RoundedRectRangeSliderTrackShape(useV2Slider: useV2Slider); - final RangeSliderTickMarkShape _defaultTickMarkShape = RoundRangeSliderTickMarkShape(useV2Slider: useV2Slider); + const double _defaultTrackHeight = 4; + const RangeSliderTrackShape _defaultTrackShape = RoundedRectRangeSliderTrackShape(); + const RangeSliderTickMarkShape _defaultTickMarkShape = RoundRangeSliderTickMarkShape(); const SliderComponentShape _defaultOverlayShape = RoundSliderOverlayShape(); - final RangeSliderThumbShape _defaultThumbShape = RoundRangeSliderThumbShape(useV2Slider: useV2Slider); - final RangeSliderValueIndicatorShape _defaultValueIndicatorShape = useV2Slider ? const RectangularRangeSliderValueIndicatorShape() : const PaddleRangeSliderValueIndicatorShape(); + const RangeSliderThumbShape _defaultThumbShape = RoundRangeSliderThumbShape(); + const RangeSliderValueIndicatorShape _defaultValueIndicatorShape = RectangularRangeSliderValueIndicatorShape(); const ShowValueIndicator _defaultShowValueIndicator = ShowValueIndicator.onlyForDiscrete; const double _defaultMinThumbSeparation = 8; @@ -643,8 +614,6 @@ class _RangeSliderState extends State with TickerProviderStateMixin onChangeEnd: widget.onChangeEnd != null ? _handleDragEnd : null, state: this, semanticFormatterCallback: widget.semanticFormatterCallback, - // ignore: deprecated_member_use_from_same_package - useV2Slider: widget.useV2Slider, ), ); } @@ -684,7 +653,6 @@ class _RangeSliderRenderObjectWidget extends LeafRenderObjectWidget { this.onChangeEnd, this.state, this.semanticFormatterCallback, - this.useV2Slider, }) : super(key: key); final RangeValues values; @@ -698,7 +666,6 @@ class _RangeSliderRenderObjectWidget extends LeafRenderObjectWidget { final ValueChanged onChangeEnd; final RangeSemanticFormatterCallback semanticFormatterCallback; final _RangeSliderState state; - final bool useV2Slider; @override _RenderRangeSlider createRenderObject(BuildContext context) { @@ -717,7 +684,6 @@ class _RangeSliderRenderObjectWidget extends LeafRenderObjectWidget { textDirection: Directionality.of(context), semanticFormatterCallback: semanticFormatterCallback, platform: Theme.of(context).platform, - useV2Slider: useV2Slider, ); } @@ -756,7 +722,6 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix this.onChangeEnd, @required _RangeSliderState state, @required TextDirection textDirection, - bool useV2Slider, }) : assert(values != null), assert(values.start >= 0.0 && values.start <= 1.0), assert(values.end >= 0.0 && values.end <= 1.0), @@ -773,8 +738,7 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix _screenSize = screenSize, _onChanged = onChanged, _state = state, - _textDirection = textDirection, - _useV2Slider = useV2Slider { + _textDirection = textDirection { _updateLabelPainters(); final GestureArenaTeam team = GestureArenaTeam(); _drag = HorizontalDragGestureRecognizer() @@ -1022,8 +986,6 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix return 0.05; } - final bool _useV2Slider; - void _updateLabelPainters() { _updateLabelPainter(Thumb.start); _updateLabelPainter(Thumb.end); @@ -1351,7 +1313,7 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix isEnabled: isEnabled, sliderTheme: _sliderTheme, ).width; - final double padding = _useV2Slider ? trackRect.height : tickMarkWidth; + final double padding = trackRect.height; final double adjustedTrackWidth = trackRect.width - padding; // If the tick marks would be too dense, don't bother painting them. if (adjustedTrackWidth / divisions >= 3.0 * tickMarkWidth) { diff --git a/packages/flutter/lib/src/material/slider.dart b/packages/flutter/lib/src/material/slider.dart index 830ca4ea00..e780dc54c9 100644 --- a/packages/flutter/lib/src/material/slider.dart +++ b/packages/flutter/lib/src/material/slider.dart @@ -133,12 +133,6 @@ class Slider extends StatefulWidget { this.semanticFormatterCallback, this.focusNode, this.autofocus = false, - @Deprecated( - 'This flag has changed to true by default and no longer needed. ' - 'This feature was deprecated after v1.18.0.' - ) - // ignore: deprecated_member_use_from_same_package - this.useV2Slider = true, }) : _sliderType = _SliderType.material, assert(value != null), assert(min != null), @@ -146,8 +140,6 @@ class Slider extends StatefulWidget { assert(min <= max), assert(value >= min && value <= max), assert(divisions == null || divisions > 0), - // ignore: deprecated_member_use_from_same_package - assert(useV2Slider != null), super(key: key); /// Creates a [CupertinoSlider] if the target platform is iOS, creates a @@ -172,12 +164,6 @@ class Slider extends StatefulWidget { this.semanticFormatterCallback, this.focusNode, this.autofocus = false, - @Deprecated( - 'This flag has changed to true by default and no longer needed. ' - 'This feature was deprecated after v1.18.0.' - ) - // ignore: deprecated_member_use_from_same_package - this.useV2Slider = true, }) : _sliderType = _SliderType.adaptive, assert(value != null), assert(min != null), @@ -185,8 +171,6 @@ class Slider extends StatefulWidget { assert(min <= max), assert(value >= min && value <= max), assert(divisions == null || divisions > 0), - // ignore: deprecated_member_use_from_same_package - assert(useV2Slider != null), super(key: key); /// The currently selected value for this slider. @@ -407,20 +391,6 @@ class Slider extends StatefulWidget { /// {@macro flutter.widgets.Focus.autofocus} final bool autofocus; - /// Whether to use the updated Material spec version of the [Slider]. - /// - /// * The v2 Slider has an updated value indicator that matches the latest specs. - /// * The value indicator is painted on the Overlay. - /// * The active track is bigger than the inactive track. - /// * The thumb that is activated has elevation. - /// * Updated value indicators in case they overlap with each other. - /// * - /// - /// This is a temporary flag for migrating the slider from v1 to v2. To avoid - /// unexpected breaking changes, this value should be set to true. Setting - /// this to false is considered deprecated. - final bool useV2Slider; - final _SliderType _sliderType ; @override @@ -442,7 +412,6 @@ class Slider extends StatefulWidget { properties.add(ObjectFlagProperty>.has('semanticFormatterCallback', semanticFormatterCallback)); properties.add(ObjectFlagProperty.has('focusNode', focusNode)); properties.add(FlagProperty('autofocus', value: autofocus, ifTrue: 'autofocus')); - properties.add(FlagProperty('useV2Slider', value: useV2Slider, ifFalse: 'useV1Slider')); } } @@ -636,13 +605,12 @@ class _SliderState extends State with TickerProviderStateMixin { // the default shapes and text styles are aligned to the Material // Guidelines. - final bool useV2Slider = widget.useV2Slider; - final double _defaultTrackHeight = useV2Slider ? 4 : 2; - final SliderTrackShape _defaultTrackShape = RoundedRectSliderTrackShape(useV2Slider: useV2Slider); - final SliderTickMarkShape _defaultTickMarkShape = RoundSliderTickMarkShape(useV2Slider: useV2Slider); + const double _defaultTrackHeight = 4; + const SliderTrackShape _defaultTrackShape = RoundedRectSliderTrackShape(); + const SliderTickMarkShape _defaultTickMarkShape = RoundSliderTickMarkShape(); const SliderComponentShape _defaultOverlayShape = RoundSliderOverlayShape(); - final SliderComponentShape _defaultThumbShape = RoundSliderThumbShape(useV2Slider: useV2Slider); - final SliderComponentShape _defaultValueIndicatorShape = useV2Slider ? const RectangularSliderValueIndicatorShape() : const PaddleSliderValueIndicatorShape(); + const SliderComponentShape _defaultThumbShape = RoundSliderThumbShape(); + const SliderComponentShape _defaultValueIndicatorShape = RectangularSliderValueIndicatorShape(); const ShowValueIndicator _defaultShowValueIndicator = ShowValueIndicator.onlyForDiscrete; // The value indicator's color is not the same as the thumb and active track @@ -712,7 +680,6 @@ class _SliderState extends State with TickerProviderStateMixin { semanticFormatterCallback: widget.semanticFormatterCallback, hasFocus: _focused, hovering: _hovering, - useV2Slider: widget.useV2Slider, ), ), ); @@ -774,7 +741,6 @@ class _SliderRenderObjectWidget extends LeafRenderObjectWidget { this.semanticFormatterCallback, this.hasFocus, this.hovering, - this.useV2Slider, }) : super(key: key); final double value; @@ -790,7 +756,6 @@ class _SliderRenderObjectWidget extends LeafRenderObjectWidget { final _SliderState state; final bool hasFocus; final bool hovering; - final bool useV2Slider; @override _RenderSlider createRenderObject(BuildContext context) { @@ -810,7 +775,6 @@ class _SliderRenderObjectWidget extends LeafRenderObjectWidget { platform: Theme.of(context).platform, hasFocus: hasFocus, hovering: hovering, - useV2Slider: useV2Slider, ); } @@ -854,7 +818,6 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin { @required TextDirection textDirection, bool hasFocus, bool hovering, - bool useV2Slider, }) : assert(value != null && value >= 0.0 && value <= 1.0), assert(state != null), assert(textDirection != null), @@ -870,8 +833,7 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin { _state = state, _textDirection = textDirection, _hasFocus = hasFocus, - _hovering = hovering, - _useV2Slider = useV2Slider { + _hovering = hovering { _updateLabelPainter(); final GestureArenaTeam team = GestureArenaTeam(); _drag = HorizontalDragGestureRecognizer() @@ -1116,8 +1078,6 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin { } } } - final bool _useV2Slider; - bool get showValueIndicator { bool showValueIndicator; switch (_sliderTheme.showValueIndicator) { @@ -1379,7 +1339,7 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin { isEnabled: isInteractive, sliderTheme: _sliderTheme, ).width; - final double padding = _useV2Slider ? trackRect.height : tickMarkWidth; + final double padding = trackRect.height; final double adjustedTrackWidth = trackRect.width - padding; // If the tick marks would be too dense, don't bother painting them. if (adjustedTrackWidth / divisions >= 3.0 * tickMarkWidth) { diff --git a/packages/flutter/lib/src/material/slider_theme.dart b/packages/flutter/lib/src/material/slider_theme.dart index 727c323002..c7ba881f10 100644 --- a/packages/flutter/lib/src/material/slider_theme.dart +++ b/packages/flutter/lib/src/material/slider_theme.dart @@ -109,9 +109,6 @@ import 'theme_data.dart'; /// left, and in [TextDirection.rtl], the start of the slider is on the right. /// {@endtemplate} /// -/// {@template flutter.material.slider.useV2Slider} -/// Whether to use the updated Material spec version of the slider shape. -/// /// This is a temporary flag for migrating the slider from v1 to v2. To avoid /// unexpected breaking changes, this value should be set to true. Setting /// this to false is considered deprecated. @@ -1673,14 +1670,7 @@ class RectangularSliderTrackShape extends SliderTrackShape with BaseSliderTrackS /// * [RectangularSliderTrackShape], for a similar track with sharp edges. class RoundedRectSliderTrackShape extends SliderTrackShape with BaseSliderTrackShape { /// Create a slider track that draws two rectangles with rounded outer edges. - const RoundedRectSliderTrackShape({ this.useV2Slider = true }); - - /// {@macro flutter.material.slider.useV2Slider} - @Deprecated( - 'This flag has changed to true by default and no longer needed. ' - 'This feature was deprecated after v1.18.0.' - ) - final bool useV2Slider; + const RoundedRectSliderTrackShape(); @override void paint( @@ -1743,47 +1733,28 @@ class RoundedRectSliderTrackShape extends SliderTrackShape with BaseSliderTrackS final Radius trackRadius = Radius.circular(trackRect.height / 2); final Radius activeTrackRadius = Radius.circular(trackRect.height / 2 + 1); - // ignore: deprecated_member_use_from_same_package - if (useV2Slider) { - context.canvas.drawRRect( - RRect.fromLTRBAndCorners( - trackRect.left, - (textDirection == TextDirection.ltr) ? trackRect.top - (additionalActiveTrackHeight / 2): trackRect.top, - thumbCenter.dx, - (textDirection == TextDirection.ltr) ? trackRect.bottom + (additionalActiveTrackHeight / 2) : trackRect.bottom, - topLeft: (textDirection == TextDirection.ltr) ? activeTrackRadius : trackRadius, - bottomLeft: (textDirection == TextDirection.ltr) ? activeTrackRadius: trackRadius, - ), - leftTrackPaint, - ); - context.canvas.drawRRect( - RRect.fromLTRBAndCorners( - thumbCenter.dx, - (textDirection == TextDirection.rtl) ? trackRect.top - (additionalActiveTrackHeight / 2) : trackRect.top, - trackRect.right, - (textDirection == TextDirection.rtl) ? trackRect.bottom + (additionalActiveTrackHeight / 2) : trackRect.bottom, - topRight: (textDirection == TextDirection.rtl) ? activeTrackRadius : trackRadius, - bottomRight: (textDirection == TextDirection.rtl) ? activeTrackRadius : trackRadius, - ), - rightTrackPaint, - ); - } else { - // The arc rects create a semi-circle with radius equal to track height. - final Rect leftTrackArcRect = Rect.fromLTWH(trackRect.left, trackRect.top, trackRect.height, trackRect.height); - if (!leftTrackArcRect.isEmpty) - context.canvas.drawArc(leftTrackArcRect, math.pi / 2, math.pi, false, leftTrackPaint); - final Rect rightTrackArcRect = Rect.fromLTWH(trackRect.right - trackRect.height / 2, trackRect.top, trackRect.height, trackRect.height); - if (!rightTrackArcRect.isEmpty) - context.canvas.drawArc(rightTrackArcRect, -math.pi / 2, math.pi, false, rightTrackPaint); - - final Size thumbSize = sliderTheme.thumbShape.getPreferredSize(isEnabled, isDiscrete); - final Rect leftTrackSegment = Rect.fromLTRB(trackRect.left + trackRect.height / 2, trackRect.top, thumbCenter.dx - thumbSize.width / 2, trackRect.bottom); - if (!leftTrackSegment.isEmpty) - context.canvas.drawRect(leftTrackSegment, leftTrackPaint); - final Rect rightTrackSegment = Rect.fromLTRB(thumbCenter.dx + thumbSize.width / 2, trackRect.top, trackRect.right, trackRect.bottom); - if (!rightTrackSegment.isEmpty) - context.canvas.drawRect(rightTrackSegment, rightTrackPaint); - } + context.canvas.drawRRect( + RRect.fromLTRBAndCorners( + trackRect.left, + (textDirection == TextDirection.ltr) ? trackRect.top - (additionalActiveTrackHeight / 2): trackRect.top, + thumbCenter.dx, + (textDirection == TextDirection.ltr) ? trackRect.bottom + (additionalActiveTrackHeight / 2) : trackRect.bottom, + topLeft: (textDirection == TextDirection.ltr) ? activeTrackRadius : trackRadius, + bottomLeft: (textDirection == TextDirection.ltr) ? activeTrackRadius: trackRadius, + ), + leftTrackPaint, + ); + context.canvas.drawRRect( + RRect.fromLTRBAndCorners( + thumbCenter.dx, + (textDirection == TextDirection.rtl) ? trackRect.top - (additionalActiveTrackHeight / 2) : trackRect.top, + trackRect.right, + (textDirection == TextDirection.rtl) ? trackRect.bottom + (additionalActiveTrackHeight / 2) : trackRect.bottom, + topRight: (textDirection == TextDirection.rtl) ? activeTrackRadius : trackRadius, + bottomRight: (textDirection == TextDirection.rtl) ? activeTrackRadius : trackRadius, + ), + rightTrackPaint, + ); } } @@ -1815,14 +1786,7 @@ class RectangularRangeSliderTrackShape extends RangeSliderTrackShape { /// /// The middle track segment is the selected range and is active, and the two /// outer track segments are inactive. - const RectangularRangeSliderTrackShape({this.useV2Slider}); - - /// {@macro flutter.material.slider.useV2Slider} - @Deprecated( - 'This flag has changed to true by default and no longer needed. ' - 'This feature was deprecated after v1.18.0.' - ) - final bool useV2Slider; + const RectangularRangeSliderTrackShape(); @override Rect getPreferredRect({ @@ -1948,14 +1912,7 @@ class RoundedRectRangeSliderTrackShape extends RangeSliderTrackShape { /// /// The middle track segment is the selected range and is active, and the two /// outer track segments are inactive. - const RoundedRectRangeSliderTrackShape({ this.useV2Slider }); - - /// {@macro flutter.material.slider.useV2Slider} - @Deprecated( - 'This flag has changed to true by default and no longer needed. ' - 'This feature was deprecated after v1.18.0.' - ) - final bool useV2Slider; + const RoundedRectRangeSliderTrackShape(); @override Rect getPreferredRect({ @@ -2056,62 +2013,39 @@ class RoundedRectRangeSliderTrackShape extends RangeSliderTrackShape { isDiscrete: isDiscrete, ); - // ignore: deprecated_member_use_from_same_package - if (useV2Slider) { - final Radius trackRadius = Radius.circular(trackRect.height / 2); + final Radius trackRadius = Radius.circular(trackRect.height / 2); - context.canvas.drawRRect( - RRect.fromLTRBAndCorners( - trackRect.left, - trackRect.top, - leftThumbOffset.dx, - trackRect.bottom, - topLeft: trackRadius, - bottomLeft: trackRadius, - ), - inactivePaint, - ); - context.canvas.drawRect( - Rect.fromLTRB( - leftThumbOffset.dx, - trackRect.top - (additionalActiveTrackHeight / 2), - rightThumbOffset.dx, - trackRect.bottom + (additionalActiveTrackHeight / 2), - ), - activePaint, - ); - context.canvas.drawRRect( - RRect.fromLTRBAndCorners( - rightThumbOffset.dx, - trackRect.top, - trackRect.right, - trackRect.bottom, - topRight: trackRadius, - bottomRight: trackRadius, - ), - inactivePaint, - ); - } else { - final double trackRadius = trackRect.height / 2; - - final Rect leftTrackArcRect = Rect.fromLTWH(trackRect.left, trackRect.top, trackRect.height, trackRect.height); - if (!leftTrackArcRect.isEmpty) - context.canvas.drawArc(leftTrackArcRect, math.pi / 2, math.pi, false, inactivePaint); - - final Rect leftTrackSegment = Rect.fromLTRB(trackRect.left + trackRadius, trackRect.top, leftThumbOffset.dx - thumbRadius, 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); - if (!middleTrackSegment.isEmpty) - context.canvas.drawRect(middleTrackSegment, activePaint); - final Rect rightTrackSegment = Rect.fromLTRB(rightThumbOffset.dx + thumbRadius, trackRect.top, trackRect.right - trackRadius, trackRect.bottom); - if (!rightTrackSegment.isEmpty) - context.canvas.drawRect(rightTrackSegment, inactivePaint); - - final Rect rightTrackArcRect = Rect.fromLTWH(trackRect.right - trackRect.height, trackRect.top, trackRect.height, trackRect.height); - if (!rightTrackArcRect.isEmpty) - context.canvas.drawArc(rightTrackArcRect, -math.pi / 2, math.pi, false, inactivePaint); - } + context.canvas.drawRRect( + RRect.fromLTRBAndCorners( + trackRect.left, + trackRect.top, + leftThumbOffset.dx, + trackRect.bottom, + topLeft: trackRadius, + bottomLeft: trackRadius, + ), + inactivePaint, + ); + context.canvas.drawRect( + Rect.fromLTRB( + leftThumbOffset.dx, + trackRect.top - (additionalActiveTrackHeight / 2), + rightThumbOffset.dx, + trackRect.bottom + (additionalActiveTrackHeight / 2), + ), + activePaint, + ); + context.canvas.drawRRect( + RRect.fromLTRBAndCorners( + rightThumbOffset.dx, + trackRect.top, + trackRect.right, + trackRect.bottom, + topRight: trackRadius, + bottomRight: trackRadius, + ), + inactivePaint, + ); } } @@ -2137,25 +2071,13 @@ class RoundSliderTickMarkShape extends SliderTickMarkShape { /// Create a slider tick mark that draws a circle. const RoundSliderTickMarkShape({ this.tickMarkRadius, - this.useV2Slider = true, }); /// The preferred radius of the round tick mark. /// - // ignore: deprecated_member_use_from_same_package - /// If it is not provided, and [useV2Slider] is true, then 1/4 of the - /// [SliderThemeData.trackHeight] is used. If it is not provided, and - // ignore: deprecated_member_use_from_same_package - /// [useV2Slider] is false, then half of the track height is used. + /// If it is not provided, then 1/4 of the [SliderThemeData.trackHeight] is used. final double tickMarkRadius; - /// {@macro flutter.material.slider.useV2Slider} - @Deprecated( - 'This flag has changed to true by default and no longer needed. ' - 'This feature was deprecated after v1.18.0.' - ) - final bool useV2Slider; - @override Size getPreferredSize({ @required SliderThemeData sliderTheme, @@ -2166,10 +2088,8 @@ class RoundSliderTickMarkShape extends SliderTickMarkShape { assert(isEnabled != null); // The tick marks are tiny circles. If no radius is provided, then the // radius is defaulted to be a fraction of the - // [SliderThemeData.trackHeight]. The fraction is 1/4 when [useV2Slider] is - // true, and 1/2 when it is false. - // ignore: deprecated_member_use_from_same_package - return Size.fromRadius(tickMarkRadius ?? sliderTheme.trackHeight / (useV2Slider ? 4 : 2)); + // [SliderThemeData.trackHeight]. The fraction is 1/4. + return Size.fromRadius(tickMarkRadius ?? sliderTheme.trackHeight / 4); } @override @@ -2246,25 +2166,13 @@ class RoundRangeSliderTickMarkShape extends RangeSliderTickMarkShape { /// Create a range slider tick mark that draws a circle. const RoundRangeSliderTickMarkShape({ this.tickMarkRadius, - this.useV2Slider = true, }); /// The preferred radius of the round tick mark. /// - // ignore: deprecated_member_use_from_same_package - /// If it is not provided, and [useV2Slider] is true, then 1/4 of the - /// [SliderThemeData.trackHeight] is used. If it is not provided, and - // ignore: deprecated_member_use_from_same_package - /// [useV2Slider] is false, then half of the track height is used. + /// If it is not provided, then 1/4 of the [SliderThemeData.trackHeight] is used. final double tickMarkRadius; - /// {@macro flutter.material.slider.useV2Slider} - @Deprecated( - 'This flag has changed to true by default and no longer needed. ' - 'This feature was deprecated after v1.18.0.' - ) - final bool useV2Slider; - @override Size getPreferredSize({ @required SliderThemeData sliderTheme, @@ -2273,8 +2181,7 @@ class RoundRangeSliderTickMarkShape extends RangeSliderTickMarkShape { assert(sliderTheme != null); assert(sliderTheme.trackHeight != null); assert(isEnabled != null); - // ignore: deprecated_member_use_from_same_package - return Size.fromRadius(tickMarkRadius ?? sliderTheme.trackHeight / (useV2Slider ? 4 : 2)); + return Size.fromRadius(tickMarkRadius ?? sliderTheme.trackHeight / 4); } @override @@ -2392,9 +2299,7 @@ class _EmptySliderComponentShape extends SliderComponentShape { /// The default shape of a [Slider]'s thumb. /// -// ignore: deprecated_member_use_from_same_package -/// If [useV2Slider] is true, then there is a shadow for the resting and -/// pressed state. +/// There is a shadow for the resting, pressed, hovered, and focused state. /// /// See also: /// @@ -2408,7 +2313,6 @@ class RoundSliderThumbShape extends SliderComponentShape { this.disabledThumbRadius, this.elevation = 1.0, this.pressedElevation = 6.0, - this.useV2Slider = true, }); /// The preferred radius of the round thumb shape when the slider is enabled. @@ -2425,9 +2329,6 @@ class RoundSliderThumbShape extends SliderComponentShape { /// The resting elevation adds shadow to the unpressed thumb. /// - // ignore: deprecated_member_use_from_same_package - /// This value is only used when [useV2Slider] is true. - /// /// The default is 1. /// /// Use 0 for no shadow. The higher the value, the larger the shadow. For @@ -2437,22 +2338,12 @@ class RoundSliderThumbShape extends SliderComponentShape { /// The pressed elevation adds shadow to the pressed thumb. /// - // ignore: deprecated_member_use_from_same_package - /// This value is only used when [useV2Slider] is true. - /// /// The default is 6. /// /// Use 0 for no shadow. The higher the value, the larger the shadow. For /// example, a value of 12 will create a very large shadow. final double pressedElevation; - /// {@macro flutter.material.slider.useV2Slider} - @Deprecated( - 'This flag has changed to true by default and no longer needed. ' - 'This feature was deprecated after v1.18.0.' - ) - final bool useV2Slider; - @override Size getPreferredSize(bool isEnabled, bool isDiscrete) { return Size.fromRadius(isEnabled == true ? enabledThumbRadius : _disabledThumbRadius); @@ -2494,18 +2385,15 @@ class RoundSliderThumbShape extends SliderComponentShape { final Color color = colorTween.evaluate(enableAnimation); final double radius = radiusTween.evaluate(enableAnimation); - // ignore: deprecated_member_use_from_same_package - if (useV2Slider) { - final Tween elevationTween = Tween( - begin: elevation, - end: pressedElevation, - ); + final Tween elevationTween = Tween( + begin: elevation, + end: pressedElevation, + ); - final double evaluatedElevation = elevationTween.evaluate(activationAnimation); - final Path path = Path() - ..addArc(Rect.fromCenter(center: center, width: 2 * radius, height: 2 * radius), 0, math.pi * 2); - canvas.drawShadow(path, Colors.black, evaluatedElevation, true); - } + final double evaluatedElevation = elevationTween.evaluate(activationAnimation); + final Path path = Path() + ..addArc(Rect.fromCenter(center: center, width: 2 * radius, height: 2 * radius), 0, math.pi * 2); + canvas.drawShadow(path, Colors.black, evaluatedElevation, true); canvas.drawCircle( center, @@ -2517,9 +2405,7 @@ class RoundSliderThumbShape extends SliderComponentShape { /// The default shape of a [RangeSlider]'s thumbs. /// -// ignore: deprecated_member_use_from_same_package -/// If [useV2Slider] is true, then there is a shadow for the resting and -/// pressed state. +/// There is a shadow for the resting and pressed state. /// /// See also: /// @@ -2533,16 +2419,8 @@ class RoundRangeSliderThumbShape extends RangeSliderThumbShape { this.disabledThumbRadius, this.elevation = 1.0, this.pressedElevation = 6.0, - this.useV2Slider = true, }) : assert(enabledThumbRadius != null); - /// {@macro flutter.material.slider.useV2Slider} - @Deprecated( - 'This flag has changed to true by default and no longer needed. ' - 'This feature was deprecated after v1.18.0.' - ) - final bool useV2Slider; - /// The preferred radius of the round thumb shape when the slider is enabled. /// /// If it is not provided, then the material default of 10 is used. @@ -2636,13 +2514,10 @@ class RoundRangeSliderThumbShape extends RangeSliderThumbShape { final Color color = colorTween.evaluate(enableAnimation); - // ignore: deprecated_member_use_from_same_package - if (useV2Slider) { - final double evaluatedElevation = isPressed ? elevationTween.evaluate(activationAnimation) : elevation; - final Path shadowPath = Path() - ..addArc(Rect.fromCenter(center: center, width: 2 * radius, height: 2 * radius), 0, math.pi * 2); - canvas.drawShadow(shadowPath, Colors.black, evaluatedElevation, true); - } + final double evaluatedElevation = isPressed ? elevationTween.evaluate(activationAnimation) : elevation; + final Path shadowPath = Path() + ..addArc(Rect.fromCenter(center: center, width: 2 * radius, height: 2 * radius), 0, math.pi * 2); + canvas.drawShadow(shadowPath, Colors.black, evaluatedElevation, true); canvas.drawCircle( center, diff --git a/packages/flutter/test/material/inherited_theme_test.dart b/packages/flutter/test/material/inherited_theme_test.dart index 2d87515ea2..52b8ac1d09 100644 --- a/packages/flutter/test/material/inherited_theme_test.dart +++ b/packages/flutter/test/material/inherited_theme_test.dart @@ -461,8 +461,6 @@ void main() { final Widget slider = Scaffold( body: Center( child: Slider( - // ignore: deprecated_member_use_from_same_package - useV2Slider: false, value: 0.5, onChanged: (double value) { }, ), @@ -525,7 +523,7 @@ void main() { await tester.tap(find.text('push wrapped')); await tester.pumpAndSettle(); // route animation RenderBox sliderBox = tester.firstRenderObject(find.byType(Slider)); - expect(sliderBox, paints..rect(color: activeTrackColor)..rect(color: inactiveTrackColor)); + expect(sliderBox, paints..rrect(color: activeTrackColor)..rrect(color: inactiveTrackColor)); expect(sliderBox, paints..circle(color: thumbColor)); Navigator.of(navigatorContext).pop(); @@ -534,7 +532,7 @@ void main() { await tester.tap(find.text('push unwrapped')); await tester.pumpAndSettle(); // route animation sliderBox = tester.firstRenderObject(find.byType(Slider)); - expect(sliderBox, isNot(paints..rect(color: activeTrackColor)..rect(color: inactiveTrackColor))); + expect(sliderBox, isNot(paints..rrect(color: activeTrackColor)..rrect(color: inactiveTrackColor))); expect(sliderBox, isNot(paints..circle(color: thumbColor))); }); diff --git a/packages/flutter/test/material/range_slider_test.dart b/packages/flutter/test/material/range_slider_test.dart index 557d1fc42d..28380bc8c0 100644 --- a/packages/flutter/test/material/range_slider_test.dart +++ b/packages/flutter/test/material/range_slider_test.dart @@ -1031,7 +1031,6 @@ void main() { Color inactiveColor, int divisions, bool enabled = true, - bool useV2Slider = false, }) { RangeValues values = const RangeValues(0.5, 0.75); final ValueChanged onChanged = !enabled ? null : (RangeValues newValues) { @@ -1053,8 +1052,6 @@ void main() { activeColor: activeColor, inactiveColor: inactiveColor, onChanged: onChanged, - // ignore: deprecated_member_use_from_same_package - useV2Slider: useV2Slider, ), ), ), @@ -1064,11 +1061,11 @@ void main() { ); } - testWidgets('Range Slider V2 uses the right theme colors for the right shapes for a default enabled slider', (WidgetTester tester) async { + testWidgets('Range Slider uses the right theme colors for the right shapes for a default enabled slider', (WidgetTester tester) async { final ThemeData theme = _buildTheme(); final SliderThemeData sliderTheme = theme.sliderTheme; - await tester.pumpWidget(_buildThemedApp(theme: theme, useV2Slider: true)); + await tester.pumpWidget(_buildThemedApp(theme: theme)); final RenderBox sliderBox = tester.firstRenderObject(find.byType(RangeSlider)); @@ -1083,41 +1080,16 @@ void main() { expect(sliderBox, isNot(paints..circle(color: sliderTheme.disabledThumbColor))); expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledActiveTrackColor))); expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledInactiveTrackColor))); - expect(sliderBox, isNot(paints..rrect(color: sliderTheme.disabledActiveTrackColor))); - expect(sliderBox, isNot(paints..rrect(color: sliderTheme.disabledInactiveTrackColor))); expect(sliderBox, isNot(paints..circle(color: sliderTheme.activeTickMarkColor))); expect(sliderBox, isNot(paints..circle(color: sliderTheme.inactiveTickMarkColor))); }); - testWidgets('Range Slider uses the right theme colors for the right shapes for a default enabled slider', (WidgetTester tester) async { - final ThemeData theme = _buildTheme(); - final SliderThemeData sliderTheme = theme.sliderTheme; - - await tester.pumpWidget(_buildThemedApp(theme: theme)); - - final RenderBox sliderBox = tester.firstRenderObject(find.byType(RangeSlider)); - - // Check default theme for enabled widget. - expect(sliderBox, paints - ..rect(color: sliderTheme.inactiveTrackColor) - ..rect(color: sliderTheme.activeTrackColor) - ..rect(color: sliderTheme.inactiveTrackColor)); - expect(sliderBox, paints - ..circle(color: sliderTheme.thumbColor) - ..circle(color: sliderTheme.thumbColor)); - expect(sliderBox, isNot(paints..circle(color: sliderTheme.disabledThumbColor))); - expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledActiveTrackColor))); - expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledInactiveTrackColor))); - expect(sliderBox, isNot(paints..circle(color: sliderTheme.activeTickMarkColor))); - expect(sliderBox, isNot(paints..circle(color: sliderTheme.inactiveTickMarkColor))); - }); - - testWidgets('Range Slider V2 uses the right theme colors for the right shapes when setting the active color', (WidgetTester tester) async { + testWidgets('Range Slider uses the right theme colors for the right shapes when setting the active color', (WidgetTester tester) async { const Color activeColor = Color(0xcafefeed); final ThemeData theme = _buildTheme(); final SliderThemeData sliderTheme = theme.sliderTheme; - await tester.pumpWidget(_buildThemedApp(theme: theme, activeColor: activeColor, useV2Slider: true)); + await tester.pumpWidget(_buildThemedApp(theme: theme, activeColor: activeColor)); final RenderBox sliderBox = tester.firstRenderObject(find.byType(RangeSlider)); @@ -1136,61 +1108,6 @@ void main() { expect(sliderBox, isNot(paints..circle(color: sliderTheme.disabledThumbColor))); expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledActiveTrackColor))); expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledInactiveTrackColor))); - expect(sliderBox, isNot(paints..rrect(color: sliderTheme.disabledActiveTrackColor))); - expect(sliderBox, isNot(paints..rrect(color: sliderTheme.disabledInactiveTrackColor))); - }); - - testWidgets('Range Slider uses the right theme colors for the right shapes when setting the active color', (WidgetTester tester) async { - const Color activeColor = Color(0xcafefeed); - final ThemeData theme = _buildTheme(); - final SliderThemeData sliderTheme = theme.sliderTheme; - - await tester.pumpWidget(_buildThemedApp(theme: theme, activeColor: activeColor)); - - final RenderBox sliderBox = tester.firstRenderObject(find.byType(RangeSlider)); - - expect( - sliderBox, - paints - ..rect(color: sliderTheme.inactiveTrackColor) - ..rect(color: activeColor) - ..rect(color: sliderTheme.inactiveTrackColor)); - expect( - sliderBox, - paints - ..circle(color: activeColor) - ..circle(color: activeColor)); - expect(sliderBox, isNot(paints..circle(color: sliderTheme.thumbColor))); - expect(sliderBox, isNot(paints..circle(color: sliderTheme.disabledThumbColor))); - expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledActiveTrackColor))); - expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledInactiveTrackColor))); - }); - - testWidgets('Range Slider V2 uses the right theme colors for the right shapes when setting the inactive color', (WidgetTester tester) async { - const Color inactiveColor = Color(0xdeadbeef); - final ThemeData theme = _buildTheme(); - final SliderThemeData sliderTheme = theme.sliderTheme; - - await tester.pumpWidget(_buildThemedApp(theme: theme, inactiveColor: inactiveColor, useV2Slider: true)); - - final RenderBox sliderBox = tester.firstRenderObject(find.byType(RangeSlider)); - - expect( - sliderBox, - paints - ..rrect(color: inactiveColor) - ..rect(color: sliderTheme.activeTrackColor) - ..rrect(color: inactiveColor)); - expect( - sliderBox, - paints - ..circle(color: sliderTheme.thumbColor) - ..circle(color: sliderTheme.thumbColor)); - expect(sliderBox, isNot(paints..circle(color: sliderTheme.disabledThumbColor))); - expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledActiveTrackColor))); - expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledInactiveTrackColor))); - expect(sliderBox, isNot(paints..rrect(color: sliderTheme.disabledActiveTrackColor))); - expect(sliderBox, isNot(paints..rrect(color: sliderTheme.disabledInactiveTrackColor))); }); testWidgets('Range Slider uses the right theme colors for the right shapes when setting the inactive color', (WidgetTester tester) async { @@ -1205,9 +1122,9 @@ void main() { expect( sliderBox, paints - ..rect(color: inactiveColor) + ..rrect(color: inactiveColor) ..rect(color: sliderTheme.activeTrackColor) - ..rect(color: inactiveColor)); + ..rrect(color: inactiveColor)); expect( sliderBox, paints @@ -1218,38 +1135,6 @@ void main() { expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledInactiveTrackColor))); }); - testWidgets('Range Slider V2 uses the right theme colors for the right shapes with active and inactive colors', (WidgetTester tester) async { - const Color activeColor = Color(0xcafefeed); - const Color inactiveColor = Color(0xdeadbeef); - final ThemeData theme = _buildTheme(); - final SliderThemeData sliderTheme = theme.sliderTheme; - - await tester.pumpWidget(_buildThemedApp( - theme: theme, - activeColor: activeColor, - inactiveColor: inactiveColor, - useV2Slider: true, - )); - - final RenderBox sliderBox = tester.firstRenderObject(find.byType(RangeSlider)); - - expect( - sliderBox, - paints - ..rrect(color: inactiveColor) - ..rect(color: activeColor) - ..rrect(color: inactiveColor)); - expect( - sliderBox, - paints - ..circle(color: activeColor) - ..circle(color: activeColor)); - expect(sliderBox, isNot(paints..circle(color: sliderTheme.thumbColor))); - expect(sliderBox, isNot(paints..circle(color: sliderTheme.disabledThumbColor))); - expect(sliderBox, isNot(paints..rrect(color: sliderTheme.disabledActiveTrackColor))); - expect(sliderBox, isNot(paints..rrect(color: sliderTheme.disabledInactiveTrackColor))); - }); - testWidgets('Range Slider uses the right theme colors for the right shapes with active and inactive colors', (WidgetTester tester) async { const Color activeColor = Color(0xcafefeed); const Color inactiveColor = Color(0xdeadbeef); @@ -1267,9 +1152,9 @@ void main() { expect( sliderBox, paints - ..rect(color: inactiveColor) + ..rrect(color: inactiveColor) ..rect(color: activeColor) - ..rect(color: inactiveColor)); + ..rrect(color: inactiveColor)); expect( sliderBox, paints @@ -1281,11 +1166,11 @@ void main() { expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledInactiveTrackColor))); }); - testWidgets('Range Slider V2 uses the right theme colors for the right shapes for a discrete slider', (WidgetTester tester) async { + testWidgets('Range Slider uses the right theme colors for the right shapes for a discrete slider', (WidgetTester tester) async { final ThemeData theme = _buildTheme(); final SliderThemeData sliderTheme = theme.sliderTheme; - await tester.pumpWidget(_buildThemedApp(theme: theme, divisions: 3, useV2Slider: true)); + await tester.pumpWidget(_buildThemedApp(theme: theme, divisions: 3)); final RenderBox sliderBox = tester.firstRenderObject(find.byType(RangeSlider)); @@ -1307,78 +1192,6 @@ void main() { expect(sliderBox, isNot(paints..circle(color: sliderTheme.disabledThumbColor))); expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledActiveTrackColor))); expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledInactiveTrackColor))); - expect(sliderBox, isNot(paints..rrect(color: sliderTheme.disabledActiveTrackColor))); - expect(sliderBox, isNot(paints..rrect(color: sliderTheme.disabledInactiveTrackColor))); - }); - - testWidgets('Range Slider uses the right theme colors for the right shapes for a discrete slider', (WidgetTester tester) async { - final ThemeData theme = _buildTheme(); - final SliderThemeData sliderTheme = theme.sliderTheme; - - await tester.pumpWidget(_buildThemedApp(theme: theme, divisions: 3)); - - final RenderBox sliderBox = tester.firstRenderObject(find.byType(RangeSlider)); - - expect( - sliderBox, - paints - ..rect(color: sliderTheme.inactiveTrackColor) - ..rect(color: sliderTheme.activeTrackColor) - ..rect(color: sliderTheme.inactiveTrackColor)); - expect( - sliderBox, - paints - ..circle(color: sliderTheme.inactiveTickMarkColor) - ..circle(color: sliderTheme.inactiveTickMarkColor) - ..circle(color: sliderTheme.activeTickMarkColor) - ..circle(color: sliderTheme.inactiveTickMarkColor) - ..circle(color: sliderTheme.thumbColor) - ..circle(color: sliderTheme.thumbColor)); - expect(sliderBox, isNot(paints..circle(color: sliderTheme.disabledThumbColor))); - expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledActiveTrackColor))); - expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledInactiveTrackColor))); - }); - - testWidgets('Range Slider V2 uses the right theme colors for the right shapes for a discrete slider with active and inactive colors', (WidgetTester tester) async { - const Color activeColor = Color(0xcafefeed); - const Color inactiveColor = Color(0xdeadbeef); - final ThemeData theme = _buildTheme(); - final SliderThemeData sliderTheme = theme.sliderTheme; - - - await tester.pumpWidget(_buildThemedApp( - theme: theme, - activeColor: activeColor, - inactiveColor: inactiveColor, - divisions: 3, - useV2Slider: true, - )); - - final RenderBox sliderBox = tester.firstRenderObject(find.byType(RangeSlider)); - - expect( - sliderBox, - paints - ..rrect(color: inactiveColor) - ..rect(color: activeColor) - ..rrect(color: inactiveColor)); - expect( - sliderBox, - paints - ..circle(color: activeColor) - ..circle(color: activeColor) - ..circle(color: inactiveColor) - ..circle(color: activeColor) - ..circle(color: activeColor) - ..circle(color: activeColor)); - expect(sliderBox, isNot(paints..circle(color: sliderTheme.thumbColor))); - expect(sliderBox, isNot(paints..circle(color: sliderTheme.disabledThumbColor))); - expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledActiveTrackColor))); - expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledInactiveTrackColor))); - expect(sliderBox, isNot(paints..rrect(color: sliderTheme.disabledActiveTrackColor))); - expect(sliderBox, isNot(paints..rrect(color: sliderTheme.disabledInactiveTrackColor))); - expect(sliderBox, isNot(paints..circle(color: sliderTheme.activeTickMarkColor))); - expect(sliderBox, isNot(paints..circle(color: sliderTheme.inactiveTickMarkColor))); }); testWidgets('Range Slider uses the right theme colors for the right shapes for a discrete slider with active and inactive colors', (WidgetTester tester) async { @@ -1400,9 +1213,9 @@ void main() { expect( sliderBox, paints - ..rect(color: inactiveColor) + ..rrect(color: inactiveColor) ..rect(color: activeColor) - ..rect(color: inactiveColor)); + ..rrect(color: inactiveColor)); expect( sliderBox, paints @@ -1420,27 +1233,6 @@ void main() { expect(sliderBox, isNot(paints..circle(color: sliderTheme.inactiveTickMarkColor))); }); - testWidgets('Range Slider V2 uses the right theme colors for the right shapes for a default disabled slider', (WidgetTester tester) async { - final ThemeData theme = _buildTheme(); - final SliderThemeData sliderTheme = theme.sliderTheme; - - await tester.pumpWidget(_buildThemedApp(theme: theme, enabled: false, useV2Slider: true)); - - final RenderBox sliderBox = tester.firstRenderObject(find.byType(RangeSlider)); - - expect( - sliderBox, - paints - ..rrect(color: sliderTheme.disabledInactiveTrackColor) - ..rect(color: sliderTheme.disabledActiveTrackColor) - ..rrect(color: sliderTheme.disabledInactiveTrackColor)); - expect(sliderBox, isNot(paints..circle(color: sliderTheme.thumbColor))); - expect(sliderBox, isNot(paints..rect(color: sliderTheme.activeTrackColor))); - expect(sliderBox, isNot(paints..rect(color: sliderTheme.inactiveTrackColor))); - expect(sliderBox, isNot(paints..rrect(color: sliderTheme.activeTrackColor))); - expect(sliderBox, isNot(paints..rrect(color: sliderTheme.inactiveTrackColor))); - }); - testWidgets('Range Slider uses the right theme colors for the right shapes for a default disabled slider', (WidgetTester tester) async { final ThemeData theme = _buildTheme(); final SliderThemeData sliderTheme = theme.sliderTheme; @@ -1449,34 +1241,6 @@ void main() { final RenderBox sliderBox = tester.firstRenderObject(find.byType(RangeSlider)); - expect( - sliderBox, - paints - ..rect(color: sliderTheme.disabledInactiveTrackColor) - ..rect(color: sliderTheme.disabledActiveTrackColor) - ..rect(color: sliderTheme.disabledInactiveTrackColor)); - expect(sliderBox, isNot(paints..circle(color: sliderTheme.thumbColor))); - expect(sliderBox, isNot(paints..rect(color: sliderTheme.activeTrackColor))); - expect(sliderBox, isNot(paints..rect(color: sliderTheme.inactiveTrackColor))); - - }); - - testWidgets('Range Slider V2 uses the right theme colors for the right shapes for a disabled slider with active and inactive colors', (WidgetTester tester) async { - const Color activeColor = Color(0xcafefeed); - const Color inactiveColor = Color(0xdeadbeef); - final ThemeData theme = _buildTheme(); - final SliderThemeData sliderTheme = theme.sliderTheme; - - await tester.pumpWidget(_buildThemedApp( - theme: theme, - activeColor: activeColor, - inactiveColor: inactiveColor, - enabled: false, - useV2Slider: true, - )); - - final RenderBox sliderBox = tester.firstRenderObject(find.byType(RangeSlider)); - expect( sliderBox, paints @@ -1486,8 +1250,6 @@ void main() { expect(sliderBox, isNot(paints..circle(color: sliderTheme.thumbColor))); expect(sliderBox, isNot(paints..rect(color: sliderTheme.activeTrackColor))); expect(sliderBox, isNot(paints..rect(color: sliderTheme.inactiveTrackColor))); - expect(sliderBox, isNot(paints..rrect(color: sliderTheme.activeTrackColor))); - expect(sliderBox, isNot(paints..rrect(color: sliderTheme.inactiveTrackColor))); }); testWidgets('Range Slider uses the right theme colors for the right shapes for a disabled slider with active and inactive colors', (WidgetTester tester) async { @@ -1508,15 +1270,15 @@ void main() { expect( sliderBox, paints - ..rect(color: sliderTheme.disabledInactiveTrackColor) + ..rrect(color: sliderTheme.disabledInactiveTrackColor) ..rect(color: sliderTheme.disabledActiveTrackColor) - ..rect(color: sliderTheme.disabledInactiveTrackColor)); + ..rrect(color: sliderTheme.disabledInactiveTrackColor)); expect(sliderBox, isNot(paints..circle(color: sliderTheme.thumbColor))); expect(sliderBox, isNot(paints..rect(color: sliderTheme.activeTrackColor))); expect(sliderBox, isNot(paints..rect(color: sliderTheme.inactiveTrackColor))); }); - testWidgets('Range Slider V2 uses the right theme colors for the right shapes when the value indicators are showing', (WidgetTester tester) async { + testWidgets('Range Slider uses the right theme colors for the right shapes when the value indicators are showing', (WidgetTester tester) async { final ThemeData theme = _buildTheme(); final SliderThemeData sliderTheme = theme.sliderTheme; RangeValues values = const RangeValues(0.5, 0.75); @@ -1546,8 +1308,6 @@ void main() { activeColor: activeColor, inactiveColor: inactiveColor, onChanged: onChanged, - // ignore: deprecated_member_use_from_same_package - useV2Slider: true, ), ), ), @@ -1575,159 +1335,7 @@ void main() { await gesture.up(); // Wait for value indicator animation to finish. await tester.pumpAndSettle(); - }); - testWidgets('Range Slider uses the right theme colors for the right shapes when the value indicators are showing', (WidgetTester tester) async { - const Color customColor1 = Color(0xcafefeed); - const Color customColor2 = Color(0xdeadbeef); - final ThemeData theme = _buildTheme(); - final SliderThemeData sliderTheme = theme.sliderTheme; - RangeValues values = const RangeValues(0.5, 0.75); - - Widget buildApp({ - Color activeColor, - Color inactiveColor, - int divisions, - bool enabled = true, - }) { - final ValueChanged onChanged = !enabled ? null : (RangeValues newValues) { - values = newValues; - }; - return MaterialApp( - home: Directionality( - textDirection: TextDirection.ltr, - child: MediaQuery( - data: MediaQueryData.fromWindow(window), - child: Material( - child: Center( - child: Theme( - data: theme, - child: RangeSlider( - // ignore: deprecated_member_use_from_same_package - useV2Slider: false, - values: values, - labels: RangeLabels(values.start.toStringAsFixed(2), values.end.toStringAsFixed(2)), - divisions: divisions, - activeColor: activeColor, - inactiveColor: inactiveColor, - onChanged: onChanged, - ), - ), - ), - ), - ), - ), - ); - } - - await tester.pumpWidget(buildApp(divisions: 3)); - - final RenderBox valueIndicatorBox = tester.firstRenderObject(find.byType(Overlay)); - - final Offset topRight = tester.getTopRight(find.byType(RangeSlider)).translate(-24, 0); - TestGesture gesture = await tester.startGesture(topRight); - // Wait for value indicator animation to finish. - await tester.pumpAndSettle(); - expect(values.end, equals(1)); - expect( - valueIndicatorBox, - paints - ..path(color: sliderTheme.valueIndicatorColor) - ..path(color: sliderTheme.valueIndicatorColor), - ); - await gesture.up(); - // Wait for value indicator animation to finish. - await tester.pumpAndSettle(); - - // Testing the custom colors are used for the indicator. - await tester.pumpWidget(buildApp( - divisions: 3, - activeColor: customColor1, - inactiveColor: customColor2, - )); - gesture = await tester.startGesture(topRight); - // Wait for value indicator animation to finish. - await tester.pumpAndSettle(); - expect(values.end, equals(1)); - expect( - valueIndicatorBox, - paints - ..path(color: customColor1) - ..path(color: customColor1), - ); - await gesture.up(); - }); - - testWidgets('Range Slider V2 top thumb gets stroked when overlapping', (WidgetTester tester) async { - RangeValues values = const RangeValues(0.3, 0.7); - - final ThemeData theme = ThemeData( - platform: TargetPlatform.android, - primarySwatch: Colors.blue, - sliderTheme: const SliderThemeData( - thumbColor: Color(0xff000001), - overlappingShapeStrokeColor: Color(0xff000002), - ), - ); - final SliderThemeData sliderTheme = theme.sliderTheme; - - await tester.pumpWidget( - MaterialApp( - home: Directionality( - textDirection: TextDirection.ltr, - child: StatefulBuilder( - builder: (BuildContext context, StateSetter setState) { - return MediaQuery( - data: MediaQueryData.fromWindow(window), - child: Material( - child: Center( - child: Theme( - data: theme, - child: RangeSlider( - values: values, - onChanged: (RangeValues newValues) { - setState(() { - values = newValues; - }); - }, - // ignore: deprecated_member_use_from_same_package - useV2Slider: true, - ), - ), - ), - ), - ); - }, - ), - ), - ), - ); - - final RenderBox valueIndicatorBox = tester.firstRenderObject(find.byType(Overlay)); - - // Get the bounds of the track by finding the slider edges and translating - // inwards by the overlay radius. - final Offset topLeft = tester.getTopLeft(find.byType(RangeSlider)).translate(24, 0); - final Offset bottomRight = tester.getBottomRight(find.byType(RangeSlider)).translate(-24, 0); - final Offset middle = topLeft + bottomRight / 2; - - // Drag the thumbs towards the center. - final Offset leftTarget = topLeft + (bottomRight - topLeft) * 0.3; - await tester.dragFrom(leftTarget, middle - leftTarget); - await tester.pumpAndSettle(); - final Offset rightTarget = topLeft + (bottomRight - topLeft) * 0.7; - await tester.dragFrom(rightTarget, middle - rightTarget); - expect(values.start, closeTo(0.5, 0.03)); - expect(values.end, closeTo(0.5, 0.03)); - await tester.pumpAndSettle(); - - expect( - valueIndicatorBox, - paints - ..circle(color: sliderTheme.thumbColor) - ..circle(color: sliderTheme.overlappingShapeStrokeColor) - ..circle(color: sliderTheme.thumbColor), - ); }); testWidgets('Range Slider top thumb gets stroked when overlapping', (WidgetTester tester) async { @@ -1800,84 +1408,6 @@ void main() { ); }); - testWidgets('Range Slider V2 top value indicator gets stroked when overlapping', (WidgetTester tester) async { - RangeValues values = const RangeValues(0.3, 0.7); - - final ThemeData theme = ThemeData( - platform: TargetPlatform.android, - primarySwatch: Colors.blue, - sliderTheme: const SliderThemeData( - valueIndicatorColor: Color(0xff000001), - overlappingShapeStrokeColor: Color(0xff000002), - showValueIndicator: ShowValueIndicator.always, - ), - ); - final SliderThemeData sliderTheme = theme.sliderTheme; - - await tester.pumpWidget( - MaterialApp( - home: Directionality( - textDirection: TextDirection.ltr, - child: StatefulBuilder( - builder: (BuildContext context, StateSetter setState) { - return MediaQuery( - data: MediaQueryData.fromWindow(window), - child: Material( - child: Center( - child: Theme( - data: theme, - child: RangeSlider( - values: values, - labels: RangeLabels(values.start.toStringAsFixed(2), values.end.toStringAsFixed(2)), - onChanged: (RangeValues newValues) { - setState(() { - values = newValues; - }); - }, - // ignore: deprecated_member_use_from_same_package - useV2Slider: true, - ), - ), - ), - ), - ); - }, - ), - ), - ), - ); - - final RenderBox valueIndicatorBox = tester.firstRenderObject(find.byType(Overlay)); - - // Get the bounds of the track by finding the slider edges and translating - // inwards by the overlay radius. - final Offset topLeft = tester.getTopLeft(find.byType(RangeSlider)).translate(24, 0); - final Offset bottomRight = tester.getBottomRight(find.byType(RangeSlider)).translate(-24, 0); - final Offset middle = topLeft + bottomRight / 2; - - // Drag the thumbs towards the center. - final Offset leftTarget = topLeft + (bottomRight - topLeft) * 0.3; - await tester.dragFrom(leftTarget, middle - leftTarget); - await tester.pumpAndSettle(); - final Offset rightTarget = topLeft + (bottomRight - topLeft) * 0.7; - await tester.dragFrom(rightTarget, middle - rightTarget); - await tester.pumpAndSettle(); - expect(values.start, closeTo(0.5, 0.03)); - expect(values.end, closeTo(0.5, 0.03)); - final TestGesture gesture = await tester.startGesture(middle); - await tester.pumpAndSettle(); - - expect( - valueIndicatorBox, - paints - ..path(color: sliderTheme.valueIndicatorColor) - ..path(color: sliderTheme.overlappingShapeStrokeColor) - ..path(color: sliderTheme.valueIndicatorColor), - ); - - await gesture.up(); - }); - testWidgets('Range Slider top value indicator gets stroked when overlapping', (WidgetTester tester) async { RangeValues values = const RangeValues(0.3, 0.7); @@ -1954,84 +1484,6 @@ void main() { await gesture.up(); }); - testWidgets('Range Slider V2 top value indicator gets stroked when overlapping with large text scale', (WidgetTester tester) async { - RangeValues values = const RangeValues(0.3, 0.7); - - final ThemeData theme = ThemeData( - platform: TargetPlatform.android, - primarySwatch: Colors.blue, - sliderTheme: const SliderThemeData( - valueIndicatorColor: Color(0xff000001), - overlappingShapeStrokeColor: Color(0xff000002), - showValueIndicator: ShowValueIndicator.always, - ), - ); - final SliderThemeData sliderTheme = theme.sliderTheme; - - await tester.pumpWidget( - MaterialApp( - home: Directionality( - textDirection: TextDirection.ltr, - child: StatefulBuilder( - builder: (BuildContext context, StateSetter setState) { - return MediaQuery( - data: MediaQueryData.fromWindow(window).copyWith(textScaleFactor: 2.0), - child: Material( - child: Center( - child: Theme( - data: theme, - child: RangeSlider( - values: values, - labels: RangeLabels(values.start.toStringAsFixed(2), values.end.toStringAsFixed(2)), - onChanged: (RangeValues newValues) { - setState(() { - values = newValues; - }); - }, - // ignore: deprecated_member_use_from_same_package - useV2Slider: true, - ), - ), - ), - ), - ); - }, - ), - ), - ), - ); - - final RenderBox valueIndicatorBox = tester.firstRenderObject(find.byType(Overlay)); - - // Get the bounds of the track by finding the slider edges and translating - // inwards by the overlay radius. - final Offset topLeft = tester.getTopLeft(find.byType(RangeSlider)).translate(24, 0); - final Offset bottomRight = tester.getBottomRight(find.byType(RangeSlider)).translate(-24, 0); - final Offset middle = topLeft + bottomRight / 2; - - // Drag the thumbs towards the center. - final Offset leftTarget = topLeft + (bottomRight - topLeft) * 0.3; - await tester.dragFrom(leftTarget, middle - leftTarget); - await tester.pumpAndSettle(); - final Offset rightTarget = topLeft + (bottomRight - topLeft) * 0.7; - await tester.dragFrom(rightTarget, middle - rightTarget); - await tester.pumpAndSettle(); - expect(values.start, closeTo(0.5, 0.03)); - expect(values.end, closeTo(0.5, 0.03)); - final TestGesture gesture = await tester.startGesture(middle); - await tester.pumpAndSettle(); - - expect( - valueIndicatorBox, - paints - ..path(color: sliderTheme.valueIndicatorColor) - ..path(color: sliderTheme.overlappingShapeStrokeColor) - ..path(color: sliderTheme.valueIndicatorColor), - ); - - await gesture.up(); - }); - testWidgets('Range Slider top value indicator gets stroked when overlapping with large text scale', (WidgetTester tester) async { RangeValues values = const RangeValues(0.3, 0.7); @@ -2112,8 +1564,6 @@ void main() { final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); RangeSlider( - // ignore: deprecated_member_use_from_same_package - useV2Slider: false, activeColor: Colors.blue, divisions: 4, inactiveColor: Colors.grey, @@ -2142,7 +1592,6 @@ void main() { 'labelEnd: "upperValue"', 'activeColor: MaterialColor(primary value: Color(0xff2196f3))', 'inactiveColor: MaterialColor(primary value: Color(0xff9e9e9e))', - 'useV1Slider', ]); }); } diff --git a/packages/flutter/test/material/slider_test.dart b/packages/flutter/test/material/slider_test.dart index 7f5868b5b7..3ebc8cd7a4 100644 --- a/packages/flutter/test/material/slider_test.dart +++ b/packages/flutter/test/material/slider_test.dart @@ -570,17 +570,17 @@ void main() { home: Directionality( textDirection: TextDirection.ltr, child: MediaQuery( - data: MediaQueryData.fromWindow(window), - child: Material( - child: Slider( - value: 0.0, - min: 0.0, - max: 0.0, - onChanged: (double newValue) { - log.add(newValue); - }, - ), + data: MediaQueryData.fromWindow(window), + child: Material( + child: Slider( + value: 0.0, + min: 0.0, + max: 0.0, + onChanged: (double newValue) { + log.add(newValue); + }, ), + ), ), ), ), @@ -591,7 +591,7 @@ void main() { log.clear(); }); - testWidgets('Slider V2 uses the right theme colors for the right components', (WidgetTester tester) async { + testWidgets('Slider uses the right theme colors for the right components', (WidgetTester tester) async { const Color customColor1 = Color(0xcafefeed); const Color customColor2 = Color(0xdeadbeef); final ThemeData theme = ThemeData( @@ -641,8 +641,6 @@ void main() { activeColor: activeColor, inactiveColor: inactiveColor, onChanged: onChanged, - // ignore: deprecated_member_use_from_same_package - useV2Slider: true, ), ), ), @@ -814,220 +812,6 @@ void main() { await gesture.up(); }); - testWidgets('Slider uses the right theme colors for the right components', (WidgetTester tester) async { - const Color customColor1 = Color(0xcafefeed); - const Color customColor2 = Color(0xdeadbeef); - final ThemeData theme = ThemeData( - platform: TargetPlatform.android, - primarySwatch: Colors.blue, - sliderTheme: const SliderThemeData( - disabledThumbColor: Color(0xff000001), - disabledActiveTickMarkColor: Color(0xff000002), - disabledActiveTrackColor: Color(0xff000003), - disabledInactiveTickMarkColor: Color(0xff000004), - disabledInactiveTrackColor: Color(0xff000005), - activeTrackColor: Color(0xff000006), - activeTickMarkColor: Color(0xff000007), - inactiveTrackColor: Color(0xff000008), - inactiveTickMarkColor: Color(0xff000009), - overlayColor: Color(0xff000010), - thumbColor: Color(0xff000011), - valueIndicatorColor: Color(0xff000012), - ), - ); - final SliderThemeData sliderTheme = theme.sliderTheme; - double value = 0.45; - Widget buildApp({ - Color activeColor, - Color inactiveColor, - int divisions, - bool enabled = true, - }) { - final ValueChanged onChanged = !enabled - ? null - : (double d) { - value = d; - }; - return MaterialApp( - home: Directionality( - textDirection: TextDirection.ltr, - child: MediaQuery( - data: MediaQueryData.fromWindow(window), - child: Material( - child: Center( - child: Theme( - data: theme, - child: Slider( - // ignore: deprecated_member_use_from_same_package - useV2Slider: false, - value: value, - label: '$value', - divisions: divisions, - activeColor: activeColor, - inactiveColor: inactiveColor, - onChanged: onChanged, - ), - ), - ), - ), - ), - ), - ); - } - - await tester.pumpWidget(buildApp()); - - final MaterialInkController material = Material.of(tester.element(find.byType(Slider))); - final RenderBox valueIndicatorBox = tester.firstRenderObject(find.byType(Overlay)); - - // Check default theme for enabled widget. - expect(material, paints..rect(color: sliderTheme.activeTrackColor)..rect(color: sliderTheme.inactiveTrackColor)); - expect(material, paints..circle(color: sliderTheme.thumbColor)); - expect(material, isNot(paints..circle(color: sliderTheme.disabledThumbColor))); - expect(material, isNot(paints..rect(color: sliderTheme.disabledActiveTrackColor))); - expect(material, isNot(paints..rect(color: sliderTheme.disabledInactiveTrackColor))); - expect(material, isNot(paints..circle(color: sliderTheme.activeTickMarkColor))); - expect(material, isNot(paints..circle(color: sliderTheme.inactiveTickMarkColor))); - - // Test setting only the activeColor. - await tester.pumpWidget(buildApp(activeColor: customColor1)); - expect(material, paints..rect(color: customColor1)..rect(color: sliderTheme.inactiveTrackColor)); - expect(material, paints..circle(color: customColor1)); - expect(material, isNot(paints..circle(color: sliderTheme.thumbColor))); - expect(material, isNot(paints..circle(color: sliderTheme.disabledThumbColor))); - expect(material, isNot(paints..rect(color: sliderTheme.disabledActiveTrackColor))); - expect(material, isNot(paints..rect(color: sliderTheme.disabledInactiveTrackColor))); - - // Test setting only the inactiveColor. - await tester.pumpWidget(buildApp(inactiveColor: customColor1)); - expect(material, paints..rect(color: sliderTheme.activeTrackColor)..rect(color: customColor1)); - expect(material, paints..circle(color: sliderTheme.thumbColor)); - expect(material, isNot(paints..circle(color: sliderTheme.disabledThumbColor))); - expect(material, isNot(paints..rect(color: sliderTheme.disabledActiveTrackColor))); - expect(material, isNot(paints..rect(color: sliderTheme.disabledInactiveTrackColor))); - - // Test setting both activeColor and inactiveColor. - await tester.pumpWidget(buildApp(activeColor: customColor1, inactiveColor: customColor2)); - expect(material, paints..rect(color: customColor1)..rect(color: customColor2)); - expect(material, paints..circle(color: customColor1)); - expect(material, isNot(paints..circle(color: sliderTheme.thumbColor))); - expect(material, isNot(paints..circle(color: sliderTheme.disabledThumbColor))); - expect(material, isNot(paints..rect(color: sliderTheme.disabledActiveTrackColor))); - expect(material, isNot(paints..rect(color: sliderTheme.disabledInactiveTrackColor))); - - // Test colors for discrete slider. - await tester.pumpWidget(buildApp(divisions: 3)); - expect(material, paints..rect(color: sliderTheme.activeTrackColor)..rect(color: sliderTheme.inactiveTrackColor)); - expect( - material, - paints - ..circle(color: sliderTheme.activeTickMarkColor) - ..circle(color: sliderTheme.activeTickMarkColor) - ..circle(color: sliderTheme.inactiveTickMarkColor) - ..circle(color: sliderTheme.inactiveTickMarkColor) - ..circle(color: sliderTheme.thumbColor)); - expect(material, isNot(paints..circle(color: sliderTheme.disabledThumbColor))); - expect(material, isNot(paints..rect(color: sliderTheme.disabledActiveTrackColor))); - expect(material, isNot(paints..rect(color: sliderTheme.disabledInactiveTrackColor))); - - // Test colors for discrete slider with inactiveColor and activeColor set. - await tester.pumpWidget(buildApp( - activeColor: customColor1, - inactiveColor: customColor2, - divisions: 3, - )); - expect(material, paints..rect(color: customColor1)..rect(color: customColor2)); - expect( - material, - paints - ..circle(color: customColor2) - ..circle(color: customColor2) - ..circle(color: customColor1) - ..circle(color: customColor1) - ..circle(color: customColor1)); - expect(material, isNot(paints..circle(color: sliderTheme.thumbColor))); - expect(material, isNot(paints..circle(color: sliderTheme.disabledThumbColor))); - expect(material, isNot(paints..rect(color: sliderTheme.disabledActiveTrackColor))); - expect(material, isNot(paints..rect(color: sliderTheme.disabledInactiveTrackColor))); - expect(material, isNot(paints..circle(color: sliderTheme.activeTickMarkColor))); - expect(material, isNot(paints..circle(color: sliderTheme.inactiveTickMarkColor))); - - // Test default theme for disabled widget. - await tester.pumpWidget(buildApp(enabled: false)); - await tester.pumpAndSettle(); - expect( - material, - paints - ..rect(color: sliderTheme.disabledActiveTrackColor) - ..rect(color: sliderTheme.disabledInactiveTrackColor)); - expect(material, paints..circle(color: sliderTheme.disabledThumbColor)); - expect(material, isNot(paints..circle(color: sliderTheme.thumbColor))); - expect(material, isNot(paints..rect(color: sliderTheme.activeTrackColor))); - expect(material, isNot(paints..rect(color: sliderTheme.inactiveTrackColor))); - - // Test setting the activeColor and inactiveColor for disabled widget. - await tester.pumpWidget(buildApp(activeColor: customColor1, inactiveColor: customColor2, enabled: false)); - expect( - material, - paints - ..rect(color: sliderTheme.disabledActiveTrackColor) - ..rect(color: sliderTheme.disabledInactiveTrackColor)); - expect(material, paints..circle(color: sliderTheme.disabledThumbColor)); - expect(material, isNot(paints..circle(color: sliderTheme.thumbColor))); - expect(material, isNot(paints..rect(color: sliderTheme.activeTrackColor))); - expect(material, isNot(paints..rect(color: sliderTheme.inactiveTrackColor))); - - // Test that the default value indicator has the right colors. - await tester.pumpWidget(buildApp(divisions: 3)); - Offset center = tester.getCenter(find.byType(Slider)); - TestGesture gesture = await tester.startGesture(center); - // Wait for value indicator animation to finish. - await tester.pumpAndSettle(); - expect(value, equals(2.0 / 3.0)); - expect( - material, - paints - ..rect(color: sliderTheme.activeTrackColor) - ..rect(color: sliderTheme.inactiveTrackColor) - ..circle(color: sliderTheme.overlayColor) - ..circle(color: sliderTheme.activeTickMarkColor) - ..circle(color: sliderTheme.activeTickMarkColor) - ..circle(color: sliderTheme.inactiveTickMarkColor) - ..circle(color: sliderTheme.inactiveTickMarkColor) - ..circle(color: sliderTheme.thumbColor), - ); - expect(valueIndicatorBox, paints..path(color: sliderTheme.valueIndicatorColor)); - await gesture.up(); - // Wait for value indicator animation to finish. - await tester.pumpAndSettle(); - - // Testing the custom colors are used for the indicator. - await tester.pumpWidget(buildApp( - divisions: 3, - activeColor: customColor1, - inactiveColor: customColor2, - )); - center = tester.getCenter(find.byType(Slider)); - gesture = await tester.startGesture(center); - // Wait for value indicator animation to finish. - await tester.pumpAndSettle(); - expect(value, equals(2.0 / 3.0)); - expect( - material, - paints - ..rect(color: customColor1) // active track - ..rect(color: customColor2) // inactive track - ..circle(color: customColor1.withOpacity(0.12)) // overlay - ..circle(color: customColor2) // 1st tick mark - ..circle(color: customColor2) // 2nd tick mark - ..circle(color: customColor2) // 3rd tick mark - ..circle(color: customColor1) // 4th tick mark - ..circle(color: customColor1) // thumb, - ); - expect(valueIndicatorBox, paints..path(color: customColor1)); - await gesture.up(); - }); - testWidgets('Slider can tap in vertical scroller', (WidgetTester tester) async { double value = 0.0; await tester.pumpWidget( @@ -1138,12 +922,12 @@ void main() { child: MediaQuery( data: MediaQueryData.fromWindow(window), child: const Material( - child: Center( - child: Slider( - value: 0.5, - onChanged: null, - ), + child: Center( + child: Slider( + value: 0.5, + onChanged: null, ), + ), ), ), ), @@ -1198,7 +982,7 @@ void main() { expect(tester.renderObject(find.byType(Slider)).size, const Size(144.0 + 2.0 * 24.0, 48.0)); }); - testWidgets('Slider V2 respects textScaleFactor', (WidgetTester tester) async { + testWidgets('Slider respects textScaleFactor', (WidgetTester tester) async { final Key sliderKey = UniqueKey(); double value = 0.0; @@ -1235,8 +1019,6 @@ void main() { value = newValue; }); }, - // ignore: deprecated_member_use_from_same_package - useV2Slider: true, ), ), ), @@ -1329,123 +1111,22 @@ void main() { await tester.pumpAndSettle(); expect( - tester.firstRenderObject(find.byType(Overlay)), - paints - ..path( - includes: const [ - Offset(0.0, 0.0), - Offset(0.0, -52.0), - Offset(-44.0, -16.0), - Offset(44.0, -16.0), - ], - color: const Color(0xf55f5f5f), - ), + tester.firstRenderObject(find.byType(Overlay)), + paints + ..path( + includes: const [ + Offset(0.0, 0.0), + Offset(0.0, -52.0), + Offset(-44.0, -16.0), + Offset(44.0, -16.0), + ], + color: const Color(0xf55f5f5f), + ), ); await gesture.up(); await tester.pumpAndSettle(); - }); - - testWidgets('Slider respects textScaleFactor', (WidgetTester tester) async { - final Key sliderKey = UniqueKey(); - double value = 0.0; - - Widget buildSlider({ - double textScaleFactor, - bool isDiscrete = true, - ShowValueIndicator show = ShowValueIndicator.onlyForDiscrete, - }) { - return MaterialApp( - home: Directionality( - textDirection: TextDirection.ltr, - child: StatefulBuilder( - builder: (BuildContext context, StateSetter setState) { - return MediaQuery( - data: MediaQueryData(textScaleFactor: textScaleFactor), - child: Material( - child: Theme( - data: Theme.of(context).copyWith( - sliderTheme: Theme.of(context).sliderTheme.copyWith(showValueIndicator: show), - ), - child: Center( - child: OverflowBox( - maxWidth: double.infinity, - maxHeight: double.infinity, - child: Slider( - // ignore: deprecated_member_use_from_same_package - useV2Slider: false, - key: sliderKey, - min: 0.0, - max: 100.0, - divisions: isDiscrete ? 10 : null, - label: '${value.round()}', - value: value, - onChanged: (double newValue) { - setState(() { - value = newValue; - }); - }, - ), - ), - ), - ), - ), - ); - }, - ), - ), - ); - } - - await tester.pumpWidget(buildSlider(textScaleFactor: 1.0)); - Offset center = tester.getCenter(find.byType(Slider)); - TestGesture gesture = await tester.startGesture(center); - await tester.pumpAndSettle(); - - expect(tester.firstRenderObject(find.byType(Overlay)), paints..scale(x: 1.0, y: 1.0)); - - await gesture.up(); - await tester.pumpAndSettle(); - - await tester.pumpWidget(buildSlider(textScaleFactor: 2.0)); - center = tester.getCenter(find.byType(Slider)); - gesture = await tester.startGesture(center); - await tester.pumpAndSettle(); - - expect(tester.firstRenderObject(find.byType(Overlay)), paints..scale(x: 2.0, y: 2.0)); - - await gesture.up(); - await tester.pumpAndSettle(); - - // Check continuous - await tester.pumpWidget(buildSlider( - textScaleFactor: 1.0, - isDiscrete: false, - show: ShowValueIndicator.onlyForContinuous, - )); - center = tester.getCenter(find.byType(Slider)); - gesture = await tester.startGesture(center); - await tester.pumpAndSettle(); - - expect(tester.firstRenderObject(find.byType(Overlay)), paints..scale(x: 1.0, y: 1.0)); - - await gesture.up(); - await tester.pumpAndSettle(); - - await tester.pumpWidget(buildSlider( - textScaleFactor: 2.0, - isDiscrete: false, - show: ShowValueIndicator.onlyForContinuous, - )); - center = tester.getCenter(find.byType(Slider)); - gesture = await tester.startGesture(center); - await tester.pumpAndSettle(); - - expect(tester.firstRenderObject(find.byType(Overlay)), paints..scale(x: 2.0, y: 2.0)); - - await gesture.up(); - await tester.pumpAndSettle(); - }); + }, skip: isBrowser); testWidgets('Tick marks are skipped when they are too dense', (WidgetTester tester) async { Widget buildSlider({ @@ -1498,140 +1179,6 @@ void main() { expect(material, paintsExactlyCountTimes(#drawCircle, 1)); }); - testWidgets('Slider V2 has correct animations when reparented', (WidgetTester tester) async { - final Key sliderKey = GlobalKey(debugLabel: 'A'); - double value = 0.0; - - Widget buildSlider(int parents) { - Widget createParents(int parents, StateSetter setState) { - Widget slider = Slider( - key: sliderKey, - value: value, - divisions: 4, - onChanged: (double newValue) { - setState(() { - value = newValue; - }); - }, - // ignore: deprecated_member_use_from_same_package - useV2Slider: true, - ); - - for (int i = 0; i < parents; ++i) { - slider = Column(children: [slider]); - } - return slider; - } - - return MaterialApp( - home: Directionality( - textDirection: TextDirection.ltr, - child: StatefulBuilder( - builder: (BuildContext context, StateSetter setState) { - return MediaQuery( - data: MediaQueryData.fromWindow(window), - child: Material( - child: createParents(parents, setState), - ), - ); - }, - ), - ), - ); - } - - Future testReparenting(bool reparent) async { - final RenderBox sliderBox = tester.firstRenderObject(find.byType(Slider)); - final Offset center = tester.getCenter(find.byType(Slider)); - // Move to 0.0. - TestGesture gesture = await tester.startGesture(Offset.zero); - await tester.pump(); - await gesture.up(); - await tester.pumpAndSettle(); - expect(SchedulerBinding.instance.transientCallbackCount, equals(0)); - expect( - sliderBox, - paints - ..circle(x: 26.0, y: 24.0, radius: 1.0) - ..circle(x: 213.0, y: 24.0, radius: 1.0) - ..circle(x: 400.0, y: 24.0, radius: 1.0) - ..circle(x: 587.0, y: 24.0, radius: 1.0) - ..circle(x: 774.0, y: 24.0, radius: 1.0) - ..circle(x: 24.0, y: 24.0, radius: 10.0), - ); - - gesture = await tester.startGesture(center); - await tester.pump(); - // Wait for animations to start. - await tester.pump(const Duration(milliseconds: 25)); - expect(SchedulerBinding.instance.transientCallbackCount, equals(2)); - expect( - sliderBox, - paints - ..circle(x: 111.20703125, y: 24.0, radius: 5.687664985656738) - ..circle(x: 26.0, y: 24.0, radius: 1.0) - ..circle(x: 213.0, y: 24.0, radius: 1.0) - ..circle(x: 400.0, y: 24.0, radius: 1.0) - ..circle(x: 587.0, y: 24.0, radius: 1.0) - ..circle(x: 774.0, y: 24.0, radius: 1.0) - ..circle(x: 111.20703125, y: 24.0, radius: 10.0), - ); - - // Reparenting in the middle of an animation should do nothing. - if (reparent) { - await tester.pumpWidget(buildSlider(2)); - } - - // Move a little further in the animations. - await tester.pump(const Duration(milliseconds: 10)); - expect(SchedulerBinding.instance.transientCallbackCount, equals(2)); - expect( - sliderBox, - paints - ..circle(x: 190.0135726928711, y: 24.0, radius: 12.0) - ..circle(x: 26.0, y: 24.0, radius: 1.0) - ..circle(x: 213.0, y: 24.0, radius: 1.0) - ..circle(x: 400.0, y: 24.0, radius: 1.0) - ..circle(x: 587.0, y: 24.0, radius: 1.0) - ..circle(x: 774.0, y: 24.0, radius: 1.0) - ..circle(x: 190.0135726928711, y: 24.0, radius: 10.0), - ); - // Wait for animations to finish. - await tester.pumpAndSettle(); - expect(SchedulerBinding.instance.transientCallbackCount, equals(0)); - expect( - sliderBox, - paints - ..circle(x: 400.0, y: 24.0, radius: 24.0) - ..circle(x: 26.0, y: 24.0, radius: 1.0) - ..circle(x: 213.0, y: 24.0, radius: 1.0) - ..circle(x: 400.0, y: 24.0, radius: 1.0) - ..circle(x: 587.0, y: 24.0, radius: 1.0) - ..circle(x: 774.0, y: 24.0, radius: 1.0) - ..circle(x: 400.0, y: 24.0, radius: 10.0), - ); - await gesture.up(); - await tester.pumpAndSettle(); - expect(SchedulerBinding.instance.transientCallbackCount, equals(0)); - expect( - sliderBox, - paints - ..circle(x: 26.0, y: 24.0, radius: 1.0) - ..circle(x: 213.0, y: 24.0, radius: 1.0) - ..circle(x: 400.0, y: 24.0, radius: 1.0) - ..circle(x: 587.0, y: 24.0, radius: 1.0) - ..circle(x: 774.0, y: 24.0, radius: 1.0) - ..circle(x: 400.0, y: 24.0, radius: 10.0), - ); - } - - await tester.pumpWidget(buildSlider(1)); - // Do it once without reparenting in the middle of an animation - await testReparenting(false); - // Now do it again with reparenting in the middle of an animation. - await testReparenting(true); - }); - testWidgets('Slider has correct animations when reparented', (WidgetTester tester) async { final Key sliderKey = GlobalKey(debugLabel: 'A'); double value = 0.0; @@ -1639,8 +1186,6 @@ void main() { Widget buildSlider(int parents) { Widget createParents(int parents, StateSetter setState) { Widget slider = Slider( - // ignore: deprecated_member_use_from_same_package - useV2Slider: false, key: sliderKey, value: value, divisions: 4, @@ -1686,11 +1231,11 @@ void main() { expect( material, paints - ..circle(x: 25.0, y: 24.0, radius: 1.0) - ..circle(x: 212.5, y: 24.0, radius: 1.0) + ..circle(x: 26.0, y: 24.0, radius: 1.0) + ..circle(x: 213.0, y: 24.0, radius: 1.0) ..circle(x: 400.0, y: 24.0, radius: 1.0) - ..circle(x: 587.5, y: 24.0, radius: 1.0) - ..circle(x: 775.0, y: 24.0, radius: 1.0) + ..circle(x: 587.0, y: 24.0, radius: 1.0) + ..circle(x: 774.0, y: 24.0, radius: 1.0) ..circle(x: 24.0, y: 24.0, radius: 10.0), ); @@ -1703,11 +1248,11 @@ void main() { material, paints ..circle(x: 111.20703125, y: 24.0, radius: 5.687664985656738) - ..circle(x: 25.0, y: 24.0, radius: 1.0) - ..circle(x: 212.5, y: 24.0, radius: 1.0) + ..circle(x: 26.0, y: 24.0, radius: 1.0) + ..circle(x: 213.0, y: 24.0, radius: 1.0) ..circle(x: 400.0, y: 24.0, radius: 1.0) - ..circle(x: 587.5, y: 24.0, radius: 1.0) - ..circle(x: 775.0, y: 24.0, radius: 1.0) + ..circle(x: 587.0, y: 24.0, radius: 1.0) + ..circle(x: 774.0, y: 24.0, radius: 1.0) ..circle(x: 111.20703125, y: 24.0, radius: 10.0), ); @@ -1723,11 +1268,11 @@ void main() { material, paints ..circle(x: 190.0135726928711, y: 24.0, radius: 12.0) - ..circle(x: 25.0, y: 24.0, radius: 1.0) - ..circle(x: 212.5, y: 24.0, radius: 1.0) + ..circle(x: 26.0, y: 24.0, radius: 1.0) + ..circle(x: 213.0, y: 24.0, radius: 1.0) ..circle(x: 400.0, y: 24.0, radius: 1.0) - ..circle(x: 587.5, y: 24.0, radius: 1.0) - ..circle(x: 775.0, y: 24.0, radius: 1.0) + ..circle(x: 587.0, y: 24.0, radius: 1.0) + ..circle(x: 774.0, y: 24.0, radius: 1.0) ..circle(x: 190.0135726928711, y: 24.0, radius: 10.0), ); // Wait for animations to finish. @@ -1737,11 +1282,11 @@ void main() { material, paints ..circle(x: 400.0, y: 24.0, radius: 24.0) - ..circle(x: 25.0, y: 24.0, radius: 1.0) - ..circle(x: 212.5, y: 24.0, radius: 1.0) + ..circle(x: 26.0, y: 24.0, radius: 1.0) + ..circle(x: 213.0, y: 24.0, radius: 1.0) ..circle(x: 400.0, y: 24.0, radius: 1.0) - ..circle(x: 587.5, y: 24.0, radius: 1.0) - ..circle(x: 775.0, y: 24.0, radius: 1.0) + ..circle(x: 587.0, y: 24.0, radius: 1.0) + ..circle(x: 774.0, y: 24.0, radius: 1.0) ..circle(x: 400.0, y: 24.0, radius: 10.0), ); await gesture.up(); @@ -1750,11 +1295,11 @@ void main() { expect( material, paints - ..circle(x: 25.0, y: 24.0, radius: 1.0) - ..circle(x: 212.5, y: 24.0, radius: 1.0) + ..circle(x: 26.0, y: 24.0, radius: 1.0) + ..circle(x: 213.0, y: 24.0, radius: 1.0) ..circle(x: 400.0, y: 24.0, radius: 1.0) - ..circle(x: 587.5, y: 24.0, radius: 1.0) - ..circle(x: 775.0, y: 24.0, radius: 1.0) + ..circle(x: 587.0, y: 24.0, radius: 1.0) + ..circle(x: 774.0, y: 24.0, radius: 1.0) ..circle(x: 400.0, y: 24.0, radius: 10.0), ); } @@ -1874,25 +1419,25 @@ void main() { final SemanticsTester semantics = SemanticsTester(tester); await tester.pumpWidget( - MaterialApp( - home: Theme( - data: ThemeData.light(), - child: Directionality( - textDirection: TextDirection.ltr, - child: MediaQuery( - data: MediaQueryData.fromWindow(window), - child: Material( - child: Slider( - value: 100.0, - min: 0.0, - max: 200.0, - onChanged: (double v) { }, + MaterialApp( + home: Theme( + data: ThemeData.light(), + child: Directionality( + textDirection: TextDirection.ltr, + child: MediaQuery( + data: MediaQueryData.fromWindow(window), + child: Material( + child: Slider( + value: 100.0, + min: 0.0, + max: 200.0, + onChanged: (double v) { }, + ), ), ), ), ), - ), - ) + ) ); expect( @@ -2505,8 +2050,6 @@ void main() { final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); const Slider( - // ignore: deprecated_member_use_from_same_package - useV2Slider: false, activeColor: Colors.blue, divisions: 10, inactiveColor: Colors.grey, @@ -2533,7 +2076,6 @@ void main() { 'label: "Set a value"', 'activeColor: MaterialColor(primary value: Color(0xff2196f3))', 'inactiveColor: MaterialColor(primary value: Color(0xff9e9e9e))', - 'useV1Slider', ]); }); } diff --git a/packages/flutter/test/material/slider_theme_test.dart b/packages/flutter/test/material/slider_theme_test.dart index 452e53d6de..7a2e26f9b0 100644 --- a/packages/flutter/test/material/slider_theme_test.dart +++ b/packages/flutter/test/material/slider_theme_test.dart @@ -94,54 +94,18 @@ void main() { ]); }); - testWidgets('Slider V2 uses ThemeData slider theme if present', (WidgetTester tester) async { - final ThemeData theme = ThemeData( - platform: TargetPlatform.android, - primarySwatch: Colors.red, - ); - final SliderThemeData sliderTheme = theme.sliderTheme; - - await tester.pumpWidget(_buildApp(sliderTheme, value: 0.5, enabled: false, useV2Slider: true)); - final RenderBox sliderBox = tester.firstRenderObject(find.byType(Slider)); - - expect( - sliderBox, - paints - ..rrect(color: sliderTheme.disabledActiveTrackColor) - ..rrect(color: sliderTheme.disabledInactiveTrackColor), - ); - }); - testWidgets('Slider uses ThemeData slider theme if present', (WidgetTester tester) async { final ThemeData theme = ThemeData( platform: TargetPlatform.android, primarySwatch: Colors.red, ); final SliderThemeData sliderTheme = theme.sliderTheme; - - await tester.pumpWidget(_buildApp(sliderTheme, value: 0.5, enabled: false)); - final MaterialInkController material = Material.of(tester.element(find.byType(Slider))); - - expect( - material, - paints - ..rect(color: sliderTheme.disabledActiveTrackColor) - ..rect(color: sliderTheme.disabledInactiveTrackColor), - ); - }); - - testWidgets('Slider V2 overrides ThemeData theme if SliderTheme present', (WidgetTester tester) async { - final ThemeData theme = ThemeData( - platform: TargetPlatform.android, - primarySwatch: Colors.red, - ); - final SliderThemeData sliderTheme = theme.sliderTheme; final SliderThemeData customTheme = sliderTheme.copyWith( activeTrackColor: Colors.purple, inactiveTrackColor: Colors.purple.withAlpha(0x3d), ); - await tester.pumpWidget(_buildApp(sliderTheme, value: 0.5, enabled: false, useV2Slider: true)); + await tester.pumpWidget(_buildApp(sliderTheme, value: 0.5, enabled: false)); final MaterialInkController material = Material.of(tester.element(find.byType(Slider))); expect( @@ -169,8 +133,8 @@ void main() { expect( material, paints - ..rect(color: customTheme.disabledActiveTrackColor) - ..rect(color: customTheme.disabledInactiveTrackColor), + ..rrect(color: customTheme.disabledActiveTrackColor) + ..rrect(color: customTheme.disabledInactiveTrackColor), ); }); @@ -258,14 +222,14 @@ void main() { expect(lerp.valueIndicatorTextStyle.color, equals(middleGrey.withAlpha(0xff))); }); - testWidgets('Slider V2 track draws correctly', (WidgetTester tester) async { + testWidgets('Default slider track draws correctly', (WidgetTester tester) async { final ThemeData theme = ThemeData( platform: TargetPlatform.android, primarySwatch: Colors.blue, ); final SliderThemeData sliderTheme = theme.sliderTheme.copyWith(thumbColor: Colors.red.shade500); - await tester.pumpWidget(_buildApp(sliderTheme, value: 0.25, useV2Slider: true)); + await tester.pumpWidget(_buildApp(sliderTheme, value: 0.25)); final MaterialInkController material = Material.of(tester.element(find.byType(Slider))); const Radius radius = Radius.circular(2); @@ -280,7 +244,7 @@ void main() { ..rrect(rrect: RRect.fromLTRBAndCorners(212.0, 298.0, 776.0, 302.0, topRight: radius, bottomRight: radius), color: sliderTheme.inactiveTrackColor), ); - await tester.pumpWidget(_buildApp(sliderTheme, value: 0.25, enabled: false, useV2Slider: true)); + await tester.pumpWidget(_buildApp(sliderTheme, value: 0.25, enabled: false)); await tester.pumpAndSettle(); // wait for disable animation // The disabled slider thumb is the same size as the enabled thumb. @@ -292,37 +256,6 @@ void main() { ); }); - testWidgets('Default slider track draws correctly', (WidgetTester tester) async { - final ThemeData theme = ThemeData( - platform: TargetPlatform.android, - primarySwatch: Colors.blue, - ); - final SliderThemeData sliderTheme = theme.sliderTheme.copyWith(thumbColor: Colors.red.shade500); - - await tester.pumpWidget(_buildApp(sliderTheme, value: 0.25)); - final MaterialInkController material = Material.of(tester.element(find.byType(Slider))); - - // The enabled slider thumb has track segments that extend to and from - // the center of the thumb. - expect( - material, - paints - ..rect(rect: const Rect.fromLTRB(25.0, 299.0, 202.0, 301.0), color: sliderTheme.activeTrackColor) - ..rect(rect: const Rect.fromLTRB(222.0, 299.0, 776.0, 301.0), color: sliderTheme.inactiveTrackColor), - ); - - await tester.pumpWidget(_buildApp(sliderTheme, value: 0.25, enabled: false)); - await tester.pumpAndSettle(); // wait for disable animation - - // The disabled slider thumb is the same size as the enabled thumb. - expect( - material, - paints - ..rect(rect: const Rect.fromLTRB(25.0, 299.0, 202.0, 301.0), color: sliderTheme.disabledActiveTrackColor) - ..rect(rect: const Rect.fromLTRB(222.0, 299.0, 776.0, 301.0), color: sliderTheme.disabledInactiveTrackColor), - ); - }); - testWidgets('Default slider overlay draws correctly', (WidgetTester tester) async { final ThemeData theme = ThemeData( platform: TargetPlatform.android, @@ -428,7 +361,7 @@ void main() { ); }); - testWidgets('Slider V2 value indicator shape draws correctly', (WidgetTester tester) async { + testWidgets('Default paddle slider value indicator shape draws correctly', (WidgetTester tester) async { final ThemeData theme = ThemeData( platform: TargetPlatform.android, primarySwatch: Colors.blue, @@ -436,6 +369,7 @@ void main() { final SliderThemeData sliderTheme = theme.sliderTheme.copyWith( thumbColor: Colors.red.shade500, showValueIndicator: ShowValueIndicator.always, + valueIndicatorShape: const PaddleSliderValueIndicatorShape(), ); Widget buildApp(String value, { double sliderValue = 0.5, double textScale = 1.0 }) { return MaterialApp( @@ -454,8 +388,6 @@ void main() { label: value, divisions: 3, onChanged: (double d) { }, - // ignore: deprecated_member_use_from_same_package - useV2Slider: true, ), ), ), @@ -479,13 +411,13 @@ void main() { valueIndicatorBox, paints ..path( - includes: const [ - Offset(0.0, 0.0), - Offset(-20.0, -12.0), - Offset(20.0, -34.0), - Offset(0.0, -38.0), + color: sliderTheme.valueIndicatorColor, + includes: [ + const Offset(0.0, -40.0), + const Offset(15.9, -40.0), + const Offset(-15.9, -40.0), ], - color: const Color(0xf55f5f5f), + excludes: [const Offset(16.1, -40.0), const Offset(-16.1, -40.0)], ), ); @@ -500,16 +432,14 @@ void main() { expect( valueIndicatorBox, paints - ..rrect() - ..rrect() ..path( - includes: const [ - Offset(0.0, 0.0), - Offset(-30.0, -12.0), - Offset(30.0, -34.0), - Offset(0.0, -38.0), + color: sliderTheme.valueIndicatorColor, + includes: [ + const Offset(0.0, -40.0), + const Offset(35.9, -40.0), + const Offset(-35.9, -40.0), ], - color: const Color(0xf55f5f5f), + excludes: [const Offset(36.1, -40.0), const Offset(-36.1, -40.0)], ), ); await gesture.up(); @@ -523,17 +453,15 @@ void main() { expect( valueIndicatorBox, paints - ..rrect() - ..rrect() ..path( - includes: const [ - Offset(0.0, 0.0), - Offset(-12.0, -12.0), - Offset(110.0, -34.0), - Offset(0.0, -38.0), + color: sliderTheme.valueIndicatorColor, + includes: [ + const Offset(0.0, -40.0), + const Offset(92.0, -40.0), + const Offset(-16.0, -40.0), ], - color: const Color(0xf55f5f5f), - ) + excludes: [const Offset(98.1, -40.0), const Offset(-20.1, -40.0)], + ), ); await gesture.up(); @@ -546,21 +474,19 @@ void main() { expect( valueIndicatorBox, paints - ..rrect() - ..rrect() ..path( - includes: const [ - Offset(0.0, 0.0), - Offset(-110.0, -12.0), - Offset(12.0, -34.0), - Offset(0.0, -38.0), + color: sliderTheme.valueIndicatorColor, + includes: [ + const Offset(0.0, -40.0), + const Offset(16.0, -40.0), + const Offset(-92.0, -40.0), ], - color: const Color(0xf55f5f5f), - ) + excludes: [const Offset(20.1, -40.0), const Offset(-98.1, -40.0)], + ), ); await gesture.up(); - // Test that the box decreases in height when the text scale gets smaller. + // Test that the neck stretches when the text scale gets smaller. await tester.pumpWidget(buildApp('1000000', sliderValue: 0.0, textScale: 0.5)); center = tester.getCenter(find.byType(Slider)); gesture = await tester.startGesture(center); @@ -569,25 +495,25 @@ void main() { expect( valueIndicatorBox, paints - ..rrect() - ..rrect() ..path( - includes: const [ - Offset(0.0, 0.0), - Offset(-12.0, -12.0), - Offset(61.0, -16.0), - Offset(0.0, -20.0), + color: sliderTheme.valueIndicatorColor, + includes: [ + const Offset(0.0, -49.0), + const Offset(68.0, -49.0), + const Offset(-24.0, -49.0), ], - excludes: const [ - Offset(0.0, -38.0) + excludes: [ + const Offset(98.0, -32.0), // inside full size, outside small + const Offset(-40.0, -32.0), // inside full size, outside small + const Offset(90.1, -49.0), + const Offset(-40.1, -49.0), ], - color: const Color(0xf55f5f5f), - ) + ), ); await gesture.up(); - // Test that the box increases in height when the text scale gets bigger. - await tester.pumpWidget(buildApp('1000000', sliderValue: 0.0, textScale: 2.0)); + // Test that the neck shrinks when the text scale gets larger. + await tester.pumpWidget(buildApp('1000000', sliderValue: 0.0, textScale: 2.5)); center = tester.getCenter(find.byType(Slider)); gesture = await tester.startGesture(center); // Wait for value indicator animation to finish. @@ -595,17 +521,19 @@ void main() { expect( valueIndicatorBox, paints - ..rrect() - ..rrect() ..path( - includes: const [ - Offset(0.0, 0.0), - Offset(-12.0, -16.0), - Offset(208.0, -40.0), - Offset(0.0, -50.0), + color: sliderTheme.valueIndicatorColor, + includes: [ + const Offset(0.0, -38.8), + const Offset(92.0, -38.8), + const Offset(8.0, -23.0), // Inside large, outside scale=1.0 + const Offset(-2.0, -23.0), // Inside large, outside scale=1.0 ], - color: const Color(0xf55f5f5f), - ) + excludes: [ + const Offset(98.5, -38.8), + const Offset(-16.1, -38.8), + ], + ), ); await gesture.up(); }); @@ -789,38 +717,10 @@ void main() { testWidgets('The slider track height can be overridden', (WidgetTester tester) async { final SliderThemeData sliderTheme = ThemeData().sliderTheme.copyWith(trackHeight: 16); - - await tester.pumpWidget(_buildApp(sliderTheme, value: 0.25)); - - final MaterialInkController material = Material.of(tester.element(find.byType(Slider))); - - // Top and bottom are centerY (300) + and - trackRadius (8). - expect( - material, - paints - ..rect(rect: const Rect.fromLTRB(32.0, 292.0, 202.0, 308.0), color: sliderTheme.activeTrackColor) - ..rect(rect: const Rect.fromLTRB(222.0, 292.0, 776.0, 308.0), color: sliderTheme.inactiveTrackColor), - ); - - await tester.pumpWidget(_buildApp(sliderTheme, value: 0.25, enabled: false)); - await tester.pumpAndSettle(); // wait for disable animation - - // The disabled thumb is smaller so the active track has to paint longer to - // get to the edge. - expect( - material, - paints - ..rect(rect: const Rect.fromLTRB(32.0, 292.0, 202.0, 308.0), color: sliderTheme.disabledActiveTrackColor) - ..rect(rect: const Rect.fromLTRB(222.0, 292.0, 776.0, 308.0), color: sliderTheme.disabledInactiveTrackColor), - ); - }); - - testWidgets('The slider V2 track height can be overridden', (WidgetTester tester) async { - final SliderThemeData sliderTheme = ThemeData().sliderTheme.copyWith(trackHeight: 16); const Radius radius = Radius.circular(8); const Radius activatedRadius = Radius.circular(9); - await tester.pumpWidget(_buildApp(sliderTheme, value: 0.25, useV2Slider: true)); + await tester.pumpWidget(_buildApp(sliderTheme, value: 0.25)); final MaterialInkController material = Material.of(tester.element(find.byType(Slider))); @@ -832,7 +732,7 @@ void main() { ..rrect(rrect: RRect.fromLTRBAndCorners(212.0, 292.0, 776.0, 308.0, topRight: radius, bottomRight: radius), color: sliderTheme.inactiveTrackColor), ); - await tester.pumpWidget(_buildApp(sliderTheme, value: 0.25, enabled: false, useV2Slider: true)); + await tester.pumpWidget(_buildApp(sliderTheme, value: 0.25, enabled: false)); await tester.pumpAndSettle(); // wait for disable animation // The disabled thumb is smaller so the active track has to paint longer to @@ -847,10 +747,10 @@ void main() { testWidgets('The default slider thumb shape sizes can be overridden', (WidgetTester tester) async { final SliderThemeData sliderTheme = ThemeData().sliderTheme.copyWith( - thumbShape: const RoundSliderThumbShape( - enabledThumbRadius: 7, - disabledThumbRadius: 11, - ), + thumbShape: const RoundSliderThumbShape( + enabledThumbRadius: 7, + disabledThumbRadius: 11, + ), ); await tester.pumpWidget(_buildApp(sliderTheme, value: 0.25)); @@ -906,39 +806,6 @@ void main() { final MaterialInkController material = Material.of(tester.element(find.byType(Slider))); - expect( - material, - paints - ..circle(x: 29, y: 300, radius: 5, color: sliderTheme.activeTickMarkColor) - ..circle(x: 400, y: 300, radius: 5, color: sliderTheme.activeTickMarkColor) - ..circle(x: 771, y: 300, radius: 5, color: sliderTheme.inactiveTickMarkColor), - ); - - await tester.pumpWidget(_buildApp(sliderTheme, value: 0.5, divisions: 2, enabled: false)); - await tester.pumpAndSettle(); - - expect( - material, - paints - ..circle(x: 29, y: 300, radius: 5, color: sliderTheme.disabledActiveTickMarkColor) - ..circle(x: 400, y: 300, radius: 5, color: sliderTheme.disabledActiveTickMarkColor) - ..circle(x: 771, y: 300, radius: 5, color: sliderTheme.disabledInactiveTickMarkColor), - ); - }); - - testWidgets('The default slider V2 tick mark shape size can be overridden', (WidgetTester tester) async { - final SliderThemeData sliderTheme = ThemeData().sliderTheme.copyWith( - tickMarkShape: const RoundSliderTickMarkShape(tickMarkRadius: 5, useV2Slider: true), - activeTickMarkColor: const Color(0xfadedead), - inactiveTickMarkColor: const Color(0xfadebeef), - disabledActiveTickMarkColor: const Color(0xfadecafe), - disabledInactiveTickMarkColor: const Color(0xfadeface), - ); - - await tester.pumpWidget(_buildApp(sliderTheme, value: 0.5, divisions: 2, useV2Slider: true)); - - final MaterialInkController material = Material.of(tester.element(find.byType(Slider))); - expect( material, paints @@ -947,7 +814,7 @@ void main() { ..circle(x: 774, y: 300, radius: 5, color: sliderTheme.inactiveTickMarkColor), ); - await tester.pumpWidget(_buildApp(sliderTheme, value: 0.5, divisions: 2, enabled: false, useV2Slider: true)); + await tester.pumpWidget(_buildApp(sliderTheme, value: 0.5, divisions: 2, enabled: false)); await tester.pumpAndSettle(); expect( @@ -1029,7 +896,7 @@ void main() { final MaterialInkController material = Material.of(tester.element(find.byType(Slider))); // Only 2 track segments. - expect(material, paintsExactlyCountTimes(#drawRect, 2)); + expect(material, paintsExactlyCountTimes(#drawRRect, 2)); expect(material, paintsExactlyCountTimes(#drawCircle, 0)); expect(material, paintsExactlyCountTimes(#drawPath, 0)); }); @@ -1203,6 +1070,55 @@ void main() { await gesture.up(); }); + + testWidgets('Default paddle range slider value indicator shape draws correctly', (WidgetTester tester) async { + final ThemeData theme = ThemeData( + platform: TargetPlatform.android, + primarySwatch: Colors.blue, + ); + final SliderThemeData sliderTheme = theme.sliderTheme.copyWith( + thumbColor: Colors.red.shade500, + showValueIndicator: ShowValueIndicator.always, + rangeValueIndicatorShape: const PaddleRangeSliderValueIndicatorShape(), + ); + + await tester.pumpWidget(_buildRangeApp(sliderTheme)); + + final RenderBox valueIndicatorBox = tester.firstRenderObject(find.byType(Overlay)); + + final Offset center = tester.getCenter(find.byType(RangeSlider)); + final TestGesture gesture = await tester.startGesture(center); + // Wait for value indicator animation to finish. + await tester.pumpAndSettle(); + expect( + valueIndicatorBox, + paints + ..rrect(rrect: RRect.fromLTRBAndCorners( + 24.0, 298.0, 24.0, 302.0, + topLeft: const Radius.circular(2.0), + topRight: const Radius.circular(0.0), + bottomRight: const Radius.circular(0.0), + bottomLeft: const Radius.circular(2.0), + )) + ..rect(rect: const Rect.fromLTRB(24.0, 297.0, 24.0, 303.0)) + ..rrect(rrect: RRect.fromLTRBAndCorners( + 24.0, 298.0, 776.0, 302.0, + topLeft: const Radius.circular(0.0), + topRight: const Radius.circular(2.0), + bottomRight: const Radius.circular(2.0), + bottomLeft: const Radius.circular(0.0), + )) + ..circle(x: 24.0, y: 300.0) + ..shadow(elevation: 1.0) + ..circle(x: 24.0, y: 300.0) + ..shadow(elevation: 6.0) + ..circle(x: 24.0, y: 300.0) + ); + + await gesture.up(); + + }); + testWidgets('PaddleRangeSliderValueIndicatorShape skips all painting at zero scale', (WidgetTester tester) async { // Pump a slider with just a value indicator. await tester.pumpWidget(_buildRangeApp( @@ -1265,12 +1181,11 @@ void main() { } Widget _buildApp( - SliderThemeData sliderTheme, { - double value = 0.0, - bool enabled = true, - int divisions, - bool useV2Slider = false, -}) { + SliderThemeData sliderTheme, { + double value = 0.0, + bool enabled = true, + int divisions, + }) { final ValueChanged onChanged = enabled ? (double d) => value = d : null; return MaterialApp( home: Scaffold( @@ -1282,8 +1197,6 @@ Widget _buildApp( label: '$value', onChanged: onChanged, divisions: divisions, - // ignore: deprecated_member_use_from_same_package - useV2Slider: useV2Slider ), ), ),