Do not crash if the controller and TabBarView are updated at different phases (build and layout) of the same frame.#104998
Conversation
| } | ||
|
|
||
| bool _debugScheduleCheckHasValidTabsCount() { | ||
| WidgetsBinding.instance.addPostFrameCallback((Duration duration) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
That would mean the error will be thrown twice if the length is indeed inconsistent at the end of the frame.
|
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. |
|
For slivers we're only adding/removing children on demand so there doesn't appear to be a double build problem. For |
…different phases (build and layout) of the same frame. (flutter/flutter#104998)
…different phases (build and layout) of the same frame. (flutter/flutter#104998)
…different phases (build and layout) of the same frame. (flutter/flutter#104998)
…different phases (build and layout) of the same frame. (flutter/flutter#104998)
…different phases (build and layout) of the same frame. (flutter/flutter#104998)
…different phases (build and layout) of the same frame. (flutter/flutter#104998)
…different phases (build and layout) of the same frame. (flutter/flutter#104998)
…different phases (build and layout) of the same frame. (flutter/flutter#104998)
…t phases (build and layout) of the same frame. (flutter#104998)
…different phases (build and layout) of the same frame. (flutter/flutter#104998)
…different phases (build and layout) of the same frame. (flutter/flutter#104998)
Fixes #104994
If wrap the
TabBarViewor 'TabBar' under aLayoutBuilderbut let theDefaultTabControllerout of theLayoutBuilder, it may be thrown.This is because the
TabBarViewor '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.