mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Fix a slider layout bug when the overlay size is smaller than the thumb size (#74880)
This commit is contained in:
parent
29e604e241
commit
d40f4399e2
@ -1451,7 +1451,7 @@ abstract class BaseSliderTrackShape {
|
||||
assert(overlayWidth >= 0);
|
||||
assert(trackHeight >= 0);
|
||||
|
||||
final double trackLeft = offset.dx + overlayWidth / 2;
|
||||
final double trackLeft = offset.dx + math.max(overlayWidth / 2, thumbWidth / 2);
|
||||
final double trackTop = offset.dy + (parentBox.size.height - trackHeight) / 2;
|
||||
final double trackRight = trackLeft + parentBox.size.width - math.max(thumbWidth, overlayWidth);
|
||||
final double trackBottom = trackTop + trackHeight;
|
||||
|
||||
@ -852,6 +852,47 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
// Regression test for https://github.com/flutter/flutter/issues/74503
|
||||
testWidgets('The slider track layout correctly when the overlay size is smaller than the thumb size', (WidgetTester tester) async {
|
||||
final SliderThemeData sliderTheme = ThemeData().sliderTheme.copyWith(
|
||||
overlayShape: SliderComponentShape.noOverlay,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(_buildApp(sliderTheme, value: 0.5));
|
||||
|
||||
final MaterialInkController material = Material.of(
|
||||
tester.element(find.byType(Slider)),
|
||||
)!;
|
||||
|
||||
// The track rectangle begins at 10 pixels from the left of the screen and ends 10 pixels from the right
|
||||
// (790 pixels from the left). The main check here it that the track itself should be centered on
|
||||
// the 800 pixel-wide screen.
|
||||
expect(
|
||||
material,
|
||||
paints
|
||||
// active track RRect. Starts 10 pixels from left of screen.
|
||||
..rrect(rrect: RRect.fromLTRBAndCorners(
|
||||
10.0,
|
||||
297.0,
|
||||
400.0,
|
||||
303.0,
|
||||
topLeft: const Radius.circular(3.0),
|
||||
bottomLeft: const Radius.circular(3.0),
|
||||
))
|
||||
// inactive track RRect. Ends 10 pixels from right of screen.
|
||||
..rrect(rrect: RRect.fromLTRBAndCorners(
|
||||
400.0,
|
||||
298.0,
|
||||
790.0,
|
||||
302.0,
|
||||
topRight: const Radius.circular(2.0),
|
||||
bottomRight: const Radius.circular(2.0),
|
||||
))
|
||||
// The thumb.
|
||||
..circle(x: 400.0, y: 300.0, radius: 10.0, )
|
||||
);
|
||||
});
|
||||
|
||||
// Only the thumb, overlay, and tick mark have special shortcuts to provide
|
||||
// no-op or empty shapes.
|
||||
//
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user