mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Slider paint incorrectly when the track shape is rectangular (#64534)
This commit is contained in:
parent
f1a2357463
commit
c26c2363a0
@ -1560,12 +1560,10 @@ class RectangularSliderTrackShape extends SliderTrackShape with BaseSliderTrackS
|
|||||||
isDiscrete: isDiscrete,
|
isDiscrete: isDiscrete,
|
||||||
);
|
);
|
||||||
|
|
||||||
final Size thumbSize = sliderTheme.thumbShape.getPreferredSize(isEnabled, isDiscrete);
|
final Rect leftTrackSegment = Rect.fromLTRB(trackRect.left, trackRect.top, thumbCenter.dx, trackRect.bottom);
|
||||||
|
|
||||||
final Rect leftTrackSegment = Rect.fromLTRB(trackRect.left + trackRect.height / 2, trackRect.top, thumbCenter.dx - thumbSize.width / 2, trackRect.bottom);
|
|
||||||
if (!leftTrackSegment.isEmpty)
|
if (!leftTrackSegment.isEmpty)
|
||||||
context.canvas.drawRect(leftTrackSegment, leftTrackPaint);
|
context.canvas.drawRect(leftTrackSegment, leftTrackPaint);
|
||||||
final Rect rightTrackSegment = Rect.fromLTRB(thumbCenter.dx + thumbSize.width / 2, trackRect.top, trackRect.right, trackRect.bottom);
|
final Rect rightTrackSegment = Rect.fromLTRB(thumbCenter.dx, trackRect.top, trackRect.right, trackRect.bottom);
|
||||||
if (!rightTrackSegment.isEmpty)
|
if (!rightTrackSegment.isEmpty)
|
||||||
context.canvas.drawRect(rightTrackSegment, rightTrackPaint);
|
context.canvas.drawRect(rightTrackSegment, rightTrackPaint);
|
||||||
}
|
}
|
||||||
|
@ -2359,4 +2359,41 @@ void main() {
|
|||||||
'inactiveColor: MaterialColor(primary value: Color(0xff9e9e9e))',
|
'inactiveColor: MaterialColor(primary value: Color(0xff9e9e9e))',
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('Slider paint correctly when the track shape is rectangular', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
theme: ThemeData(
|
||||||
|
sliderTheme: const SliderThemeData(
|
||||||
|
trackShape: RectangularSliderTrackShape(),
|
||||||
|
)
|
||||||
|
),
|
||||||
|
home: Directionality(
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
child: MediaQuery(
|
||||||
|
data: MediaQueryData.fromWindow(window),
|
||||||
|
child: const Material(
|
||||||
|
child: Center(
|
||||||
|
child: Slider(
|
||||||
|
value: 0.5,
|
||||||
|
onChanged: null,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
// _RenderSlider is the last render object in the tree.
|
||||||
|
final RenderObject renderObject = tester.allRenderObjects.last;
|
||||||
|
|
||||||
|
// The active track rect should start at 24.0 pixels,
|
||||||
|
// and there should not have a gap between active and inactive track.
|
||||||
|
expect(renderObject,
|
||||||
|
paints
|
||||||
|
..rect(rect: const Rect.fromLTRB(24.0, 298.0, 400.0, 302.0)) // active track Rect.
|
||||||
|
..rect(rect: const Rect.fromLTRB(400.0, 298.0, 776.0, 302.0)) // inactive track Rect.
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user