RangeSlider overlap properly (#60549)
This commit is contained in:
@@ -328,8 +328,7 @@ enum Thumb {
|
||||
/// {@macro flutter.material.slider.seeAlso.rangeSliderTickMarkShape}
|
||||
@immutable
|
||||
class SliderThemeData with Diagnosticable {
|
||||
/// Create a [SliderThemeData] given a set of exact values. All the values
|
||||
/// must be specified.
|
||||
/// Create a [SliderThemeData] given a set of exact values.
|
||||
///
|
||||
/// This will rarely be used directly. It is used by [lerp] to
|
||||
/// create intermediate themes based on two themes.
|
||||
@@ -2513,29 +2512,11 @@ class RoundRangeSliderThumbShape extends RangeSliderThumbShape {
|
||||
// Add a stroke of 1dp around the circle if this thumb would overlap
|
||||
// the other thumb.
|
||||
if (isOnTop == true) {
|
||||
bool showValueIndicator;
|
||||
switch (sliderTheme.showValueIndicator) {
|
||||
case ShowValueIndicator.onlyForDiscrete:
|
||||
showValueIndicator = isDiscrete;
|
||||
break;
|
||||
case ShowValueIndicator.onlyForContinuous:
|
||||
showValueIndicator = !isDiscrete;
|
||||
break;
|
||||
case ShowValueIndicator.always:
|
||||
showValueIndicator = true;
|
||||
break;
|
||||
case ShowValueIndicator.never:
|
||||
showValueIndicator = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!showValueIndicator || activationAnimation.value == 0) {
|
||||
final Paint strokePaint = Paint()
|
||||
..color = sliderTheme.overlappingShapeStrokeColor
|
||||
..strokeWidth = 1.0
|
||||
..style = PaintingStyle.stroke;
|
||||
canvas.drawCircle(center, radius, strokePaint);
|
||||
}
|
||||
final Paint strokePaint = Paint()
|
||||
..color = sliderTheme.overlappingShapeStrokeColor
|
||||
..strokeWidth = 1.0
|
||||
..style = PaintingStyle.stroke;
|
||||
canvas.drawCircle(center, radius, strokePaint);
|
||||
}
|
||||
|
||||
final Color color = colorTween.evaluate(enableAnimation);
|
||||
|
||||
@@ -1662,6 +1662,86 @@ void main() {
|
||||
await gesture.up();
|
||||
});
|
||||
|
||||
testWidgets('Range Slider 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(
|
||||
valueIndicatorColor: Color(0xff000001),
|
||||
showValueIndicator: ShowValueIndicator.onlyForContinuous,
|
||||
),
|
||||
);
|
||||
final SliderThemeData sliderTheme = theme.sliderTheme;
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: StatefulBuilder(
|
||||
builder: (BuildContext context, StateSetter setState) {
|
||||
return 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;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// 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();
|
||||
|
||||
/// The first circle is the thumb, the second one is the overlapping shape
|
||||
/// circle, and the last one is the second thumb.
|
||||
expect(
|
||||
find.byType(RangeSlider),
|
||||
paints
|
||||
..circle()
|
||||
..circle(color: sliderTheme.overlappingShapeStrokeColor)
|
||||
..circle()
|
||||
);
|
||||
|
||||
await gesture.up();
|
||||
|
||||
expect(
|
||||
find.byType(RangeSlider),
|
||||
paints
|
||||
..circle()
|
||||
..circle(color: sliderTheme.overlappingShapeStrokeColor)
|
||||
..circle()
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('Range Slider implements debugFillProperties', (WidgetTester tester) async {
|
||||
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user