-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Fix slider preferred height #36028
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix slider preferred height #36028
Conversation
|
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here (e.g. What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
|
I have signed it! |
|
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
|
Thanks for the contribution! Can you add a test for this? |
|
CC @clocksmith |
|
LGTM, but please add a test |
|
I'm sorry but I don't have time to write a test, if someone would like to do this fix and write a test I'd be happy to close this PR and let that one merge. |
|
Unfortunately we can't merge a change like this without a test. I did a little digging to see what a test for this would look like, and it looks like this code passes today because all the implementations that touch these properties use sizes where height == width. So a test should create a property where the height > width, pass it into the theme, and make sure the widget is laid out correctly. 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);
});Where TallSliderTickMarkShape is something like: 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);
}
} |
|
@dnfield Shouldn't this height > width case be for the whole Slider component (the inner RenderBox), not just the TickMarkShape? |
|
@clocksmith - any one of those will cause the height to be higher |
dnfield
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
[Material] Fix slider preferred height
Description
This PR fixes the preferred height of the slider.
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]). This will ensure a smooth and quick review process.///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change
Does your PR require Flutter developers to manually update their apps to accommodate your change?