Skip to content

Conversation

@xu-baolin
Copy link
Member

@xu-baolin xu-baolin commented Aug 26, 2020

Description

This PR change Slider can not be painted in a narrower constraint like other Material Widgets such as Switch.

If I just remove the assert checks, the fellow demo code paint Slider incorrectly below(the active track and inactive track switched mistake), so I modify the getPreferredRect logic.
image

After change:
image

The issue #64629 root cause is that, when minimizing the window the screen size will change to zero and trigger a flushPaint.
This change does make the appearance of the issue disappear, but I am not sure whether the window size change to zero is intended, I think we can track that at a new issue, right?

DEMO

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';

void main() {
  debugPaintLayerBordersEnabled = true;
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  double value = 0.5;
  _onChange(newValue) {
    setState(() {
      print('$newValue');
      value = newValue;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Directionality(
      textDirection: TextDirection.ltr,
      child: Center(
        child: RepaintBoundary(
          child: SizedBox(
            width: 10,
            height: 10,
            child: Slider(
              value: value,
              onChanged: _onChange,
            ),
          ),
        ),
      ),
    ));
  }
}

Related Issues

Fixes #64629

Tests

I added the following tests:

See files.

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 read the Tree Hygiene wiki page, which explains my responsibilities.
  • 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

Did any tests fail when you ran them? Please read Handling breaking changes.

@flutter-dashboard flutter-dashboard bot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Aug 26, 2020
Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

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

This looks OK to me. It would be helpful to include a screenshot in the PR's description, to demo what happens when the width gets small.

Deferring to Anthony and Jose...

return Rect.fromLTWH(trackLeft, trackTop, trackWidth, trackHeight);
final double trackRight = trackLeft + parentBox.size.width - math.max(thumbWidth, overlayWidth);
final double trackButtom = trackTop + trackHeight;
// if the parentBox.size < slider's size, the trackRight will less then trackLeft, we need switch them.
Copy link
Contributor

Choose a reason for hiding this comment

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

If the .. will be less.., so switch them.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

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

Need to fixup the analyzer errors..

@xu-baolin
Copy link
Member Author

Need to fixup the analyzer errors..

Fixed. I update the PR description above.

@xu-baolin xu-baolin requested a review from HansMuller August 27, 2020 07:16
isDiscrete: isDiscrete,
);
final Rect leftTrackSegment = Rect.fromLTRB(trackRect.left, trackRect.top, leftThumbOffset.dx - thumbRadius, trackRect.bottom);
final Rect leftTrackSegment = Rect.fromLTRB(trackRect.left, trackRect.top, leftThumbOffset.dx, trackRect.bottom);
Copy link
Member Author

Choose a reason for hiding this comment

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

I remove the gap between the inactive track and active track, also see #64534

@xu-baolin xu-baolin changed the title Slider can be painted in a narrower constraint like other Material Wi… Slider and RangeSlider can be painted in a narrower constraint like other Material Wi… Aug 28, 2020
@xu-baolin
Copy link
Member Author

@clocksmith Hi, please review. :)

Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

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

The inexplicable extra import of dart:math in slider.dart could be broken out as a separate PR. Should be a quickie.

@xu-baolin
Copy link
Member Author

The inexplicable extra import of dart:math in slider.dart could be broken out as a separate PR. Should be a quickie.

OK, I will do it right now.

@xu-baolin
Copy link
Member Author

The inexplicable extra import of dart:math in slider.dart could be broken out as a separate PR. Should be a quickie.

Done. #65060

Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

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

LGTM

@fluttergithubbot fluttergithubbot merged commit c7353bc into flutter:master Sep 2, 2020
mingwandroid pushed a commit to mingwandroid/flutter that referenced this pull request Sep 6, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 2, 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.

Minimize the app window will trigger a Slider assert

5 participants