Skip to content

Conversation

@brettmeemo
Copy link
Contributor

@brettmeemo brettmeemo commented Jul 11, 2019

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.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require Flutter developers to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (Please read Handling breaking changes). Replace this with a link to the e-mail where you asked for input on this proposed change.
  • No, this is not a breaking change.

@googlebot
Copy link

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. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@fluttergithubbot fluttergithubbot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Jul 11, 2019
@brettmeemo
Copy link
Contributor Author

I have signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@dnfield
Copy link
Contributor

dnfield commented Jul 12, 2019

Thanks for the contribution!

Can you add a test for this?

@HansMuller
Copy link
Contributor

CC @clocksmith

@HansMuller HansMuller changed the title fixing preferred height Fix slider preferred height Jul 17, 2019
@clocksmith clocksmith self-assigned this Jul 17, 2019
@clocksmith
Copy link
Contributor

LGTM, but please add a test

@brettmeemo
Copy link
Contributor Author

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.

@dnfield
Copy link
Contributor

dnfield commented Jul 24, 2019

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);
  }
}

@clocksmith
Copy link
Contributor

@dnfield Shouldn't this height > width case be for the whole Slider component (the inner RenderBox), not just the TickMarkShape?

@dnfield
Copy link
Contributor

dnfield commented Jul 24, 2019

@clocksmith - any one of those will cause the height to be higher

Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@clocksmith clocksmith merged commit 38fdf56 into flutter:master Jul 26, 2019
johnsonmh pushed a commit to johnsonmh/flutter that referenced this pull request Jul 30, 2019
[Material] Fix slider preferred height
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants