Replies: 1 comment 3 replies
-
The issue seem to be that you are changing the shape of the widget tree during the transition, which is typically not recommended. Rather than doing
consider:
This way, the shape of the widget tree does not change, and during the transition, the InheritedWidget will still exist. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Intro
This was noticed while using the Router API (specifically, with beamer package, but this has shown irrelevant): slovnicki/beamer#328. The original issue is using
flutter_bloc
package, but it relies onprovider
concerning the issue in question, so this is also irrelevant. Then it seemed like a transition issue in flutter, but I found it doesn't show the error with regularInheritedWidget
s as shown in the snippet bellow.Describe the bug
Say we have 2
Navigator
widgets; one with 1 page (BooksList
) and the other with 2 pages (BooksList
,BookDetails
). We would like to provide some data to firstNavigator
and some other data to the secondNavigator
so we wrap them in providers. When we are in a situation with[BooksList, BookDetails]
as our pages (i.e. having built the secondNavigator
) and do apop
(i.e. effectively build the firstNavigator
), there is some transition happening where the first page is still "getting off the screen", but provider is no longer there so we get an error in the console and also a brief red error screen built:About the Router API
With the Router API, we are rebuilding the
Navigator
widget with newList
ofpages
every time we want to navigate. There might be some default or custom transitions in between; how pages are getting on and off the screen. So this is all about (re)building the page stack and we might want different page stacks be provided with different data.It's still a Flutter issue also
Although the snippet with
InheritedWidget
s is not showing the error, it is showing a white background for a moment, meaning it also has no access to the data (because the data in question isColor
for theScaffold
's background). There is no error becausedependOnInheritedWidgetOfExactType
returns a nullable type so we pass effectivelybackgroundColor: null
when doingbackgroundColor: DetailsData.of(context)?.color
.Honestly, there's nothing much to be done here and it seems like such a deep problem. I would like to hear your thought on this. Of course these snippets are not a real-life use case for this problem and of course we can just put providers above everything, but should we limit ourselves to never scoping our data to specific page stacks (think all possible "shop page stacks" and all possible "account page stacks" built under a single
RouterDelegate
and say we deep-link from account to favorite product on shop)?To Reproduce
AppBar
's back button topop
(this causes the error)(Note: The green and yellow background colors are the data being provided)
Expected behavior
No errors are shown with both app snippets. (or the error should be shown, but red screen not)
Actual behavior
Error is printed and red error screen briefly built when using Providers snippet.
Lengthy code snippets
Snippets are not below 100 lines, but this is pretty much as low as it can go with Router API without using any navigation packages. These snippets are copied from John's gist that was used for his "Learning Flutter’s new navigation and routing system" article, I only migrated them to null safety and made a few lint tweaks.
Providers
Inherited Widgets
Beta Was this translation helpful? Give feedback.
All reactions