Skip to content

Conversation

@xu-baolin
Copy link
Member

@xu-baolin xu-baolin commented May 31, 2022

Fixes #104994

If wrap the TabBarView or 'TabBar' under a LayoutBuilder but let the DefaultTabController out of the LayoutBuilder, it may be thrown.

This is because the TabBarView or 'TabBar' will be updated later in the layout phase.
So I just move the checker to the post-frame phase.

This also blocks #104958 landing.

@flutter-dashboard flutter-dashboard bot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels May 31, 2022
@xu-baolin xu-baolin requested a review from goderbauer May 31, 2022 06:16
}

bool _debugScheduleCheckHasValidTabsCount() {
WidgetsBinding.instance.addPostFrameCallback((Duration duration) {
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 TabBarView widget is in a LayoutBuilder and the DefaultTabBarController is not, build will be called twice in the same frame and the post frame callback will be scheduled twice.

Copy link
Contributor

@LongCatIsLooong LongCatIsLooong Jun 2, 2022

Choose a reason for hiding this comment

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

That would mean the error will be thrown twice if the length is indeed inconsistent at the end of the frame.

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.

@LongCatIsLooong
Copy link
Contributor

LongCatIsLooong commented Jun 2, 2022

LGTM modulo comments, as I don't know any other way to get around this. I had a pull request that tries to prevent widgets inside of a LayoutBuilder from being rebuilt twice but I stopped working on that because of lack of interest. Do you mind if I repurpose #104994 for double rebuild in layout builder? If we can fix that we'll be able to remove the post frame checks back to the build method.

@xu-baolin
Copy link
Member Author

LGTM modulo comments, as I don't know any other way to get around this. I had a pull request that tries to prevent widgets inside of a LayoutBuilder from being rebuilt twice but I stopped working on that because of lack of interest. Do you mind if I repurpose #104994 for double rebuild in layout builder? If we can fix that we'll be able to remove the post frame checks back to the build method.

I'm curious how we can identify widgets under a LayoutBuilder elegant. Even if we do, we also need to ensure that multiple builds during a frame cannot throw. Because in the lazy loaded sliver, the build will also happen in the layout phase.

@LongCatIsLooong
Copy link
Contributor

For slivers we're only adding/removing children on demand so there doesn't appear to be a double build problem. For LayoutBuilder we can prevent the first buildScope from processing nodes in side a LayoutBuilder to prevent the double build.

@fluttergithubbot fluttergithubbot merged commit d73f7ad into flutter:master Jun 6, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Jun 7, 2022
…different phases (build and layout) of the same frame. (flutter/flutter#104998)
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 7, 2022
…different phases (build and layout) of the same frame. (flutter/flutter#104998)
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 7, 2022
…different phases (build and layout) of the same frame. (flutter/flutter#104998)
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 7, 2022
…different phases (build and layout) of the same frame. (flutter/flutter#104998)
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 7, 2022
…different phases (build and layout) of the same frame. (flutter/flutter#104998)
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 7, 2022
…different phases (build and layout) of the same frame. (flutter/flutter#104998)
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 7, 2022
…different phases (build and layout) of the same frame. (flutter/flutter#104998)
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 7, 2022
…different phases (build and layout) of the same frame. (flutter/flutter#104998)
camsim99 pushed a commit to camsim99/flutter that referenced this pull request Aug 10, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 30, 2022
…different phases (build and layout) of the same frame. (flutter/flutter#104998)
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Aug 30, 2022
…different phases (build and layout) of the same frame. (flutter/flutter#104998)
@hgraceb hgraceb mentioned this pull request Sep 1, 2024
9 tasks
auto-submit bot pushed a commit that referenced this pull request Sep 8, 2024
Fixes #154484 

Similar to #104998. Cause with updated at different phases of the same frame.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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.

TabBarView may throw out when work with LayoutBuilder

3 participants