-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Refactor of cupertino/material/widgets app #22161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| /// The [HeroController] used for Cupertino page transitions. | ||
| /// | ||
| /// Used by [CupertinoTabView] and [CupertinoApp]. | ||
| static HeroController createCupterinoTransitionController() => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HansMuller I believe you're doing something related to this for Material right now - should this really be going in a theme somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spelling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also no need to make it abstract. Just call it createCupertinoHeroController.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#21715 makes the default transition for MaterialPageRoute a theme feature. MaterialPageRoutes use Cupertino-style horizontal page transitions on iOS by default. I don't think anyone has proposed using Cupertino-style heroics in Material apps.
|
One other change to call out: The existing logic today prevents |
| /// If the [builder] is null, the [onGenerateRoute] argument is required, and | ||
| /// corresponds to [Navigator.onGenerateRoute]. If the [builder] is non-null | ||
| /// If the [builder] is null, the [onGenerateRoute] and [pageRouteBuilder] | ||
| /// arguments are required. The [onGenerateRoute] parameters corresponds to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this read "parameter" in the singular?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Copy paste error, thanks for catching
|
I'm not particular familiar with the internals of the App Widgets, but generally LGTM. |
xster
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
| /// The [HeroController] used for Cupertino page transitions. | ||
| /// | ||
| /// Used by [CupertinoTabView] and [CupertinoApp]. | ||
| static HeroController createCupterinoTransitionController() => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spelling
| /// The [HeroController] used for Cupertino page transitions. | ||
| /// | ||
| /// Used by [CupertinoTabView] and [CupertinoApp]. | ||
| static HeroController createCupterinoTransitionController() => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also no need to make it abstract. Just call it createCupertinoHeroController.
| 'must have their initial values ' | ||
| '(null, null, and the empty list, respectively).' | ||
| ), | ||
| assert(onGenerateRoute != null || pageRouteBuilder != null), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't assume people have read the docs before / all docs and error messages should be clear independently.
This needs an error message since if people hit this check out of the blue, they won't get the relationship between onGenerateRoute and pageRouteBuilder.
| /// If this property is set, the [pageRouteBuilder] property must also be set | ||
| /// so that the default route handler will know what kind of [PageRoute]s to | ||
| /// build. | ||
| final Map<String, WidgetBuilder> routes; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This property has a default value so its set by default. Is that what we want?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes - we want to make sure it's not null (if empty, just an empty map). that's from existing code in MaterialApp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to square the property with the doc If this property is set, the [pageRouteBuilder] property must also be set. The constructor doesn't require pageRouteBuilder to be set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the doc to "If the routes map is not empty..." in b82e038
|
I'm not sure this is really the direction I would have liked us to go with this... it doesn't seem really in sync with either my Router work or Hans' route transition theme work. For this kind of low-level change in the future please make sure to get reviews from @HansMuller, @goderbauer, and/or myself. |
|
(i don't think we need to revert this, it's fine to leave as is.) |
|
Around the time of this PR, |
|
@Hixie so we know what to watch for for the future, what did you have in mind? I get the impression from your branch that *App will compose a Router which composes a Navigator. This PR just makes the 3 *App's APIs consistent. Or did you intent for the Router to only be configured by the MaterialApp but not WidgetsApp? Hans' transition theme is further down the widget tree and should be orthogonal. |
|
Right, but Navigator doesn't know about |
|
@Hixie do you have an up to date doc that explains the high level logistics of the routing solution you're working on? |
|
Ah I see, so master...Hixie:router#diff-c798125dc01f08ce6bd3a0931482078bR627 is just a parallel backward compatibility mechanism apart from The lines above said "it's most common to use the navigator created by the [Router] which itself is created and configured by a [WidgetsApp] or a [MaterialApp] widget". I thought the *App implicitly translated the Will watch out for navigation related PRs in the future. |
|
@matthew-carroll no, only the API docs on my branch. |
|
@dnfield I have a question regarding one of the asserts added to WidgetsApp in this commit. I'm trying to create a simple one page app that doesn't have any need of routes, but I want to use the WidgetsApp class so that I can get the safe area. Before this commit I had a simple implementation like this: Which was broken by this assertion: Since I'm not using routes, I don't think should need to have either of those. So I'm wondering if I'm doing this correctly and also if this was an intentional change. The flutter docs around this are not very clear. |
|
Hmm. This was intended to be a non-breaking change. The assert message on the one that is being violated was meant to explain what to do here - if you're not providing a way to do routing, you need a I suppose we could add a check to that assert for something like What do you think of that? |
|
Actually, this should be the correct assert: assert(
builder != null ||
onGenerateRoute != null ||
pageRouteBuilder != null,
'If neither builder nor onGenerateRoute are provided, the '
'pageRouteBuilder must be specified so that the default handler '
'will know what kind of PageRoute transition to build.'
), |
|
Let's continue discussion at the linked PR #23976 |
|
@roydaw The MaterialApp and WidgetsApp That said, we didn't intend to introduce a backwards-incompatible change here. In other words, just specifying a |
CupertinoAppdoes not properly process calls fromsetInitialRoutein the embedder. The root cause of this is that it tries to useCupertinoTabView(which probably was not originally intended to ever create a root navigator) to create a navigator instead ofWidgetsApp.This change fixes that, and refactors
MaterialAppandWidgetsAppto place more of the common route/home logic and documentation intoWidgetsApp.This change is intended to be completely non-breaking.
WidgetsAppcan still be invoked with the same parameters that have been valid up until now, but it can also be used with the samehome/routesstyle invocation thatMaterialAppandCupertinoApphave, but with the additional need of apageRouteBuilderto tell it which kind of page transition to build (e.g.CupertinoPageRouteorMaterialPageroute). However, it does make it possible forMaterialAppandCupertinoAppto beconst(theasserts preventing this now all live onWidgetsApp, which already couldn't beconst), so the tests had to be appropriately updated to make the analyzer happy.Fixes part of #22054 (the part reporting that
setInitialRoutedoesn't work from iOS - which was happening because I was testing with aCupertinoAppwhich didn't bother to use the property onwindowbefore)./cc @xster @HansMuller @Hixie @matthew-carroll