Skip to content

Commit cf43def

Browse files
hello-coder-xuTahaTesser
authored andcommitted
Change implementation method
1 parent 5b7526b commit cf43def

File tree

3 files changed

+47
-36
lines changed

3 files changed

+47
-36
lines changed

packages/flutter/lib/src/material/slider.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,9 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
802802
// (which can be defined by activeColor) if the
803803
// RectangularSliderValueIndicatorShape is used. In all other cases, the
804804
// value indicator is assumed to be the same as the active color.
805-
final SliderComponentShape valueIndicatorShape = sliderTheme.valueIndicatorShape ?? defaultValueIndicatorShape;
805+
final SliderComponentShape valueIndicatorShape = widget.label == null
806+
? SliderComponentShape.noThumb
807+
: sliderTheme.valueIndicatorShape ?? defaultValueIndicatorShape;
806808
final Color valueIndicatorColor;
807809
if (valueIndicatorShape is RectangularSliderValueIndicatorShape) {
808810
valueIndicatorColor = sliderTheme.valueIndicatorColor ?? Color.alphaBlend(theme.colorScheme.onSurface.withOpacity(0.60), theme.colorScheme.surface.withOpacity(0.90));

packages/flutter/lib/src/material/slider_theme.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3485,10 +3485,6 @@ class _DropSliderValueIndicatorPathPainter {
34853485
return;
34863486
}
34873487
assert(!sizeWithOverflow.isEmpty);
3488-
if (labelPainter.text == null) {
3489-
// labelPainter.text is null do not draw anything, so it's safe to just return.
3490-
return;
3491-
}
34923488
final double rectangleWidth = _upperRectangleWidth(labelPainter, scale);
34933489
final double horizontalShift = getHorizontalShift(
34943490
parentBox: parentBox,

packages/flutter/test/material/slider_theme_test.dart

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2652,27 +2652,35 @@ void main() {
26522652
(WidgetTester tester) async {
26532653
debugDisableShadows = false;
26542654
try {
2655-
await tester.pumpWidget(_buildSilderApp());
2656-
2657-
final RenderBox valueIndicatorBox =
2658-
tester.renderObject(find.byType(Overlay));
2659-
2660-
// Calculate a specific position on the Slider
2661-
final Rect sliderRect = tester.getRect(find.byType(Slider));
2662-
final Offset tapPositionLeft = Offset(
2663-
sliderRect.left + sliderRect.width * 0.25, sliderRect.center.dy);
2664-
final Offset tapPositionRight = Offset(
2665-
sliderRect.left + sliderRect.width * 0.75, sliderRect.center.dy);
2666-
2667-
// Tap on the 25% position of the Slider
2668-
await tester.tapAt(tapPositionLeft);
2669-
await tester.pumpAndSettle();
2670-
expect(valueIndicatorBox, paintsExactlyCountTimes(#drawPath, 1));
2655+
final List<SliderComponentShape> shapes = [
2656+
const PaddleSliderValueIndicatorShape(),
2657+
const DropSliderValueIndicatorShape(),
2658+
const RectangularSliderValueIndicatorShape(),
2659+
];
2660+
2661+
for (final SliderComponentShape element in shapes) {
2662+
await tester.pumpWidget(_buildSilderApp(element));
2663+
2664+
final RenderBox valueIndicatorBox =
2665+
tester.renderObject(find.byType(Overlay));
2666+
2667+
// Calculate a specific position on the Slider
2668+
final Rect sliderRect = tester.getRect(find.byType(Slider));
2669+
final Offset tapPositionLeft = Offset(
2670+
sliderRect.left + sliderRect.width * 0.25, sliderRect.center.dy);
2671+
final Offset tapPositionRight = Offset(
2672+
sliderRect.left + sliderRect.width * 0.75, sliderRect.center.dy);
2673+
2674+
// Tap on the 25% position of the Slider
2675+
await tester.tapAt(tapPositionLeft);
2676+
await tester.pumpAndSettle();
2677+
expect(valueIndicatorBox, paintsExactlyCountTimes(#drawPath, 1));
26712678

2672-
// Tap on the 75% position of the Slider
2673-
await tester.tapAt(tapPositionRight);
2674-
await tester.pumpAndSettle();
2675-
expect(valueIndicatorBox, paintsExactlyCountTimes(#drawPath, 0));
2679+
// Tap on the 75% position of the Slider
2680+
await tester.tapAt(tapPositionRight);
2681+
await tester.pumpAndSettle();
2682+
expect(valueIndicatorBox, paintsExactlyCountTimes(#drawPath, 0));
2683+
}
26762684
} finally {
26772685
debugDisableShadows = true;
26782686
}
@@ -2751,22 +2759,27 @@ Widget _buildRangeApp(
27512759
),
27522760
);
27532761
}
2754-
Widget _buildSilderApp() {
2762+
Widget _buildSilderApp(SliderComponentShape sliderComponentShape) {
27552763
double sliderValue = 10;
27562764
return MaterialApp(
27572765
home: StatefulBuilder(
27582766
builder: (BuildContext context, void Function(void Function()) setState) {
27592767
return Material(
2760-
child: Slider(
2761-
value: sliderValue,
2762-
max: 100,
2763-
label: sliderValue > 50 ? null : sliderValue.toString(),
2764-
divisions: 10,
2765-
onChanged: (double value) {
2766-
setState(() {
2767-
sliderValue = value;
2768-
});
2769-
},
2768+
child: SliderTheme(
2769+
data: SliderTheme.of(context).copyWith(
2770+
valueIndicatorShape: sliderComponentShape,
2771+
),
2772+
child: Slider(
2773+
value: sliderValue,
2774+
max: 100,
2775+
label: sliderValue > 50 ? null : sliderValue.toString(),
2776+
divisions: 10,
2777+
onChanged: (double value) {
2778+
setState(() {
2779+
sliderValue = value;
2780+
});
2781+
},
2782+
),
27702783
),
27712784
);
27722785
},

0 commit comments

Comments
 (0)