Skip to content

Left Aligned ViewPort in Page View #52014

Closed

Description

@vivekkannavenus

How it works

PageView widget looks cool but when we set viewportFraction, the view gets center aligned.

If viewportFraction sets

PageView(
   viewportFraction: 0.8
)

Center-Aligned view port

How I expect

But what I need is the view to start with left-aligned like how playstore dashboard works.

There should be some gravity attribute and based on the value,
the view has to start with the respective position.

Left-Aligned view port
The above screenshot has taken from the Google Play Store.

I've also posted a query in StackOverflow
https://stackoverflow.com/questions/60547319/flutter-how-to-left-align-view-port-in-pageview

Activity

  1. VladyslavBondarenko commented on Mar 5, 2020

    @VladyslavBondarenko

    Hi @vivekkannavenus
    Among similar I found only this https://stackoverflow.com/questions/56871898/align-a-flutter-pageview-to-the-screen-left
    There is gist in the solution, where I can change align by editing value in the line final portion = (position.extentInside - itemDimension) / 2;
    But this is another case, not about PageController with viewportFraction

  2. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    c: new featureNothing broken; request for a new capability
    on Mar 5, 2020
  3. vivekkannavenus commented on Mar 5, 2020

    @vivekkannavenus
    Author

    @VladyslavBondarenko Thanks for referring the mere same stuff.
    It works but has some stability issues like this code doesn't work effectively when page view items dynamically change.

  4. yousifk commented on May 31, 2020

    @yousifk

    It is helpful to add this feature.

  5. payam-zahedi commented on Aug 8, 2020

    @payam-zahedi
    Contributor

    Hi @VladyslavBondarenko , I want to create PR for this issue. I check out the source code and I saw there is a SliverFillViewport widget that maybe we can wrap it with align. do you have any idea about how can I solve this?

    @override
      Widget build(BuildContext context) {
        final AxisDirection axisDirection = _getDirection(context);
        final ScrollPhysics physics = _ForceImplicitScrollPhysics(
          allowImplicitScrolling: widget.allowImplicitScrolling,
        ).applyTo(widget.pageSnapping
            ? _kPagePhysics.applyTo(widget.physics)
            : widget.physics);
    
        return NotificationListener<ScrollNotification>(
          onNotification: (ScrollNotification notification) {
            if (notification.depth == 0 && widget.onPageChanged != null && notification is ScrollUpdateNotification) {
              final PageMetrics metrics = notification.metrics as PageMetrics;
              final int currentPage = metrics.page.round();
              if (currentPage != _lastReportedPage) {
                _lastReportedPage = currentPage;
                widget.onPageChanged(currentPage);
              }
            }
            return false;
          },
          child: Scrollable(
            dragStartBehavior: widget.dragStartBehavior,
            axisDirection: axisDirection,
            controller: widget.controller,
            physics: physics,
            viewportBuilder: (BuildContext context, ViewportOffset position) {
              return Viewport(
                // TODO(dnfield): we should provide a way to set cacheExtent
                // independent of implicit scrolling:
                // https://github.com/flutter/flutter/issues/45632
                cacheExtent: widget.allowImplicitScrolling ? 1.0 : 0.0,
                cacheExtentStyle: CacheExtentStyle.viewport,
                axisDirection: axisDirection,
                offset: position,
                slivers: <Widget>[
                  SliverFillViewport(
                    viewportFraction: widget.controller.viewportFraction,
                    delegate: widget.childrenDelegate,
                  ),
                ],
              );
            },
          ),
        );
      }```
  6. spareblock commented on Aug 29, 2020

    @spareblock

    Any update on this?

  7. ScottMacDougall commented on Oct 3, 2020

    @ScottMacDougall

    Would love to see this addressed.

  8. PaulVinSoft249 commented on Oct 5, 2020

    @PaulVinSoft249

    I have a solution for this... Would be happy to share... PR

  9. PaulVinSoft249 commented on Oct 9, 2020

    @PaulVinSoft249

    ezgif-2-67bd8fd1188f

  10. Dariel-G commented on Oct 27, 2020

    @Dariel-G

    I have a solution for this... Would be happy to share... PR

    @PaulVinSoft249 Can you share the solution for alignin pageview to the left side?

  11. edemekong commented on Oct 30, 2020

    @edemekong

    @Dariel11
    Yes bro,
    I will be writing a PR on this. But anyway I can share it.

  12. edemekong commented on Oct 30, 2020

    @edemekong
  13. divid3d commented on Dec 16, 2020

    @divid3d

    https://gist.github.com/hello-paulvin/0aa8b6389e3aeb345fa1f3f246d9ab69#file-gistfile1-txt

    You can open that and check it out :)

    Is there option to align to the left last item same as previous?

  14. harrisonturton commented on Mar 11, 2021

    @harrisonturton

    I've run into this issue when trying to implement a dynamically-sized TabController and TabBarView interface. In other words, an app organised into different tabs, where the user can add and remove tabs at runtime.

    Most StackOverflow answers say to use PageController and PageView instead. But in order to implement a TabBar equivalent, you need to use another PageView synchronised with the main content PageView. The viewportFraction then needs to be less than 1.0 to see multiple tabs on the same page. If the PageView cannot be left-aligned, implementing this becomes significantly more difficult.

  15. uzuki-P commented on May 2, 2021

    @uzuki-P

    Any update on this?

  16. daixianceng commented on May 11, 2021

    @daixianceng

    padEnds还不能用啊

  17. srikanth-vm commented on Jun 3, 2021

    @srikanth-vm

    padEnds on which widget ? I don't see that option on page view.

  18. github-actions commented on Jul 31, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  19. locked as resolved and limited conversation to collaborators on Jul 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: new featureNothing broken; request for a new capabilityf: scrollingViewports, list views, slivers, etc.frameworkflutter/packages/flutter repository. See also f: labels.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions