Skip to content

Added 'physics' prop to Stepper.#26297

Merged
HansMuller merged 19 commits intoflutter:masterfrom
soupjake:master
Feb 12, 2019
Merged

Added 'physics' prop to Stepper.#26297
HansMuller merged 19 commits intoflutter:masterfrom
soupjake:master

Conversation

@soupjake
Copy link

@soupjake soupjake commented Jan 9, 2019

Added 'physics' prop which allows the developer to assign the Stepper's scroll view's 'ScrollPhysics' which can solve with unwanted scrolling behaviour if the parent is also a scroll view.

Fixes #19513

Added 'physics' prop which allows the developer to assign the Stepper's scroll view's 'ScrollPhysics' which can solve with unwanted scrolling behaviour if the parent is also a scroll view. Defaults to 'AlwaysScrollableScrollPhysics' if null.
@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

@soupjake
Copy link
Author

soupjake commented Jan 9, 2019

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes and removed cla: no labels Jan 9, 2019
@zoechi zoechi added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Jan 9, 2019
Removed unnecessary import and defaulting to 'AlwaysScrollableScrollPhysics' if physics prop is null.
@dnfield
Copy link
Contributor

dnfield commented Jan 11, 2019

Analysis is still unhappy because of whitespace at the end of a line - can you fix that up?

@dnfield
Copy link
Contributor

dnfield commented Jan 11, 2019

Can you add a test that fails without this change?

e.g. a test that shows how you're able to get rid of the unwanted scrolling behavior you mention

Ran through format to remove unwanted whitespace which Analysis isn't happy about.
@soupjake
Copy link
Author

soupjake commented Jan 14, 2019

Ran it through the VSCode Format command so hope that solved the whitespace issue.

I'm not sure how to create a unit test to demonstrate why I'm proposing this PR but let's say we have a ListView including a Stepper:

ListView(
        children: <Widget>[
          Text('long text'),
          Stepper(
              //stuff here
              ),
          Text('more long text'),

The ListView within the Stepper will mess with the parent ListView resulting in the user being unable to scroll down the page:

With adding a physics prop to the Stepper, the developer is easily able to prevent this from happening by using another kind of ScrollPhysics such as ClampingScrollPhysis which results in this:

ListView(
        children: <Widget>[
          Text('long text'),
          Stepper(
              physics: ClampingScrollPhysics(),
              //other stuff here
              ),
          Text('more long text'),

You could achieve this using a NestedScrollView and setting up a ScrollController etc but I think this simple change results in the same result with it being far easier to implement as the developer.

@dnfield
Copy link
Contributor

dnfield commented Jan 14, 2019

We don't really have a lot of success with dartfmt on this repo, unfortunately. It does some strange things with linebreaks that don't fit with the style of the repo. VSCode actually has a setting to trim whitespace for you:

image

Can you revert the dartfmt for this and reapply your other changes?

As far as a test goes, you should be able to create a testWidgets that creates your problematic scenario, uses a tester.tap or tester.fling or somesuch to try to scroll it, and verify what's visible on the screen. With physics set to null, you should be able to expect that the first list item is still visible - with it set to ClampingScrollPhysics you should expect to see new items visible.

Jake Gough added 6 commits January 15, 2019 08:42
Tried reformatting again.
Tried reformatting again.
Formatting again why do you hate me github editor.
if this format doesn't work i'll cry
Added Stepper scroll tests. One that fails to find Text after Stepper if physics left as null and one that succeeds if physics set to `ClampingScrollPhysics()`
@soupjake
Copy link
Author

Okay got the format right (finally) and added tests. Let me know if these are acceptable and thanks for helping (you can really tell this is my first PR to a Google project).

Jake Gough added 5 commits January 15, 2019 12:15
Added const constructors
trying to get rid of whitespace again
why whitespace why
Jake Gough added 3 commits January 15, 2019 13:09
@HansMuller
Copy link
Contributor

Sorry this has taken so long to reach the finish line!

I'm going to fix up the last formatting problems and a note to the physics property doc about using ClampingScrollPhysics when the stepper is used within another scrolling container. And then, when the build is green I'll land the changes.

Thanks again for your contribution!

@tomosullivan8
Copy link

Can we get the Stepper's physics to also be implemented for StepperType.horizontal? I've changed it manually for now but presume the physics needs to be updated for the ListView where StepperType.horizontal?

@DrFrancky
Copy link

DrFrancky commented Dec 30, 2019

Temp solution is to add:
physics: widget.physics,
after Expanded( child: ListView(
near line 671 in file stepper.dart

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 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.

Stepper should have a no scroll option

7 participants