Skip to content

Expose padEnds on PageView widget - #78558

Merged
fluttergithubbot merged 9 commits into
flutter:masterfrom
pedromassango:padEnds
Apr 22, 2021
Merged

fluttergithubbot merged 9 commits into
flutter:masterfrom
pedromassango:padEnds

Conversation

@pedromassango

@pedromassango pedromassango commented Mar 18, 2021 •

Copy link
Copy Markdown
Member

Fixes #78492
Fixes #52014

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt.
  • All existing and new tests are passing.

@flutter-dashboard

Copy link
Copy Markdown

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@flutter-dashboard flutter-dashboard Bot added the framework flutter/packages/flutter repository. See also f: labels. label Mar 18, 2021
@google-cla google-cla Bot added the cla: yes label Mar 18, 2021
@chunhtai
chunhtai self-requested a review March 19, 2021 00:01

@chunhtai chunhtai left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The page snapping doesn't seem to work correctly

repro
/// Flutter code sample for PageView

// Here is an example of [PageView]. It creates a centered [Text] in each of the three pages
// which scroll horizontally.

import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

/// This is the main application widget.
class MyApp extends StatelessWidget {
  const MyApp({Key key}) : super(key: key);

  static const String _title = 'Flutter Code Sample';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: _title,
      home: Scaffold(
        appBar: AppBar(title: const Text(_title)),
        body: const MyStatelessWidget(),
      ),
    );
  }
}

/// This is the stateless widget that the main application instantiates.
class MyStatelessWidget extends StatelessWidget {
  const MyStatelessWidget({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final PageController controller = PageController(initialPage: 0, viewportFraction: 0.5);
    return PageView(
      /// [PageView.scrollDirection] defaults to [Axis.horizontal].
      /// Use [Axis.vertical] to scroll vertically.
      scrollDirection: Axis.horizontal,
      padEnds: false,
      controller: controller,
      children: const <Widget>[
        Center(
          child: Text('First Page'),
        ),
        Center(
          child: Text('Second Page'),
        ),
        Center(
          child: Text('Third Page'),
        ),
        Center(
          child: Text('Forth Page'),
        ),
        Center(
          child: Text('Fifth Page'),
        )
      ],
    );
  }
}

@pedromassango

pedromassango commented Mar 23, 2021 •

Copy link
Copy Markdown
Member Author

I think is working, it is just that the paddings at start/end were removed and that is what I want to achieve: remove the padding at the start of the list.

gif

@chunhtai

Copy link
Copy Markdown
Contributor

I think is working, it is just that the paddings at start/end were removed and that is what I want to achieve: remove the padding at the start of the list.

I am not entirely sure what the correct behavior if snapping = true. Right now it seems like snapping is offset due to the none padding, and I don't think it can be useful.

@pedromassango

Copy link
Copy Markdown
Member Author

One of the use cases is in the docs itself:

Screen Shot 2021-03-23 at 21 50 12

I can share mine but I may take some time to share it here.

@chunhtai

chunhtai commented Mar 23, 2021 •

Copy link
Copy Markdown
Contributor

I can share mine but I may take some time to share it here.

My previous comment is confusing sorry. What I meant is I understand padEnds is useful, but the current snapping effect with padEnds = true looks wrong. We have to do something about it.

@pedromassangocode

This comment has been minimized.

@pedromassango

pedromassango commented Mar 26, 2021 •

Copy link
Copy Markdown
Member Author

We have to do something about it.

@chunhtai should this be done in this PR? I'm not sure what is wrong or what should be the expected behavior!
Cc @Piinks

@pedromassango

pedromassango commented Mar 27, 2021 •

Copy link
Copy Markdown
Member Author

[just-a-note]

Also, it would be useful to customize the the paddings: being able to specify padding-right only or padding left and provide custom values to those paddings.

@pedromassango
pedromassango requested a review from Piinks March 27, 2021 02:22
@chunhtai

chunhtai commented Mar 29, 2021 •

Copy link
Copy Markdown
Contributor

@pedromassangocode I see, It looks like snapping will be snap the page to the beginning instead of to the center. I couldn't find a material design for the animation in this case, so I don't know what is the expected behavior, neither. We can either document this behavior in the PageView.pagesnapping, or default pagesnapping to false when padEnds is true and have an assert to make sure pagesnapping is false.

Maybe @Piinks has other suggestions?

@Piinks Piinks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can either document this behavior in the PageView.pagesnapping, or default pagesnapping to false when padEnds is true and have an assert to make sure pagesnapping is false.

I think either of these options sounds fine. I am not familiar with the expected behavior, but have not been able to find anything to indicate one way or the other.

@pedromassango

Copy link
Copy Markdown
Member Author

We can either document this behavior in the PageView.pagesnapping, or default pagesnapping to false when padEnds is true and have an assert to make sure pagesnapping is false.

I will go with the first option as the page snapping may be required as well (My current use-case actually needs the snapping feature)

@Piinks Piinks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks like this branch needs to be updated for merge conflicts before moving forward.

@pedromassango

Copy link
Copy Markdown
Member Author

I will update this ASAP

# Conflicts:
#	packages/flutter/lib/src/widgets/page_view.dart
@pedromassango
pedromassango requested a review from Piinks April 20, 2021 19:07

@chunhtai chunhtai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, except some comment suggestions

@pedromassango
pedromassango requested a review from chunhtai April 21, 2021 20:49
@fluttergithubbot

This comment has been minimized.

@chunhtai

Copy link
Copy Markdown
Contributor

the test failure looks like the branch is not up to date

@pedromassango

Copy link
Copy Markdown
Member Author

Should be fine now

@fluttergithubbot

Copy link
Copy Markdown
Contributor

This pull request is not suitable for automatic merging in its current state.

  • The status or check suite Linux analyze has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite analyze-linux has failed. Please fix the issues identified (or deflake) before re-applying this label.

@yoktavian

Copy link
Copy Markdown

is it already release in the stable channel? I've update my flutter version but still no paddedEnd param in the PageView constructor

@pedromassango

Copy link
Copy Markdown
Member Author

is it already release in the stable channel?

Not yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[proposal] Provide a way to disable padEnds on PageView widget Left Aligned ViewPort in Page View

6 participants