Skip to content

PageView conflict with TabBarView during orientation change #64899

@Sid0518

Description

@Sid0518

I ran into a particularly specific problem, but the relevant code is too big to provide here, so I'll describe my widget tree as best as I can, and attach appropriate screenshots.

I have a Scaffold with a PageView as the body, along with a BottomNavigationBar which is used to change the PageView's page. The Scaffold's AppBar also updates accordingly when the BottomNavigationBar is used to change pages.
One of my PageView pages is a TabBarView with 3 tabs, so my main Scaffold's AppBar is rebuilt with a TabBar when the user navigates to this TabBarView page. Other pages do not have this, so they have the basic AppBar.

TabBarView
Page next to TabBarView

Now here's the problem:
When the user is on the TabBarView page in portrait mode, and the screen is rotated to landscape, the PageView advances one page forward by itself, so the wrong page gets aligned with the TabBar, so it gets drawn incorrectly.

TabBarView after screen rotation

The 'ard' sticking out from the left is a portion of the 'TODO: Dashboard' text which is supposed to be drawn on the next page.

This only ever happens during a screen rotation from portrait to landscape, and that too only while on the TabBarView page. A landscape to portrait rotation on the same TabBarView page does not glitch out like this, and every other page in the PageView goes through a correct portrait to landscape rotation.
No errors are raised by Flutter itself anywhere during this. I would've expected Flutter to raise an error if it was told to draw a TabBar which does not have a TabBarView below it.

I have managed to find a workaround by wrapping my PageView in an OrientationBuilder, which rebuilds the PageView on orientation change, and then I manually call jumpToPage on its PageController to set the correct page number (which I know because it's the same as the currentIndex of the BottomNavigationBar).

I don't require assistance to fix this bug (since I have fixed it myself for now), instead, I only wanted to point out this issue, so the Flutter team could look into it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    f: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.in triagePresently being triaged by the triage team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions