Commit 38fdf56c authored by brettfingo's avatar brettfingo Committed by Anthony

Fix slider preferred height (#36028)

[Material] Fix slider preferred height
parent 9c8badd1
...@@ -698,7 +698,7 @@ class _RenderSlider extends RenderBox { ...@@ -698,7 +698,7 @@ class _RenderSlider extends RenderBox {
// other than the track shape. It is assumed that these shapes are vertically // other than the track shape. It is assumed that these shapes are vertically
// centered on the track. // centered on the track.
double get _maxSliderPartWidth => _sliderPartSizes.map((Size size) => size.width).reduce(math.max); double get _maxSliderPartWidth => _sliderPartSizes.map((Size size) => size.width).reduce(math.max);
double get _maxSliderPartHeight => _sliderPartSizes.map((Size size) => size.width).reduce(math.max); double get _maxSliderPartHeight => _sliderPartSizes.map((Size size) => size.height).reduce(math.max);
List<Size> get _sliderPartSizes => <Size>[ List<Size> get _sliderPartSizes => <Size>[
_sliderTheme.overlayShape.getPreferredSize(isInteractive, isDiscrete), _sliderTheme.overlayShape.getPreferredSize(isInteractive, isDiscrete),
_sliderTheme.thumbShape.getPreferredSize(isInteractive, isDiscrete), _sliderTheme.thumbShape.getPreferredSize(isInteractive, isDiscrete),
......
...@@ -46,6 +46,28 @@ class LoggingThumbShape extends SliderComponentShape { ...@@ -46,6 +46,28 @@ class LoggingThumbShape extends SliderComponentShape {
} }
} }
class TallSliderTickMarkShape extends SliderTickMarkShape {
@override
Size getPreferredSize({SliderThemeData sliderTheme, bool isEnabled}) {
return const Size(10.0, 200.0);
}
@override
void paint(
PaintingContext context,
Offset offset, {
Offset thumbCenter,
RenderBox parentBox,
SliderThemeData sliderTheme,
Animation<double> enableAnimation,
bool isEnabled,
TextDirection textDirection,
}) {
final Paint paint = Paint()..color = Colors.red;
context.canvas.drawRect(Rect.fromLTWH(offset.dx, offset.dy, 10.0, 20.0), paint);
}
}
void main() { void main() {
testWidgets('Slider can move when tapped (LTR)', (WidgetTester tester) async { testWidgets('Slider can move when tapped (LTR)', (WidgetTester tester) async {
final Key sliderKey = UniqueKey(); final Key sliderKey = UniqueKey();
...@@ -1485,4 +1507,44 @@ void main() { ...@@ -1485,4 +1507,44 @@ void main() {
await gesture.moveBy(const Offset(600.0, 0.0)); await gesture.moveBy(const Offset(600.0, 0.0));
expect(value, 1.0); expect(value, 1.0);
}); });
testWidgets('Slider respects height from theme', (WidgetTester tester) async {
final Key sliderKey = UniqueKey();
double value = 0.0;
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
final SliderThemeData sliderTheme = SliderTheme.of(context).copyWith(tickMarkShape: TallSliderTickMarkShape());
return MediaQuery(
data: MediaQueryData.fromWindow(window),
child: Material(
child: Center(
child: IntrinsicHeight(
child: SliderTheme(
data: sliderTheme,
child: Slider(
key: sliderKey,
value: value,
divisions: 4,
onChanged: (double newValue) {
setState(() {
value = newValue;
});
},
),
),
),
),
),
);
},
),
),
);
final RenderBox renderObject = tester.renderObject<RenderBox>(find.byType(Slider));
expect(renderObject.size.height, 200);
});
} }
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