Unverified Commit 0549ab23 authored by Jose Alba's avatar Jose Alba Committed by GitHub

Removed useV2 Slider flag (#55857)

parent 368da5bb
...@@ -132,12 +132,6 @@ class RangeSlider extends StatefulWidget { ...@@ -132,12 +132,6 @@ class RangeSlider extends StatefulWidget {
this.activeColor, this.activeColor,
this.inactiveColor, this.inactiveColor,
this.semanticFormatterCallback, 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(values != null),
assert(min != null), assert(min != null),
assert(max != null), assert(max != null),
...@@ -146,8 +140,6 @@ class RangeSlider extends StatefulWidget { ...@@ -146,8 +140,6 @@ class RangeSlider extends StatefulWidget {
assert(values.start >= min && values.start <= max), assert(values.start >= min && values.start <= max),
assert(values.end >= min && values.end <= max), assert(values.end >= min && values.end <= max),
assert(divisions == null || divisions > 0), assert(divisions == null || divisions > 0),
// ignore: deprecated_member_use_from_same_package
assert(useV2Slider != null),
super(key: key); super(key: key);
/// The currently selected values for this range slider. /// The currently selected values for this range slider.
...@@ -346,23 +338,6 @@ class RangeSlider extends StatefulWidget { ...@@ -346,23 +338,6 @@ class RangeSlider extends StatefulWidget {
/// {@end-tool} /// {@end-tool}
final RangeSemanticFormatterCallback semanticFormatterCallback; 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.
/// * <https://groups.google.com/g/flutter-announce/c/69dmlKUL5Ew/m/tQh-ajiEAAAJl>
///
/// 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. // Touch width for the tap boundary of the slider thumbs.
static const double _minTouchTargetWidth = kMinInteractiveDimension; static const double _minTouchTargetWidth = kMinInteractiveDimension;
...@@ -384,8 +359,6 @@ class RangeSlider extends StatefulWidget { ...@@ -384,8 +359,6 @@ class RangeSlider extends StatefulWidget {
properties.add(StringProperty('labelEnd', labels?.end)); properties.add(StringProperty('labelEnd', labels?.end));
properties.add(ColorProperty('activeColor', activeColor)); properties.add(ColorProperty('activeColor', activeColor));
properties.add(ColorProperty('inactiveColor', inactiveColor)); properties.add(ColorProperty('inactiveColor', inactiveColor));
// ignore: deprecated_member_use_from_same_package
properties.add(FlagProperty('useV2Slider', value: useV2Slider, ifFalse: 'useV1Slider'));
properties.add(ObjectFlagProperty<ValueChanged<RangeValues>>.has('semanticFormatterCallback', semanticFormatterCallback)); properties.add(ObjectFlagProperty<ValueChanged<RangeValues>>.has('semanticFormatterCallback', semanticFormatterCallback));
} }
} }
...@@ -573,14 +546,12 @@ class _RangeSliderState extends State<RangeSlider> with TickerProviderStateMixin ...@@ -573,14 +546,12 @@ class _RangeSliderState extends State<RangeSlider> with TickerProviderStateMixin
// the default shapes and text styles are aligned to the Material // the default shapes and text styles are aligned to the Material
// Guidelines. // Guidelines.
// ignore: deprecated_member_use_from_same_package const double _defaultTrackHeight = 4;
final bool useV2Slider = widget.useV2Slider; const RangeSliderTrackShape _defaultTrackShape = RoundedRectRangeSliderTrackShape();
final double _defaultTrackHeight = useV2Slider ? 4 : 2; const RangeSliderTickMarkShape _defaultTickMarkShape = RoundRangeSliderTickMarkShape();
final RangeSliderTrackShape _defaultTrackShape = RoundedRectRangeSliderTrackShape(useV2Slider: useV2Slider);
final RangeSliderTickMarkShape _defaultTickMarkShape = RoundRangeSliderTickMarkShape(useV2Slider: useV2Slider);
const SliderComponentShape _defaultOverlayShape = RoundSliderOverlayShape(); const SliderComponentShape _defaultOverlayShape = RoundSliderOverlayShape();
final RangeSliderThumbShape _defaultThumbShape = RoundRangeSliderThumbShape(useV2Slider: useV2Slider); const RangeSliderThumbShape _defaultThumbShape = RoundRangeSliderThumbShape();
final RangeSliderValueIndicatorShape _defaultValueIndicatorShape = useV2Slider ? const RectangularRangeSliderValueIndicatorShape() : const PaddleRangeSliderValueIndicatorShape(); const RangeSliderValueIndicatorShape _defaultValueIndicatorShape = RectangularRangeSliderValueIndicatorShape();
const ShowValueIndicator _defaultShowValueIndicator = ShowValueIndicator.onlyForDiscrete; const ShowValueIndicator _defaultShowValueIndicator = ShowValueIndicator.onlyForDiscrete;
const double _defaultMinThumbSeparation = 8; const double _defaultMinThumbSeparation = 8;
...@@ -643,8 +614,6 @@ class _RangeSliderState extends State<RangeSlider> with TickerProviderStateMixin ...@@ -643,8 +614,6 @@ class _RangeSliderState extends State<RangeSlider> with TickerProviderStateMixin
onChangeEnd: widget.onChangeEnd != null ? _handleDragEnd : null, onChangeEnd: widget.onChangeEnd != null ? _handleDragEnd : null,
state: this, state: this,
semanticFormatterCallback: widget.semanticFormatterCallback, semanticFormatterCallback: widget.semanticFormatterCallback,
// ignore: deprecated_member_use_from_same_package
useV2Slider: widget.useV2Slider,
), ),
); );
} }
...@@ -684,7 +653,6 @@ class _RangeSliderRenderObjectWidget extends LeafRenderObjectWidget { ...@@ -684,7 +653,6 @@ class _RangeSliderRenderObjectWidget extends LeafRenderObjectWidget {
this.onChangeEnd, this.onChangeEnd,
this.state, this.state,
this.semanticFormatterCallback, this.semanticFormatterCallback,
this.useV2Slider,
}) : super(key: key); }) : super(key: key);
final RangeValues values; final RangeValues values;
...@@ -698,7 +666,6 @@ class _RangeSliderRenderObjectWidget extends LeafRenderObjectWidget { ...@@ -698,7 +666,6 @@ class _RangeSliderRenderObjectWidget extends LeafRenderObjectWidget {
final ValueChanged<RangeValues> onChangeEnd; final ValueChanged<RangeValues> onChangeEnd;
final RangeSemanticFormatterCallback semanticFormatterCallback; final RangeSemanticFormatterCallback semanticFormatterCallback;
final _RangeSliderState state; final _RangeSliderState state;
final bool useV2Slider;
@override @override
_RenderRangeSlider createRenderObject(BuildContext context) { _RenderRangeSlider createRenderObject(BuildContext context) {
...@@ -717,7 +684,6 @@ class _RangeSliderRenderObjectWidget extends LeafRenderObjectWidget { ...@@ -717,7 +684,6 @@ class _RangeSliderRenderObjectWidget extends LeafRenderObjectWidget {
textDirection: Directionality.of(context), textDirection: Directionality.of(context),
semanticFormatterCallback: semanticFormatterCallback, semanticFormatterCallback: semanticFormatterCallback,
platform: Theme.of(context).platform, platform: Theme.of(context).platform,
useV2Slider: useV2Slider,
); );
} }
...@@ -756,7 +722,6 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix ...@@ -756,7 +722,6 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix
this.onChangeEnd, this.onChangeEnd,
@required _RangeSliderState state, @required _RangeSliderState state,
@required TextDirection textDirection, @required TextDirection textDirection,
bool useV2Slider,
}) : assert(values != null), }) : assert(values != null),
assert(values.start >= 0.0 && values.start <= 1.0), assert(values.start >= 0.0 && values.start <= 1.0),
assert(values.end >= 0.0 && values.end <= 1.0), assert(values.end >= 0.0 && values.end <= 1.0),
...@@ -773,8 +738,7 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix ...@@ -773,8 +738,7 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix
_screenSize = screenSize, _screenSize = screenSize,
_onChanged = onChanged, _onChanged = onChanged,
_state = state, _state = state,
_textDirection = textDirection, _textDirection = textDirection {
_useV2Slider = useV2Slider {
_updateLabelPainters(); _updateLabelPainters();
final GestureArenaTeam team = GestureArenaTeam(); final GestureArenaTeam team = GestureArenaTeam();
_drag = HorizontalDragGestureRecognizer() _drag = HorizontalDragGestureRecognizer()
...@@ -1022,8 +986,6 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix ...@@ -1022,8 +986,6 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix
return 0.05; return 0.05;
} }
final bool _useV2Slider;
void _updateLabelPainters() { void _updateLabelPainters() {
_updateLabelPainter(Thumb.start); _updateLabelPainter(Thumb.start);
_updateLabelPainter(Thumb.end); _updateLabelPainter(Thumb.end);
...@@ -1351,7 +1313,7 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix ...@@ -1351,7 +1313,7 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix
isEnabled: isEnabled, isEnabled: isEnabled,
sliderTheme: _sliderTheme, sliderTheme: _sliderTheme,
).width; ).width;
final double padding = _useV2Slider ? trackRect.height : tickMarkWidth; final double padding = trackRect.height;
final double adjustedTrackWidth = trackRect.width - padding; final double adjustedTrackWidth = trackRect.width - padding;
// If the tick marks would be too dense, don't bother painting them. // If the tick marks would be too dense, don't bother painting them.
if (adjustedTrackWidth / divisions >= 3.0 * tickMarkWidth) { if (adjustedTrackWidth / divisions >= 3.0 * tickMarkWidth) {
......
...@@ -133,12 +133,6 @@ class Slider extends StatefulWidget { ...@@ -133,12 +133,6 @@ class Slider extends StatefulWidget {
this.semanticFormatterCallback, this.semanticFormatterCallback,
this.focusNode, this.focusNode,
this.autofocus = false, 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, }) : _sliderType = _SliderType.material,
assert(value != null), assert(value != null),
assert(min != null), assert(min != null),
...@@ -146,8 +140,6 @@ class Slider extends StatefulWidget { ...@@ -146,8 +140,6 @@ class Slider extends StatefulWidget {
assert(min <= max), assert(min <= max),
assert(value >= min && value <= max), assert(value >= min && value <= max),
assert(divisions == null || divisions > 0), assert(divisions == null || divisions > 0),
// ignore: deprecated_member_use_from_same_package
assert(useV2Slider != null),
super(key: key); super(key: key);
/// Creates a [CupertinoSlider] if the target platform is iOS, creates a /// Creates a [CupertinoSlider] if the target platform is iOS, creates a
...@@ -172,12 +164,6 @@ class Slider extends StatefulWidget { ...@@ -172,12 +164,6 @@ class Slider extends StatefulWidget {
this.semanticFormatterCallback, this.semanticFormatterCallback,
this.focusNode, this.focusNode,
this.autofocus = false, 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, }) : _sliderType = _SliderType.adaptive,
assert(value != null), assert(value != null),
assert(min != null), assert(min != null),
...@@ -185,8 +171,6 @@ class Slider extends StatefulWidget { ...@@ -185,8 +171,6 @@ class Slider extends StatefulWidget {
assert(min <= max), assert(min <= max),
assert(value >= min && value <= max), assert(value >= min && value <= max),
assert(divisions == null || divisions > 0), assert(divisions == null || divisions > 0),
// ignore: deprecated_member_use_from_same_package
assert(useV2Slider != null),
super(key: key); super(key: key);
/// The currently selected value for this slider. /// The currently selected value for this slider.
...@@ -407,20 +391,6 @@ class Slider extends StatefulWidget { ...@@ -407,20 +391,6 @@ class Slider extends StatefulWidget {
/// {@macro flutter.widgets.Focus.autofocus} /// {@macro flutter.widgets.Focus.autofocus}
final bool 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.
/// * <https://groups.google.com/g/flutter-announce/c/69dmlKUL5Ew/m/tQh-ajiEAAAJl>
///
/// 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 ; final _SliderType _sliderType ;
@override @override
...@@ -442,7 +412,6 @@ class Slider extends StatefulWidget { ...@@ -442,7 +412,6 @@ class Slider extends StatefulWidget {
properties.add(ObjectFlagProperty<ValueChanged<double>>.has('semanticFormatterCallback', semanticFormatterCallback)); properties.add(ObjectFlagProperty<ValueChanged<double>>.has('semanticFormatterCallback', semanticFormatterCallback));
properties.add(ObjectFlagProperty<FocusNode>.has('focusNode', focusNode)); properties.add(ObjectFlagProperty<FocusNode>.has('focusNode', focusNode));
properties.add(FlagProperty('autofocus', value: autofocus, ifTrue: 'autofocus')); properties.add(FlagProperty('autofocus', value: autofocus, ifTrue: 'autofocus'));
properties.add(FlagProperty('useV2Slider', value: useV2Slider, ifFalse: 'useV1Slider'));
} }
} }
...@@ -636,13 +605,12 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin { ...@@ -636,13 +605,12 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
// the default shapes and text styles are aligned to the Material // the default shapes and text styles are aligned to the Material
// Guidelines. // Guidelines.
final bool useV2Slider = widget.useV2Slider; const double _defaultTrackHeight = 4;
final double _defaultTrackHeight = useV2Slider ? 4 : 2; const SliderTrackShape _defaultTrackShape = RoundedRectSliderTrackShape();
final SliderTrackShape _defaultTrackShape = RoundedRectSliderTrackShape(useV2Slider: useV2Slider); const SliderTickMarkShape _defaultTickMarkShape = RoundSliderTickMarkShape();
final SliderTickMarkShape _defaultTickMarkShape = RoundSliderTickMarkShape(useV2Slider: useV2Slider);
const SliderComponentShape _defaultOverlayShape = RoundSliderOverlayShape(); const SliderComponentShape _defaultOverlayShape = RoundSliderOverlayShape();
final SliderComponentShape _defaultThumbShape = RoundSliderThumbShape(useV2Slider: useV2Slider); const SliderComponentShape _defaultThumbShape = RoundSliderThumbShape();
final SliderComponentShape _defaultValueIndicatorShape = useV2Slider ? const RectangularSliderValueIndicatorShape() : const PaddleSliderValueIndicatorShape(); const SliderComponentShape _defaultValueIndicatorShape = RectangularSliderValueIndicatorShape();
const ShowValueIndicator _defaultShowValueIndicator = ShowValueIndicator.onlyForDiscrete; const ShowValueIndicator _defaultShowValueIndicator = ShowValueIndicator.onlyForDiscrete;
// The value indicator's color is not the same as the thumb and active track // The value indicator's color is not the same as the thumb and active track
...@@ -712,7 +680,6 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin { ...@@ -712,7 +680,6 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
semanticFormatterCallback: widget.semanticFormatterCallback, semanticFormatterCallback: widget.semanticFormatterCallback,
hasFocus: _focused, hasFocus: _focused,
hovering: _hovering, hovering: _hovering,
useV2Slider: widget.useV2Slider,
), ),
), ),
); );
...@@ -774,7 +741,6 @@ class _SliderRenderObjectWidget extends LeafRenderObjectWidget { ...@@ -774,7 +741,6 @@ class _SliderRenderObjectWidget extends LeafRenderObjectWidget {
this.semanticFormatterCallback, this.semanticFormatterCallback,
this.hasFocus, this.hasFocus,
this.hovering, this.hovering,
this.useV2Slider,
}) : super(key: key); }) : super(key: key);
final double value; final double value;
...@@ -790,7 +756,6 @@ class _SliderRenderObjectWidget extends LeafRenderObjectWidget { ...@@ -790,7 +756,6 @@ class _SliderRenderObjectWidget extends LeafRenderObjectWidget {
final _SliderState state; final _SliderState state;
final bool hasFocus; final bool hasFocus;
final bool hovering; final bool hovering;
final bool useV2Slider;
@override @override
_RenderSlider createRenderObject(BuildContext context) { _RenderSlider createRenderObject(BuildContext context) {
...@@ -810,7 +775,6 @@ class _SliderRenderObjectWidget extends LeafRenderObjectWidget { ...@@ -810,7 +775,6 @@ class _SliderRenderObjectWidget extends LeafRenderObjectWidget {
platform: Theme.of(context).platform, platform: Theme.of(context).platform,
hasFocus: hasFocus, hasFocus: hasFocus,
hovering: hovering, hovering: hovering,
useV2Slider: useV2Slider,
); );
} }
...@@ -854,7 +818,6 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin { ...@@ -854,7 +818,6 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
@required TextDirection textDirection, @required TextDirection textDirection,
bool hasFocus, bool hasFocus,
bool hovering, bool hovering,
bool useV2Slider,
}) : assert(value != null && value >= 0.0 && value <= 1.0), }) : assert(value != null && value >= 0.0 && value <= 1.0),
assert(state != null), assert(state != null),
assert(textDirection != null), assert(textDirection != null),
...@@ -870,8 +833,7 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin { ...@@ -870,8 +833,7 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
_state = state, _state = state,
_textDirection = textDirection, _textDirection = textDirection,
_hasFocus = hasFocus, _hasFocus = hasFocus,
_hovering = hovering, _hovering = hovering {
_useV2Slider = useV2Slider {
_updateLabelPainter(); _updateLabelPainter();
final GestureArenaTeam team = GestureArenaTeam(); final GestureArenaTeam team = GestureArenaTeam();
_drag = HorizontalDragGestureRecognizer() _drag = HorizontalDragGestureRecognizer()
...@@ -1116,8 +1078,6 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin { ...@@ -1116,8 +1078,6 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
} }
} }
} }
final bool _useV2Slider;
bool get showValueIndicator { bool get showValueIndicator {
bool showValueIndicator; bool showValueIndicator;
switch (_sliderTheme.showValueIndicator) { switch (_sliderTheme.showValueIndicator) {
...@@ -1379,7 +1339,7 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin { ...@@ -1379,7 +1339,7 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
isEnabled: isInteractive, isEnabled: isInteractive,
sliderTheme: _sliderTheme, sliderTheme: _sliderTheme,
).width; ).width;
final double padding = _useV2Slider ? trackRect.height : tickMarkWidth; final double padding = trackRect.height;
final double adjustedTrackWidth = trackRect.width - padding; final double adjustedTrackWidth = trackRect.width - padding;
// If the tick marks would be too dense, don't bother painting them. // If the tick marks would be too dense, don't bother painting them.
if (adjustedTrackWidth / divisions >= 3.0 * tickMarkWidth) { if (adjustedTrackWidth / divisions >= 3.0 * tickMarkWidth) {
......
...@@ -109,9 +109,6 @@ import 'theme_data.dart'; ...@@ -109,9 +109,6 @@ import 'theme_data.dart';
/// left, and in [TextDirection.rtl], the start of the slider is on the right. /// left, and in [TextDirection.rtl], the start of the slider is on the right.
/// {@endtemplate} /// {@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 /// 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 /// unexpected breaking changes, this value should be set to true. Setting
/// this to false is considered deprecated. /// this to false is considered deprecated.
...@@ -1673,14 +1670,7 @@ class RectangularSliderTrackShape extends SliderTrackShape with BaseSliderTrackS ...@@ -1673,14 +1670,7 @@ class RectangularSliderTrackShape extends SliderTrackShape with BaseSliderTrackS
/// * [RectangularSliderTrackShape], for a similar track with sharp edges. /// * [RectangularSliderTrackShape], for a similar track with sharp edges.
class RoundedRectSliderTrackShape extends SliderTrackShape with BaseSliderTrackShape { class RoundedRectSliderTrackShape extends SliderTrackShape with BaseSliderTrackShape {
/// Create a slider track that draws two rectangles with rounded outer edges. /// Create a slider track that draws two rectangles with rounded outer edges.
const RoundedRectSliderTrackShape({ this.useV2Slider = true }); const RoundedRectSliderTrackShape();
/// {@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 @override
void paint( void paint(
...@@ -1743,47 +1733,28 @@ class RoundedRectSliderTrackShape extends SliderTrackShape with BaseSliderTrackS ...@@ -1743,47 +1733,28 @@ class RoundedRectSliderTrackShape extends SliderTrackShape with BaseSliderTrackS
final Radius trackRadius = Radius.circular(trackRect.height / 2); final Radius trackRadius = Radius.circular(trackRect.height / 2);
final Radius activeTrackRadius = Radius.circular(trackRect.height / 2 + 1); final Radius activeTrackRadius = Radius.circular(trackRect.height / 2 + 1);
// ignore: deprecated_member_use_from_same_package context.canvas.drawRRect(
if (useV2Slider) { RRect.fromLTRBAndCorners(
context.canvas.drawRRect( trackRect.left,
RRect.fromLTRBAndCorners( (textDirection == TextDirection.ltr) ? trackRect.top - (additionalActiveTrackHeight / 2): trackRect.top,
trackRect.left, thumbCenter.dx,
(textDirection == TextDirection.ltr) ? trackRect.top - (additionalActiveTrackHeight / 2): trackRect.top, (textDirection == TextDirection.ltr) ? trackRect.bottom + (additionalActiveTrackHeight / 2) : trackRect.bottom,
thumbCenter.dx, topLeft: (textDirection == TextDirection.ltr) ? activeTrackRadius : trackRadius,
(textDirection == TextDirection.ltr) ? trackRect.bottom + (additionalActiveTrackHeight / 2) : trackRect.bottom, bottomLeft: (textDirection == TextDirection.ltr) ? activeTrackRadius: trackRadius,
topLeft: (textDirection == TextDirection.ltr) ? activeTrackRadius : trackRadius, ),
bottomLeft: (textDirection == TextDirection.ltr) ? activeTrackRadius: trackRadius, leftTrackPaint,
), );
leftTrackPaint, context.canvas.drawRRect(
); RRect.fromLTRBAndCorners(
context.canvas.drawRRect( thumbCenter.dx,
RRect.fromLTRBAndCorners( (textDirection == TextDirection.rtl) ? trackRect.top - (additionalActiveTrackHeight / 2) : trackRect.top,
thumbCenter.dx, trackRect.right,
(textDirection == TextDirection.rtl) ? trackRect.top - (additionalActiveTrackHeight / 2) : trackRect.top, (textDirection == TextDirection.rtl) ? trackRect.bottom + (additionalActiveTrackHeight / 2) : trackRect.bottom,
trackRect.right, topRight: (textDirection == TextDirection.rtl) ? activeTrackRadius : trackRadius,
(textDirection == TextDirection.rtl) ? trackRect.bottom + (additionalActiveTrackHeight / 2) : trackRect.bottom, bottomRight: (textDirection == TextDirection.rtl) ? activeTrackRadius : trackRadius,
topRight: (textDirection == TextDirection.rtl) ? activeTrackRadius : trackRadius, ),
bottomRight: (textDirection == TextDirection.rtl) ? activeTrackRadius : trackRadius, rightTrackPaint,
), );
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);
}
} }
} }
...@@ -1815,14 +1786,7 @@ class RectangularRangeSliderTrackShape extends RangeSliderTrackShape { ...@@ -1815,14 +1786,7 @@ class RectangularRangeSliderTrackShape extends RangeSliderTrackShape {
/// ///
/// The middle track segment is the selected range and is active, and the two /// The middle track segment is the selected range and is active, and the two
/// outer track segments are inactive. /// outer track segments are inactive.
const RectangularRangeSliderTrackShape({this.useV2Slider}); const RectangularRangeSliderTrackShape();
/// {@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 @override
Rect getPreferredRect({ Rect getPreferredRect({
...@@ -1948,14 +1912,7 @@ class RoundedRectRangeSliderTrackShape extends RangeSliderTrackShape { ...@@ -1948,14 +1912,7 @@ class RoundedRectRangeSliderTrackShape extends RangeSliderTrackShape {
/// ///
/// The middle track segment is the selected range and is active, and the two /// The middle track segment is the selected range and is active, and the two
/// outer track segments are inactive. /// outer track segments are inactive.
const RoundedRectRangeSliderTrackShape({ this.useV2Slider }); const RoundedRectRangeSliderTrackShape();
/// {@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 @override
Rect getPreferredRect({ Rect getPreferredRect({
...@@ -2056,62 +2013,39 @@ class RoundedRectRangeSliderTrackShape extends RangeSliderTrackShape { ...@@ -2056,62 +2013,39 @@ class RoundedRectRangeSliderTrackShape extends RangeSliderTrackShape {
isDiscrete: isDiscrete, isDiscrete: isDiscrete,
); );
// ignore: deprecated_member_use_from_same_package final Radius trackRadius = Radius.circular(trackRect.height / 2);
if (useV2Slider) {
final Radius trackRadius = Radius.circular(trackRect.height / 2); context.canvas.drawRRect(
RRect.fromLTRBAndCorners(
context.canvas.drawRRect( trackRect.left,
RRect.fromLTRBAndCorners( trackRect.top,
trackRect.left, leftThumbOffset.dx,
trackRect.top, trackRect.bottom,
leftThumbOffset.dx, topLeft: trackRadius,
trackRect.bottom, bottomLeft: trackRadius,
topLeft: trackRadius, ),
bottomLeft: trackRadius, inactivePaint,
), );
inactivePaint, context.canvas.drawRect(
); Rect.fromLTRB(
context.canvas.drawRect( leftThumbOffset.dx,
Rect.fromLTRB( trackRect.top - (additionalActiveTrackHeight / 2),
leftThumbOffset.dx, rightThumbOffset.dx,
trackRect.top - (additionalActiveTrackHeight / 2), trackRect.bottom + (additionalActiveTrackHeight / 2),
rightThumbOffset.dx, ),
trackRect.bottom + (additionalActiveTrackHeight / 2), activePaint,
), );
activePaint, context.canvas.drawRRect(
); RRect.fromLTRBAndCorners(
context.canvas.drawRRect( rightThumbOffset.dx,
RRect.fromLTRBAndCorners( trackRect.top,
rightThumbOffset.dx, trackRect.right,
trackRect.top, trackRect.bottom,
trackRect.right, topRight: trackRadius,
trackRect.bottom, bottomRight: trackRadius,
topRight: trackRadius, ),
bottomRight: trackRadius, inactivePaint,
), );
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);
}
} }
} }
...@@ -2137,25 +2071,13 @@ class RoundSliderTickMarkShape extends SliderTickMarkShape { ...@@ -2137,25 +2071,13 @@ class RoundSliderTickMarkShape extends SliderTickMarkShape {
/// Create a slider tick mark that draws a circle. /// Create a slider tick mark that draws a circle.
const RoundSliderTickMarkShape({ const RoundSliderTickMarkShape({
this.tickMarkRadius, this.tickMarkRadius,
this.useV2Slider = true,
}); });
/// The preferred radius of the round tick mark. /// The preferred radius of the round tick mark.
/// ///
// ignore: deprecated_member_use_from_same_package /// If it is not provided, then 1/4 of the [SliderThemeData.trackHeight] is used.
/// 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.
final double tickMarkRadius; 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 @override
Size getPreferredSize({ Size getPreferredSize({
@required SliderThemeData sliderTheme, @required SliderThemeData sliderTheme,
...@@ -2166,10 +2088,8 @@ class RoundSliderTickMarkShape extends SliderTickMarkShape { ...@@ -2166,10 +2088,8 @@ class RoundSliderTickMarkShape extends SliderTickMarkShape {
assert(isEnabled != null); assert(isEnabled != null);
// The tick marks are tiny circles. If no radius is provided, then the // The tick marks are tiny circles. If no radius is provided, then the
// radius is defaulted to be a fraction of the // radius is defaulted to be a fraction of the
// [SliderThemeData.trackHeight]. The fraction is 1/4 when [useV2Slider] is // [SliderThemeData.trackHeight]. The fraction is 1/4.
// true, and 1/2 when it is false. return Size.fromRadius(tickMarkRadius ?? sliderTheme.trackHeight / 4);
// ignore: deprecated_member_use_from_same_package
return Size.fromRadius(tickMarkRadius ?? sliderTheme.trackHeight / (useV2Slider ? 4 : 2));
} }
@override @override
...@@ -2246,25 +2166,13 @@ class RoundRangeSliderTickMarkShape extends RangeSliderTickMarkShape { ...@@ -2246,25 +2166,13 @@ class RoundRangeSliderTickMarkShape extends RangeSliderTickMarkShape {
/// Create a range slider tick mark that draws a circle. /// Create a range slider tick mark that draws a circle.
const RoundRangeSliderTickMarkShape({ const RoundRangeSliderTickMarkShape({
this.tickMarkRadius, this.tickMarkRadius,
this.useV2Slider = true,
}); });
/// The preferred radius of the round tick mark. /// The preferred radius of the round tick mark.
/// ///
// ignore: deprecated_member_use_from_same_package /// If it is not provided, then 1/4 of the [SliderThemeData.trackHeight] is used.
/// 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.
final double tickMarkRadius; 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 @override
Size getPreferredSize({ Size getPreferredSize({
@required SliderThemeData sliderTheme, @required SliderThemeData sliderTheme,
...@@ -2273,8 +2181,7 @@ class RoundRangeSliderTickMarkShape extends RangeSliderTickMarkShape { ...@@ -2273,8 +2181,7 @@ class RoundRangeSliderTickMarkShape extends RangeSliderTickMarkShape {
assert(sliderTheme != null); assert(sliderTheme != null);
assert(sliderTheme.trackHeight != null); assert(sliderTheme.trackHeight != null);
assert(isEnabled != null); assert(isEnabled != null);
// ignore: deprecated_member_use_from_same_package return Size.fromRadius(tickMarkRadius ?? sliderTheme.trackHeight / 4);
return Size.fromRadius(tickMarkRadius ?? sliderTheme.trackHeight / (useV2Slider ? 4 : 2));
} }
@override @override
...@@ -2392,9 +2299,7 @@ class _EmptySliderComponentShape extends SliderComponentShape { ...@@ -2392,9 +2299,7 @@ class _EmptySliderComponentShape extends SliderComponentShape {
/// The default shape of a [Slider]'s thumb. /// The default shape of a [Slider]'s thumb.
/// ///
// ignore: deprecated_member_use_from_same_package /// There is a shadow for the resting, pressed, hovered, and focused state.
/// If [useV2Slider] is true, then there is a shadow for the resting and
/// pressed state.
/// ///
/// See also: /// See also:
/// ///
...@@ -2408,7 +2313,6 @@ class RoundSliderThumbShape extends SliderComponentShape { ...@@ -2408,7 +2313,6 @@ class RoundSliderThumbShape extends SliderComponentShape {
this.disabledThumbRadius, this.disabledThumbRadius,
this.elevation = 1.0, this.elevation = 1.0,
this.pressedElevation = 6.0, this.pressedElevation = 6.0,
this.useV2Slider = true,
}); });
/// The preferred radius of the round thumb shape when the slider is enabled. /// The preferred radius of the round thumb shape when the slider is enabled.
...@@ -2425,9 +2329,6 @@ class RoundSliderThumbShape extends SliderComponentShape { ...@@ -2425,9 +2329,6 @@ class RoundSliderThumbShape extends SliderComponentShape {
/// The resting elevation adds shadow to the unpressed thumb. /// 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. /// The default is 1.
/// ///
/// Use 0 for no shadow. The higher the value, the larger the shadow. For /// Use 0 for no shadow. The higher the value, the larger the shadow. For
...@@ -2437,22 +2338,12 @@ class RoundSliderThumbShape extends SliderComponentShape { ...@@ -2437,22 +2338,12 @@ class RoundSliderThumbShape extends SliderComponentShape {
/// The pressed elevation adds shadow to the pressed thumb. /// 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. /// The default is 6.
/// ///
/// Use 0 for no shadow. The higher the value, the larger the shadow. For /// 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. /// example, a value of 12 will create a very large shadow.
final double pressedElevation; 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 @override
Size getPreferredSize(bool isEnabled, bool isDiscrete) { Size getPreferredSize(bool isEnabled, bool isDiscrete) {
return Size.fromRadius(isEnabled == true ? enabledThumbRadius : _disabledThumbRadius); return Size.fromRadius(isEnabled == true ? enabledThumbRadius : _disabledThumbRadius);
...@@ -2494,18 +2385,15 @@ class RoundSliderThumbShape extends SliderComponentShape { ...@@ -2494,18 +2385,15 @@ class RoundSliderThumbShape extends SliderComponentShape {
final Color color = colorTween.evaluate(enableAnimation); final Color color = colorTween.evaluate(enableAnimation);
final double radius = radiusTween.evaluate(enableAnimation); final double radius = radiusTween.evaluate(enableAnimation);
// ignore: deprecated_member_use_from_same_package final Tween<double> elevationTween = Tween<double>(
if (useV2Slider) { begin: elevation,
final Tween<double> elevationTween = Tween<double>( end: pressedElevation,
begin: elevation, );
end: pressedElevation,
);
final double evaluatedElevation = elevationTween.evaluate(activationAnimation); final double evaluatedElevation = elevationTween.evaluate(activationAnimation);
final Path path = Path() final Path path = Path()
..addArc(Rect.fromCenter(center: center, width: 2 * radius, height: 2 * radius), 0, math.pi * 2); ..addArc(Rect.fromCenter(center: center, width: 2 * radius, height: 2 * radius), 0, math.pi * 2);
canvas.drawShadow(path, Colors.black, evaluatedElevation, true); canvas.drawShadow(path, Colors.black, evaluatedElevation, true);
}
canvas.drawCircle( canvas.drawCircle(
center, center,
...@@ -2517,9 +2405,7 @@ class RoundSliderThumbShape extends SliderComponentShape { ...@@ -2517,9 +2405,7 @@ class RoundSliderThumbShape extends SliderComponentShape {
/// The default shape of a [RangeSlider]'s thumbs. /// The default shape of a [RangeSlider]'s thumbs.
/// ///
// ignore: deprecated_member_use_from_same_package /// There is a shadow for the resting and pressed state.
/// If [useV2Slider] is true, then there is a shadow for the resting and
/// pressed state.
/// ///
/// See also: /// See also:
/// ///
...@@ -2533,16 +2419,8 @@ class RoundRangeSliderThumbShape extends RangeSliderThumbShape { ...@@ -2533,16 +2419,8 @@ class RoundRangeSliderThumbShape extends RangeSliderThumbShape {
this.disabledThumbRadius, this.disabledThumbRadius,
this.elevation = 1.0, this.elevation = 1.0,
this.pressedElevation = 6.0, this.pressedElevation = 6.0,
this.useV2Slider = true,
}) : assert(enabledThumbRadius != null); }) : 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. /// 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. /// If it is not provided, then the material default of 10 is used.
...@@ -2636,13 +2514,10 @@ class RoundRangeSliderThumbShape extends RangeSliderThumbShape { ...@@ -2636,13 +2514,10 @@ class RoundRangeSliderThumbShape extends RangeSliderThumbShape {
final Color color = colorTween.evaluate(enableAnimation); final Color color = colorTween.evaluate(enableAnimation);
// ignore: deprecated_member_use_from_same_package final double evaluatedElevation = isPressed ? elevationTween.evaluate(activationAnimation) : elevation;
if (useV2Slider) { final Path shadowPath = Path()
final double evaluatedElevation = isPressed ? elevationTween.evaluate(activationAnimation) : elevation; ..addArc(Rect.fromCenter(center: center, width: 2 * radius, height: 2 * radius), 0, math.pi * 2);
final Path shadowPath = Path() canvas.drawShadow(shadowPath, Colors.black, evaluatedElevation, true);
..addArc(Rect.fromCenter(center: center, width: 2 * radius, height: 2 * radius), 0, math.pi * 2);
canvas.drawShadow(shadowPath, Colors.black, evaluatedElevation, true);
}
canvas.drawCircle( canvas.drawCircle(
center, center,
......
...@@ -461,8 +461,6 @@ void main() { ...@@ -461,8 +461,6 @@ void main() {
final Widget slider = Scaffold( final Widget slider = Scaffold(
body: Center( body: Center(
child: Slider( child: Slider(
// ignore: deprecated_member_use_from_same_package
useV2Slider: false,
value: 0.5, value: 0.5,
onChanged: (double value) { }, onChanged: (double value) { },
), ),
...@@ -525,7 +523,7 @@ void main() { ...@@ -525,7 +523,7 @@ void main() {
await tester.tap(find.text('push wrapped')); await tester.tap(find.text('push wrapped'));
await tester.pumpAndSettle(); // route animation await tester.pumpAndSettle(); // route animation
RenderBox sliderBox = tester.firstRenderObject<RenderBox>(find.byType(Slider)); RenderBox sliderBox = tester.firstRenderObject<RenderBox>(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)); expect(sliderBox, paints..circle(color: thumbColor));
Navigator.of(navigatorContext).pop(); Navigator.of(navigatorContext).pop();
...@@ -534,7 +532,7 @@ void main() { ...@@ -534,7 +532,7 @@ void main() {
await tester.tap(find.text('push unwrapped')); await tester.tap(find.text('push unwrapped'));
await tester.pumpAndSettle(); // route animation await tester.pumpAndSettle(); // route animation
sliderBox = tester.firstRenderObject<RenderBox>(find.byType(Slider)); sliderBox = tester.firstRenderObject<RenderBox>(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))); expect(sliderBox, isNot(paints..circle(color: thumbColor)));
}); });
......
...@@ -1031,7 +1031,6 @@ void main() { ...@@ -1031,7 +1031,6 @@ void main() {
Color inactiveColor, Color inactiveColor,
int divisions, int divisions,
bool enabled = true, bool enabled = true,
bool useV2Slider = false,
}) { }) {
RangeValues values = const RangeValues(0.5, 0.75); RangeValues values = const RangeValues(0.5, 0.75);
final ValueChanged<RangeValues> onChanged = !enabled ? null : (RangeValues newValues) { final ValueChanged<RangeValues> onChanged = !enabled ? null : (RangeValues newValues) {
...@@ -1053,8 +1052,6 @@ void main() { ...@@ -1053,8 +1052,6 @@ void main() {
activeColor: activeColor, activeColor: activeColor,
inactiveColor: inactiveColor, inactiveColor: inactiveColor,
onChanged: onChanged, onChanged: onChanged,
// ignore: deprecated_member_use_from_same_package
useV2Slider: useV2Slider,
), ),
), ),
), ),
...@@ -1064,31 +1061,6 @@ void main() { ...@@ -1064,31 +1061,6 @@ void main() {
); );
} }
testWidgets('Range Slider V2 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));
final RenderBox sliderBox = tester.firstRenderObject<RenderBox>(find.byType(RangeSlider));
// Check default theme for enabled widget.
expect(sliderBox, paints
..rrect(color: sliderTheme.inactiveTrackColor)
..rect(color: sliderTheme.activeTrackColor)
..rrect(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..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 { 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 ThemeData theme = _buildTheme();
final SliderThemeData sliderTheme = theme.sliderTheme; final SliderThemeData sliderTheme = theme.sliderTheme;
...@@ -1099,9 +1071,9 @@ void main() { ...@@ -1099,9 +1071,9 @@ void main() {
// Check default theme for enabled widget. // Check default theme for enabled widget.
expect(sliderBox, paints expect(sliderBox, paints
..rect(color: sliderTheme.inactiveTrackColor) ..rrect(color: sliderTheme.inactiveTrackColor)
..rect(color: sliderTheme.activeTrackColor) ..rect(color: sliderTheme.activeTrackColor)
..rect(color: sliderTheme.inactiveTrackColor)); ..rrect(color: sliderTheme.inactiveTrackColor));
expect(sliderBox, paints expect(sliderBox, paints
..circle(color: sliderTheme.thumbColor) ..circle(color: sliderTheme.thumbColor)
..circle(color: sliderTheme.thumbColor)); ..circle(color: sliderTheme.thumbColor));
...@@ -1112,34 +1084,6 @@ void main() { ...@@ -1112,34 +1084,6 @@ void main() {
expect(sliderBox, isNot(paints..circle(color: sliderTheme.inactiveTickMarkColor))); 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 {
const Color activeColor = Color(0xcafefeed);
final ThemeData theme = _buildTheme();
final SliderThemeData sliderTheme = theme.sliderTheme;
await tester.pumpWidget(_buildThemedApp(theme: theme, activeColor: activeColor, useV2Slider: true));
final RenderBox sliderBox = tester.firstRenderObject<RenderBox>(find.byType(RangeSlider));
expect(
sliderBox,
paints
..rrect(color: sliderTheme.inactiveTrackColor)
..rect(color: activeColor)
..rrect(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)));
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 { 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); const Color activeColor = Color(0xcafefeed);
final ThemeData theme = _buildTheme(); final ThemeData theme = _buildTheme();
...@@ -1152,9 +1096,9 @@ void main() { ...@@ -1152,9 +1096,9 @@ void main() {
expect( expect(
sliderBox, sliderBox,
paints paints
..rect(color: sliderTheme.inactiveTrackColor) ..rrect(color: sliderTheme.inactiveTrackColor)
..rect(color: activeColor) ..rect(color: activeColor)
..rect(color: sliderTheme.inactiveTrackColor)); ..rrect(color: sliderTheme.inactiveTrackColor));
expect( expect(
sliderBox, sliderBox,
paints paints
...@@ -1166,33 +1110,6 @@ void main() { ...@@ -1166,33 +1110,6 @@ void main() {
expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledInactiveTrackColor))); 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<RenderBox>(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 { testWidgets('Range Slider uses the right theme colors for the right shapes when setting the inactive color', (WidgetTester tester) async {
const Color inactiveColor = Color(0xdeadbeef); const Color inactiveColor = Color(0xdeadbeef);
final ThemeData theme = _buildTheme(); final ThemeData theme = _buildTheme();
...@@ -1205,9 +1122,9 @@ void main() { ...@@ -1205,9 +1122,9 @@ void main() {
expect( expect(
sliderBox, sliderBox,
paints paints
..rect(color: inactiveColor) ..rrect(color: inactiveColor)
..rect(color: sliderTheme.activeTrackColor) ..rect(color: sliderTheme.activeTrackColor)
..rect(color: inactiveColor)); ..rrect(color: inactiveColor));
expect( expect(
sliderBox, sliderBox,
paints paints
...@@ -1218,7 +1135,7 @@ void main() { ...@@ -1218,7 +1135,7 @@ void main() {
expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledInactiveTrackColor))); 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 { 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 activeColor = Color(0xcafefeed);
const Color inactiveColor = Color(0xdeadbeef); const Color inactiveColor = Color(0xdeadbeef);
final ThemeData theme = _buildTheme(); final ThemeData theme = _buildTheme();
...@@ -1228,7 +1145,6 @@ void main() { ...@@ -1228,7 +1145,6 @@ void main() {
theme: theme, theme: theme,
activeColor: activeColor, activeColor: activeColor,
inactiveColor: inactiveColor, inactiveColor: inactiveColor,
useV2Slider: true,
)); ));
final RenderBox sliderBox = tester.firstRenderObject<RenderBox>(find.byType(RangeSlider)); final RenderBox sliderBox = tester.firstRenderObject<RenderBox>(find.byType(RangeSlider));
...@@ -1246,69 +1162,8 @@ void main() { ...@@ -1246,69 +1162,8 @@ void main() {
..circle(color: activeColor)); ..circle(color: activeColor));
expect(sliderBox, isNot(paints..circle(color: sliderTheme.thumbColor))); expect(sliderBox, isNot(paints..circle(color: sliderTheme.thumbColor)));
expect(sliderBox, isNot(paints..circle(color: sliderTheme.disabledThumbColor))); 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);
final ThemeData theme = _buildTheme();
final SliderThemeData sliderTheme = theme.sliderTheme;
await tester.pumpWidget(_buildThemedApp(
theme: theme,
activeColor: activeColor,
inactiveColor: inactiveColor,
));
final RenderBox sliderBox = tester.firstRenderObject<RenderBox>(find.byType(RangeSlider));
expect(
sliderBox,
paints
..rect(color: inactiveColor)
..rect(color: activeColor)
..rect(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..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', (WidgetTester tester) async {
final ThemeData theme = _buildTheme();
final SliderThemeData sliderTheme = theme.sliderTheme;
await tester.pumpWidget(_buildThemedApp(theme: theme, divisions: 3, useV2Slider: true));
final RenderBox sliderBox = tester.firstRenderObject<RenderBox>(find.byType(RangeSlider));
expect(
sliderBox,
paints
..rrect(color: sliderTheme.inactiveTrackColor)
..rect(color: sliderTheme.activeTrackColor)
..rrect(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.disabledActiveTrackColor)));
expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledInactiveTrackColor))); 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 { testWidgets('Range Slider uses the right theme colors for the right shapes for a discrete slider', (WidgetTester tester) async {
...@@ -1322,9 +1177,9 @@ void main() { ...@@ -1322,9 +1177,9 @@ void main() {
expect( expect(
sliderBox, sliderBox,
paints paints
..rect(color: sliderTheme.inactiveTrackColor) ..rrect(color: sliderTheme.inactiveTrackColor)
..rect(color: sliderTheme.activeTrackColor) ..rect(color: sliderTheme.activeTrackColor)
..rect(color: sliderTheme.inactiveTrackColor)); ..rrect(color: sliderTheme.inactiveTrackColor));
expect( expect(
sliderBox, sliderBox,
paints paints
...@@ -1339,7 +1194,7 @@ void main() { ...@@ -1339,7 +1194,7 @@ void main() {
expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledInactiveTrackColor))); 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 { testWidgets('Range Slider 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 activeColor = Color(0xcafefeed);
const Color inactiveColor = Color(0xdeadbeef); const Color inactiveColor = Color(0xdeadbeef);
final ThemeData theme = _buildTheme(); final ThemeData theme = _buildTheme();
...@@ -1351,7 +1206,6 @@ void main() { ...@@ -1351,7 +1206,6 @@ void main() {
activeColor: activeColor, activeColor: activeColor,
inactiveColor: inactiveColor, inactiveColor: inactiveColor,
divisions: 3, divisions: 3,
useV2Slider: true,
)); ));
final RenderBox sliderBox = tester.firstRenderObject<RenderBox>(find.byType(RangeSlider)); final RenderBox sliderBox = tester.firstRenderObject<RenderBox>(find.byType(RangeSlider));
...@@ -1375,72 +1229,10 @@ void main() { ...@@ -1375,72 +1229,10 @@ void main() {
expect(sliderBox, isNot(paints..circle(color: sliderTheme.disabledThumbColor))); expect(sliderBox, isNot(paints..circle(color: sliderTheme.disabledThumbColor)));
expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledActiveTrackColor))); expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledActiveTrackColor)));
expect(sliderBox, isNot(paints..rect(color: sliderTheme.disabledInactiveTrackColor))); 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.activeTickMarkColor)));
expect(sliderBox, isNot(paints..circle(color: sliderTheme.inactiveTickMarkColor))); 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 {
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,
));
final RenderBox sliderBox = tester.firstRenderObject<RenderBox>(find.byType(RangeSlider));
expect(
sliderBox,
paints
..rect(color: inactiveColor)
..rect(color: activeColor)
..rect(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..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 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<RenderBox>(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 { 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 ThemeData theme = _buildTheme();
final SliderThemeData sliderTheme = theme.sliderTheme; final SliderThemeData sliderTheme = theme.sliderTheme;
...@@ -1449,34 +1241,6 @@ void main() { ...@@ -1449,34 +1241,6 @@ void main() {
final RenderBox sliderBox = tester.firstRenderObject<RenderBox>(find.byType(RangeSlider)); final RenderBox sliderBox = tester.firstRenderObject<RenderBox>(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<RenderBox>(find.byType(RangeSlider));
expect( expect(
sliderBox, sliderBox,
paints paints
...@@ -1486,8 +1250,6 @@ void main() { ...@@ -1486,8 +1250,6 @@ void main() {
expect(sliderBox, isNot(paints..circle(color: sliderTheme.thumbColor))); expect(sliderBox, isNot(paints..circle(color: sliderTheme.thumbColor)));
expect(sliderBox, isNot(paints..rect(color: sliderTheme.activeTrackColor))); expect(sliderBox, isNot(paints..rect(color: sliderTheme.activeTrackColor)));
expect(sliderBox, isNot(paints..rect(color: sliderTheme.inactiveTrackColor))); 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 { 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,78 +1270,15 @@ void main() { ...@@ -1508,78 +1270,15 @@ void main() {
expect( expect(
sliderBox, sliderBox,
paints paints
..rect(color: sliderTheme.disabledInactiveTrackColor) ..rrect(color: sliderTheme.disabledInactiveTrackColor)
..rect(color: sliderTheme.disabledActiveTrackColor) ..rect(color: sliderTheme.disabledActiveTrackColor)
..rect(color: sliderTheme.disabledInactiveTrackColor)); ..rrect(color: sliderTheme.disabledInactiveTrackColor));
expect(sliderBox, isNot(paints..circle(color: sliderTheme.thumbColor))); expect(sliderBox, isNot(paints..circle(color: sliderTheme.thumbColor)));
expect(sliderBox, isNot(paints..rect(color: sliderTheme.activeTrackColor))); expect(sliderBox, isNot(paints..rect(color: sliderTheme.activeTrackColor)));
expect(sliderBox, isNot(paints..rect(color: sliderTheme.inactiveTrackColor))); 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 {
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<RangeValues> 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(
values: values,
labels: RangeLabels(values.start.toStringAsFixed(2), values.end.toStringAsFixed(2)),
divisions: divisions,
activeColor: activeColor,
inactiveColor: inactiveColor,
onChanged: onChanged,
// ignore: deprecated_member_use_from_same_package
useV2Slider: true,
),
),
),
),
),
),
);
}
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);
final 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();
});
testWidgets('Range Slider 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 {
const Color customColor1 = Color(0xcafefeed);
const Color customColor2 = Color(0xdeadbeef);
final ThemeData theme = _buildTheme(); final ThemeData theme = _buildTheme();
final SliderThemeData sliderTheme = theme.sliderTheme; final SliderThemeData sliderTheme = theme.sliderTheme;
RangeValues values = const RangeValues(0.5, 0.75); RangeValues values = const RangeValues(0.5, 0.75);
...@@ -1603,8 +1302,6 @@ void main() { ...@@ -1603,8 +1302,6 @@ void main() {
child: Theme( child: Theme(
data: theme, data: theme,
child: RangeSlider( child: RangeSlider(
// ignore: deprecated_member_use_from_same_package
useV2Slider: false,
values: values, values: values,
labels: RangeLabels(values.start.toStringAsFixed(2), values.end.toStringAsFixed(2)), labels: RangeLabels(values.start.toStringAsFixed(2), values.end.toStringAsFixed(2)),
divisions: divisions, divisions: divisions,
...@@ -1625,7 +1322,7 @@ void main() { ...@@ -1625,7 +1322,7 @@ void main() {
final RenderBox valueIndicatorBox = tester.firstRenderObject(find.byType(Overlay)); final RenderBox valueIndicatorBox = tester.firstRenderObject(find.byType(Overlay));
final Offset topRight = tester.getTopRight(find.byType(RangeSlider)).translate(-24, 0); final Offset topRight = tester.getTopRight(find.byType(RangeSlider)).translate(-24, 0);
TestGesture gesture = await tester.startGesture(topRight); final TestGesture gesture = await tester.startGesture(topRight);
// Wait for value indicator animation to finish. // Wait for value indicator animation to finish.
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(values.end, equals(1)); expect(values.end, equals(1));
...@@ -1639,95 +1336,6 @@ void main() { ...@@ -1639,95 +1336,6 @@ void main() {
// Wait for value indicator animation to finish. // Wait for value indicator animation to finish.
await tester.pumpAndSettle(); 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 { testWidgets('Range Slider top thumb gets stroked when overlapping', (WidgetTester tester) async {
...@@ -1800,84 +1408,6 @@ void main() { ...@@ -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 { testWidgets('Range Slider top value indicator gets stroked when overlapping', (WidgetTester tester) async {
RangeValues values = const RangeValues(0.3, 0.7); RangeValues values = const RangeValues(0.3, 0.7);
...@@ -1954,84 +1484,6 @@ void main() { ...@@ -1954,84 +1484,6 @@ void main() {
await gesture.up(); 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 { 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); RangeValues values = const RangeValues(0.3, 0.7);
...@@ -2112,8 +1564,6 @@ void main() { ...@@ -2112,8 +1564,6 @@ void main() {
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
RangeSlider( RangeSlider(
// ignore: deprecated_member_use_from_same_package
useV2Slider: false,
activeColor: Colors.blue, activeColor: Colors.blue,
divisions: 4, divisions: 4,
inactiveColor: Colors.grey, inactiveColor: Colors.grey,
...@@ -2142,7 +1592,6 @@ void main() { ...@@ -2142,7 +1592,6 @@ void main() {
'labelEnd: "upperValue"', 'labelEnd: "upperValue"',
'activeColor: MaterialColor(primary value: Color(0xff2196f3))', 'activeColor: MaterialColor(primary value: Color(0xff2196f3))',
'inactiveColor: MaterialColor(primary value: Color(0xff9e9e9e))', 'inactiveColor: MaterialColor(primary value: Color(0xff9e9e9e))',
'useV1Slider',
]); ]);
}); });
} }
...@@ -570,17 +570,17 @@ void main() { ...@@ -570,17 +570,17 @@ void main() {
home: Directionality( home: Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: MediaQuery( child: MediaQuery(
data: MediaQueryData.fromWindow(window), data: MediaQueryData.fromWindow(window),
child: Material( child: Material(
child: Slider( child: Slider(
value: 0.0, value: 0.0,
min: 0.0, min: 0.0,
max: 0.0, max: 0.0,
onChanged: (double newValue) { onChanged: (double newValue) {
log.add(newValue); log.add(newValue);
}, },
),
), ),
),
), ),
), ),
), ),
...@@ -591,7 +591,7 @@ void main() { ...@@ -591,7 +591,7 @@ void main() {
log.clear(); 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 customColor1 = Color(0xcafefeed);
const Color customColor2 = Color(0xdeadbeef); const Color customColor2 = Color(0xdeadbeef);
final ThemeData theme = ThemeData( final ThemeData theme = ThemeData(
...@@ -641,8 +641,6 @@ void main() { ...@@ -641,8 +641,6 @@ void main() {
activeColor: activeColor, activeColor: activeColor,
inactiveColor: inactiveColor, inactiveColor: inactiveColor,
onChanged: onChanged, onChanged: onChanged,
// ignore: deprecated_member_use_from_same_package
useV2Slider: true,
), ),
), ),
), ),
...@@ -814,220 +812,6 @@ void main() { ...@@ -814,220 +812,6 @@ void main() {
await gesture.up(); 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<double> 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 { testWidgets('Slider can tap in vertical scroller', (WidgetTester tester) async {
double value = 0.0; double value = 0.0;
await tester.pumpWidget( await tester.pumpWidget(
...@@ -1138,12 +922,12 @@ void main() { ...@@ -1138,12 +922,12 @@ void main() {
child: MediaQuery( child: MediaQuery(
data: MediaQueryData.fromWindow(window), data: MediaQueryData.fromWindow(window),
child: const Material( child: const Material(
child: Center( child: Center(
child: Slider( child: Slider(
value: 0.5, value: 0.5,
onChanged: null, onChanged: null,
),
), ),
),
), ),
), ),
), ),
...@@ -1198,7 +982,7 @@ void main() { ...@@ -1198,7 +982,7 @@ void main() {
expect(tester.renderObject<RenderBox>(find.byType(Slider)).size, const Size(144.0 + 2.0 * 24.0, 48.0)); expect(tester.renderObject<RenderBox>(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(); final Key sliderKey = UniqueKey();
double value = 0.0; double value = 0.0;
...@@ -1235,8 +1019,6 @@ void main() { ...@@ -1235,8 +1019,6 @@ void main() {
value = newValue; value = newValue;
}); });
}, },
// ignore: deprecated_member_use_from_same_package
useV2Slider: true,
), ),
), ),
), ),
...@@ -1329,123 +1111,22 @@ void main() { ...@@ -1329,123 +1111,22 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect( expect(
tester.firstRenderObject(find.byType(Overlay)), tester.firstRenderObject(find.byType(Overlay)),
paints paints
..path( ..path(
includes: const <Offset>[ includes: const <Offset>[
Offset(0.0, 0.0), Offset(0.0, 0.0),
Offset(0.0, -52.0), Offset(0.0, -52.0),
Offset(-44.0, -16.0), Offset(-44.0, -16.0),
Offset(44.0, -16.0), Offset(44.0, -16.0),
], ],
color: const Color(0xf55f5f5f), 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 gesture.up();
await tester.pumpAndSettle(); await tester.pumpAndSettle();
}); }, skip: isBrowser);
testWidgets('Tick marks are skipped when they are too dense', (WidgetTester tester) async { testWidgets('Tick marks are skipped when they are too dense', (WidgetTester tester) async {
Widget buildSlider({ Widget buildSlider({
...@@ -1498,7 +1179,7 @@ void main() { ...@@ -1498,7 +1179,7 @@ void main() {
expect(material, paintsExactlyCountTimes(#drawCircle, 1)); expect(material, paintsExactlyCountTimes(#drawCircle, 1));
}); });
testWidgets('Slider V2 has correct animations when reparented', (WidgetTester tester) async { testWidgets('Slider has correct animations when reparented', (WidgetTester tester) async {
final Key sliderKey = GlobalKey(debugLabel: 'A'); final Key sliderKey = GlobalKey(debugLabel: 'A');
double value = 0.0; double value = 0.0;
...@@ -1513,8 +1194,6 @@ void main() { ...@@ -1513,8 +1194,6 @@ void main() {
value = newValue; value = newValue;
}); });
}, },
// ignore: deprecated_member_use_from_same_package
useV2Slider: true,
); );
for (int i = 0; i < parents; ++i) { for (int i = 0; i < parents; ++i) {
...@@ -1541,7 +1220,7 @@ void main() { ...@@ -1541,7 +1220,7 @@ void main() {
} }
Future<void> testReparenting(bool reparent) async { Future<void> testReparenting(bool reparent) async {
final RenderBox sliderBox = tester.firstRenderObject<RenderBox>(find.byType(Slider)); final MaterialInkController material = Material.of(tester.element(find.byType(Slider)));
final Offset center = tester.getCenter(find.byType(Slider)); final Offset center = tester.getCenter(find.byType(Slider));
// Move to 0.0. // Move to 0.0.
TestGesture gesture = await tester.startGesture(Offset.zero); TestGesture gesture = await tester.startGesture(Offset.zero);
...@@ -1550,7 +1229,7 @@ void main() { ...@@ -1550,7 +1229,7 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(SchedulerBinding.instance.transientCallbackCount, equals(0)); expect(SchedulerBinding.instance.transientCallbackCount, equals(0));
expect( expect(
sliderBox, material,
paints paints
..circle(x: 26.0, 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: 213.0, y: 24.0, radius: 1.0)
...@@ -1566,7 +1245,7 @@ void main() { ...@@ -1566,7 +1245,7 @@ void main() {
await tester.pump(const Duration(milliseconds: 25)); await tester.pump(const Duration(milliseconds: 25));
expect(SchedulerBinding.instance.transientCallbackCount, equals(2)); expect(SchedulerBinding.instance.transientCallbackCount, equals(2));
expect( expect(
sliderBox, material,
paints paints
..circle(x: 111.20703125, y: 24.0, radius: 5.687664985656738) ..circle(x: 111.20703125, y: 24.0, radius: 5.687664985656738)
..circle(x: 26.0, y: 24.0, radius: 1.0) ..circle(x: 26.0, y: 24.0, radius: 1.0)
...@@ -1586,7 +1265,7 @@ void main() { ...@@ -1586,7 +1265,7 @@ void main() {
await tester.pump(const Duration(milliseconds: 10)); await tester.pump(const Duration(milliseconds: 10));
expect(SchedulerBinding.instance.transientCallbackCount, equals(2)); expect(SchedulerBinding.instance.transientCallbackCount, equals(2));
expect( expect(
sliderBox, material,
paints paints
..circle(x: 190.0135726928711, y: 24.0, radius: 12.0) ..circle(x: 190.0135726928711, y: 24.0, radius: 12.0)
..circle(x: 26.0, y: 24.0, radius: 1.0) ..circle(x: 26.0, y: 24.0, radius: 1.0)
...@@ -1600,7 +1279,7 @@ void main() { ...@@ -1600,7 +1279,7 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(SchedulerBinding.instance.transientCallbackCount, equals(0)); expect(SchedulerBinding.instance.transientCallbackCount, equals(0));
expect( expect(
sliderBox, material,
paints paints
..circle(x: 400.0, y: 24.0, radius: 24.0) ..circle(x: 400.0, y: 24.0, radius: 24.0)
..circle(x: 26.0, y: 24.0, radius: 1.0) ..circle(x: 26.0, y: 24.0, radius: 1.0)
...@@ -1614,7 +1293,7 @@ void main() { ...@@ -1614,7 +1293,7 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(SchedulerBinding.instance.transientCallbackCount, equals(0)); expect(SchedulerBinding.instance.transientCallbackCount, equals(0));
expect( expect(
sliderBox, material,
paints paints
..circle(x: 26.0, 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: 213.0, y: 24.0, radius: 1.0)
...@@ -1632,140 +1311,6 @@ void main() { ...@@ -1632,140 +1311,6 @@ void main() {
await testReparenting(true); await testReparenting(true);
}); });
testWidgets('Slider 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(
// ignore: deprecated_member_use_from_same_package
useV2Slider: false,
key: sliderKey,
value: value,
divisions: 4,
onChanged: (double newValue) {
setState(() {
value = newValue;
});
},
);
for (int i = 0; i < parents; ++i) {
slider = Column(children: <Widget>[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<void> testReparenting(bool reparent) async {
final MaterialInkController material = Material.of(tester.element(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(
material,
paints
..circle(x: 25.0, y: 24.0, radius: 1.0)
..circle(x: 212.5, 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: 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(
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: 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: 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(
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: 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: 190.0135726928711, y: 24.0, radius: 10.0),
);
// Wait for animations to finish.
await tester.pumpAndSettle();
expect(SchedulerBinding.instance.transientCallbackCount, equals(0));
expect(
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: 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: 400.0, y: 24.0, radius: 10.0),
);
await gesture.up();
await tester.pumpAndSettle();
expect(SchedulerBinding.instance.transientCallbackCount, equals(0));
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: 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: 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 Semantics', (WidgetTester tester) async { testWidgets('Slider Semantics', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester); final SemanticsTester semantics = SemanticsTester(tester);
...@@ -1874,25 +1419,25 @@ void main() { ...@@ -1874,25 +1419,25 @@ void main() {
final SemanticsTester semantics = SemanticsTester(tester); final SemanticsTester semantics = SemanticsTester(tester);
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
home: Theme( home: Theme(
data: ThemeData.light(), data: ThemeData.light(),
child: Directionality( child: Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: MediaQuery( child: MediaQuery(
data: MediaQueryData.fromWindow(window), data: MediaQueryData.fromWindow(window),
child: Material( child: Material(
child: Slider( child: Slider(
value: 100.0, value: 100.0,
min: 0.0, min: 0.0,
max: 200.0, max: 200.0,
onChanged: (double v) { }, onChanged: (double v) { },
),
), ),
), ),
), ),
), ),
), )
)
); );
expect( expect(
...@@ -2505,8 +2050,6 @@ void main() { ...@@ -2505,8 +2050,6 @@ void main() {
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
const Slider( const Slider(
// ignore: deprecated_member_use_from_same_package
useV2Slider: false,
activeColor: Colors.blue, activeColor: Colors.blue,
divisions: 10, divisions: 10,
inactiveColor: Colors.grey, inactiveColor: Colors.grey,
...@@ -2533,7 +2076,6 @@ void main() { ...@@ -2533,7 +2076,6 @@ void main() {
'label: "Set a value"', 'label: "Set a value"',
'activeColor: MaterialColor(primary value: Color(0xff2196f3))', 'activeColor: MaterialColor(primary value: Color(0xff2196f3))',
'inactiveColor: MaterialColor(primary value: Color(0xff9e9e9e))', 'inactiveColor: MaterialColor(primary value: Color(0xff9e9e9e))',
'useV1Slider',
]); ]);
}); });
} }
...@@ -94,54 +94,18 @@ void main() { ...@@ -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<RenderBox>(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 { testWidgets('Slider uses ThemeData slider theme if present', (WidgetTester tester) async {
final ThemeData theme = ThemeData( final ThemeData theme = ThemeData(
platform: TargetPlatform.android, platform: TargetPlatform.android,
primarySwatch: Colors.red, primarySwatch: Colors.red,
); );
final SliderThemeData sliderTheme = theme.sliderTheme; 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( final SliderThemeData customTheme = sliderTheme.copyWith(
activeTrackColor: Colors.purple, activeTrackColor: Colors.purple,
inactiveTrackColor: Colors.purple.withAlpha(0x3d), 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))); final MaterialInkController material = Material.of(tester.element(find.byType(Slider)));
expect( expect(
...@@ -169,8 +133,8 @@ void main() { ...@@ -169,8 +133,8 @@ void main() {
expect( expect(
material, material,
paints paints
..rect(color: customTheme.disabledActiveTrackColor) ..rrect(color: customTheme.disabledActiveTrackColor)
..rect(color: customTheme.disabledInactiveTrackColor), ..rrect(color: customTheme.disabledInactiveTrackColor),
); );
}); });
...@@ -258,14 +222,14 @@ void main() { ...@@ -258,14 +222,14 @@ void main() {
expect(lerp.valueIndicatorTextStyle.color, equals(middleGrey.withAlpha(0xff))); 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( final ThemeData theme = ThemeData(
platform: TargetPlatform.android, platform: TargetPlatform.android,
primarySwatch: Colors.blue, primarySwatch: Colors.blue,
); );
final SliderThemeData sliderTheme = theme.sliderTheme.copyWith(thumbColor: Colors.red.shade500); 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))); final MaterialInkController material = Material.of(tester.element(find.byType(Slider)));
const Radius radius = Radius.circular(2); const Radius radius = Radius.circular(2);
...@@ -280,7 +244,7 @@ void main() { ...@@ -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), ..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 await tester.pumpAndSettle(); // wait for disable animation
// The disabled slider thumb is the same size as the enabled thumb. // The disabled slider thumb is the same size as the enabled thumb.
...@@ -292,37 +256,6 @@ void main() { ...@@ -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 { testWidgets('Default slider overlay draws correctly', (WidgetTester tester) async {
final ThemeData theme = ThemeData( final ThemeData theme = ThemeData(
platform: TargetPlatform.android, platform: TargetPlatform.android,
...@@ -428,7 +361,7 @@ void main() { ...@@ -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( final ThemeData theme = ThemeData(
platform: TargetPlatform.android, platform: TargetPlatform.android,
primarySwatch: Colors.blue, primarySwatch: Colors.blue,
...@@ -436,6 +369,7 @@ void main() { ...@@ -436,6 +369,7 @@ void main() {
final SliderThemeData sliderTheme = theme.sliderTheme.copyWith( final SliderThemeData sliderTheme = theme.sliderTheme.copyWith(
thumbColor: Colors.red.shade500, thumbColor: Colors.red.shade500,
showValueIndicator: ShowValueIndicator.always, showValueIndicator: ShowValueIndicator.always,
valueIndicatorShape: const PaddleSliderValueIndicatorShape(),
); );
Widget buildApp(String value, { double sliderValue = 0.5, double textScale = 1.0 }) { Widget buildApp(String value, { double sliderValue = 0.5, double textScale = 1.0 }) {
return MaterialApp( return MaterialApp(
...@@ -454,8 +388,6 @@ void main() { ...@@ -454,8 +388,6 @@ void main() {
label: value, label: value,
divisions: 3, divisions: 3,
onChanged: (double d) { }, onChanged: (double d) { },
// ignore: deprecated_member_use_from_same_package
useV2Slider: true,
), ),
), ),
), ),
...@@ -479,13 +411,13 @@ void main() { ...@@ -479,13 +411,13 @@ void main() {
valueIndicatorBox, valueIndicatorBox,
paints paints
..path( ..path(
includes: const <Offset>[ color: sliderTheme.valueIndicatorColor,
Offset(0.0, 0.0), includes: <Offset>[
Offset(-20.0, -12.0), const Offset(0.0, -40.0),
Offset(20.0, -34.0), const Offset(15.9, -40.0),
Offset(0.0, -38.0), const Offset(-15.9, -40.0),
], ],
color: const Color(0xf55f5f5f), excludes: <Offset>[const Offset(16.1, -40.0), const Offset(-16.1, -40.0)],
), ),
); );
...@@ -500,16 +432,14 @@ void main() { ...@@ -500,16 +432,14 @@ void main() {
expect( expect(
valueIndicatorBox, valueIndicatorBox,
paints paints
..rrect()
..rrect()
..path( ..path(
includes: const <Offset>[ color: sliderTheme.valueIndicatorColor,
Offset(0.0, 0.0), includes: <Offset>[
Offset(-30.0, -12.0), const Offset(0.0, -40.0),
Offset(30.0, -34.0), const Offset(35.9, -40.0),
Offset(0.0, -38.0), const Offset(-35.9, -40.0),
], ],
color: const Color(0xf55f5f5f), excludes: <Offset>[const Offset(36.1, -40.0), const Offset(-36.1, -40.0)],
), ),
); );
await gesture.up(); await gesture.up();
...@@ -523,17 +453,15 @@ void main() { ...@@ -523,17 +453,15 @@ void main() {
expect( expect(
valueIndicatorBox, valueIndicatorBox,
paints paints
..rrect()
..rrect()
..path( ..path(
includes: const <Offset>[ color: sliderTheme.valueIndicatorColor,
Offset(0.0, 0.0), includes: <Offset>[
Offset(-12.0, -12.0), const Offset(0.0, -40.0),
Offset(110.0, -34.0), const Offset(92.0, -40.0),
Offset(0.0, -38.0), const Offset(-16.0, -40.0),
], ],
color: const Color(0xf55f5f5f), excludes: <Offset>[const Offset(98.1, -40.0), const Offset(-20.1, -40.0)],
) ),
); );
await gesture.up(); await gesture.up();
...@@ -546,21 +474,19 @@ void main() { ...@@ -546,21 +474,19 @@ void main() {
expect( expect(
valueIndicatorBox, valueIndicatorBox,
paints paints
..rrect()
..rrect()
..path( ..path(
includes: const <Offset>[ color: sliderTheme.valueIndicatorColor,
Offset(0.0, 0.0), includes: <Offset>[
Offset(-110.0, -12.0), const Offset(0.0, -40.0),
Offset(12.0, -34.0), const Offset(16.0, -40.0),
Offset(0.0, -38.0), const Offset(-92.0, -40.0),
], ],
color: const Color(0xf55f5f5f), excludes: <Offset>[const Offset(20.1, -40.0), const Offset(-98.1, -40.0)],
) ),
); );
await gesture.up(); 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)); await tester.pumpWidget(buildApp('1000000', sliderValue: 0.0, textScale: 0.5));
center = tester.getCenter(find.byType(Slider)); center = tester.getCenter(find.byType(Slider));
gesture = await tester.startGesture(center); gesture = await tester.startGesture(center);
...@@ -569,25 +495,25 @@ void main() { ...@@ -569,25 +495,25 @@ void main() {
expect( expect(
valueIndicatorBox, valueIndicatorBox,
paints paints
..rrect()
..rrect()
..path( ..path(
includes: const <Offset>[ color: sliderTheme.valueIndicatorColor,
Offset(0.0, 0.0), includes: <Offset>[
Offset(-12.0, -12.0), const Offset(0.0, -49.0),
Offset(61.0, -16.0), const Offset(68.0, -49.0),
Offset(0.0, -20.0), const Offset(-24.0, -49.0),
], ],
excludes: const <Offset>[ excludes: <Offset>[
Offset(0.0, -38.0) 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(); await gesture.up();
// Test that the box increases in height when the text scale gets bigger. // Test that the neck shrinks when the text scale gets larger.
await tester.pumpWidget(buildApp('1000000', sliderValue: 0.0, textScale: 2.0)); await tester.pumpWidget(buildApp('1000000', sliderValue: 0.0, textScale: 2.5));
center = tester.getCenter(find.byType(Slider)); center = tester.getCenter(find.byType(Slider));
gesture = await tester.startGesture(center); gesture = await tester.startGesture(center);
// Wait for value indicator animation to finish. // Wait for value indicator animation to finish.
...@@ -595,17 +521,19 @@ void main() { ...@@ -595,17 +521,19 @@ void main() {
expect( expect(
valueIndicatorBox, valueIndicatorBox,
paints paints
..rrect()
..rrect()
..path( ..path(
includes: const <Offset>[ color: sliderTheme.valueIndicatorColor,
Offset(0.0, 0.0), includes: <Offset>[
Offset(-12.0, -16.0), const Offset(0.0, -38.8),
Offset(208.0, -40.0), const Offset(92.0, -38.8),
Offset(0.0, -50.0), 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: <Offset>[
) const Offset(98.5, -38.8),
const Offset(-16.1, -38.8),
],
),
); );
await gesture.up(); await gesture.up();
}); });
...@@ -789,38 +717,10 @@ void main() { ...@@ -789,38 +717,10 @@ void main() {
testWidgets('The slider track height can be overridden', (WidgetTester tester) async { testWidgets('The slider track height can be overridden', (WidgetTester tester) async {
final SliderThemeData sliderTheme = ThemeData().sliderTheme.copyWith(trackHeight: 16); 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 radius = Radius.circular(8);
const Radius activatedRadius = Radius.circular(9); 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))); final MaterialInkController material = Material.of(tester.element(find.byType(Slider)));
...@@ -832,7 +732,7 @@ void main() { ...@@ -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), ..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 await tester.pumpAndSettle(); // wait for disable animation
// The disabled thumb is smaller so the active track has to paint longer to // The disabled thumb is smaller so the active track has to paint longer to
...@@ -847,10 +747,10 @@ void main() { ...@@ -847,10 +747,10 @@ void main() {
testWidgets('The default slider thumb shape sizes can be overridden', (WidgetTester tester) async { testWidgets('The default slider thumb shape sizes can be overridden', (WidgetTester tester) async {
final SliderThemeData sliderTheme = ThemeData().sliderTheme.copyWith( final SliderThemeData sliderTheme = ThemeData().sliderTheme.copyWith(
thumbShape: const RoundSliderThumbShape( thumbShape: const RoundSliderThumbShape(
enabledThumbRadius: 7, enabledThumbRadius: 7,
disabledThumbRadius: 11, disabledThumbRadius: 11,
), ),
); );
await tester.pumpWidget(_buildApp(sliderTheme, value: 0.25)); await tester.pumpWidget(_buildApp(sliderTheme, value: 0.25));
...@@ -906,39 +806,6 @@ void main() { ...@@ -906,39 +806,6 @@ void main() {
final MaterialInkController material = Material.of(tester.element(find.byType(Slider))); 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( expect(
material, material,
paints paints
...@@ -947,7 +814,7 @@ void main() { ...@@ -947,7 +814,7 @@ void main() {
..circle(x: 774, y: 300, radius: 5, color: sliderTheme.inactiveTickMarkColor), ..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(); await tester.pumpAndSettle();
expect( expect(
...@@ -1029,7 +896,7 @@ void main() { ...@@ -1029,7 +896,7 @@ void main() {
final MaterialInkController material = Material.of(tester.element(find.byType(Slider))); final MaterialInkController material = Material.of(tester.element(find.byType(Slider)));
// Only 2 track segments. // Only 2 track segments.
expect(material, paintsExactlyCountTimes(#drawRect, 2)); expect(material, paintsExactlyCountTimes(#drawRRect, 2));
expect(material, paintsExactlyCountTimes(#drawCircle, 0)); expect(material, paintsExactlyCountTimes(#drawCircle, 0));
expect(material, paintsExactlyCountTimes(#drawPath, 0)); expect(material, paintsExactlyCountTimes(#drawPath, 0));
}); });
...@@ -1203,6 +1070,55 @@ void main() { ...@@ -1203,6 +1070,55 @@ void main() {
await gesture.up(); 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 { testWidgets('PaddleRangeSliderValueIndicatorShape skips all painting at zero scale', (WidgetTester tester) async {
// Pump a slider with just a value indicator. // Pump a slider with just a value indicator.
await tester.pumpWidget(_buildRangeApp( await tester.pumpWidget(_buildRangeApp(
...@@ -1265,12 +1181,11 @@ void main() { ...@@ -1265,12 +1181,11 @@ void main() {
} }
Widget _buildApp( Widget _buildApp(
SliderThemeData sliderTheme, { SliderThemeData sliderTheme, {
double value = 0.0, double value = 0.0,
bool enabled = true, bool enabled = true,
int divisions, int divisions,
bool useV2Slider = false, }) {
}) {
final ValueChanged<double> onChanged = enabled ? (double d) => value = d : null; final ValueChanged<double> onChanged = enabled ? (double d) => value = d : null;
return MaterialApp( return MaterialApp(
home: Scaffold( home: Scaffold(
...@@ -1282,8 +1197,6 @@ Widget _buildApp( ...@@ -1282,8 +1197,6 @@ Widget _buildApp(
label: '$value', label: '$value',
onChanged: onChanged, onChanged: onChanged,
divisions: divisions, divisions: divisions,
// ignore: deprecated_member_use_from_same_package
useV2Slider: useV2Slider
), ),
), ),
), ),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment