Repository navigation
Auto populate nav bar title and previous from page route - #19637
Conversation
There was a problem hiding this comment.
Is something like this ok for now until your new API or do you prefer changing didPush's signature (breaking API) or add something new?
There was a problem hiding this comment.
I couldn't quite tell from your PR. Is the convenience home: argument on MaterialApp etc going away and everything's going to be specified via Page or wtv we're going to end up calling it or is there still one exception dead-simple API for providing a home widget (to associate a default title with)?
There was a problem hiding this comment.
all the major stuff (including home) will be backwards compatible, though i am intending there to be an alternative to them that doesn't require that you use them even in the simple case.
dfa8497 to
4e93955
Compare
| /// If true and [leading] is null, automatically try to deduce what the [leading] | ||
| /// widget should be. If [leading] widget is not null, this parameter has no effect. | ||
| /// | ||
| /// Specifically [CupertinoNavigationBar] would: |
There was a problem hiding this comment.
i think maybe "will" would be better than "would" here
| /// 1. Show a 'Close' button if the current route is a `fullscreenDialog`. | ||
| /// 2. Show a back chevron with [previousPageTitle] if [previousPageTitle] is | ||
| /// not null. | ||
| /// 3. If the current route is a [CupertinoPageRoute] and the previous route |
There was a problem hiding this comment.
1 and 2 have the form "show ... if", but 3 has the form "if ... show", which is weird
| @@ -202,17 +257,19 @@ class CupertinoSliverNavigationBar extends StatelessWidget { | |||
| /// The [largeTitle] argument is required and must not be null. | |||
| const CupertinoSliverNavigationBar({ | |||
There was a problem hiding this comment.
consider using macros for the docs on this class if they're identical to the other one
There was a problem hiding this comment.
Made templates for the ones that are mostly duplicate
| left: 0.0, | ||
| right: 0.0, | ||
| bottom: 0.0, | ||
| child: new ClipRect( |
There was a problem hiding this comment.
can we avoid the cliprect? we're on a mission to remove all clips. they are too expensive.
There was a problem hiding this comment.
not really :S
Unfortunately GitHub doesn't show code moves. I just moved this block so this file flows better.
The large title actually needs to clip. I can't just hide it behind other things because the thing on top of it is translucent.
| }) { | ||
| // Auto use the CupertinoPageRoute's title if middle not provided. | ||
| if (title == null | ||
| && automaticallyImplyTitle |
There was a problem hiding this comment.
usually we try to line up the expressions so the && would be on the end of the last line (it works better they way you've done it here when using return)
There was a problem hiding this comment.
I don't have a strong opinion either way. Dartfmt seems to place them at the end. The end it is then.
| if (title == null | ||
| && automaticallyImplyTitle | ||
| && currentRoute is CupertinoPageRoute | ||
| && currentRoute.title?.isNotEmpty == true) { |
There was a problem hiding this comment.
why is an empty string special? Generally we make "null" special.
There was a problem hiding this comment.
Nothing in particular. Changed to null.
| && currentRoute.title?.isNotEmpty == true) { | ||
| return new Text(currentRoute.title); | ||
| } else { | ||
| return title; |
| // Auto use the CupertinoPageRoute's title if middle not provided. | ||
| if (title == null | ||
| && automaticallyImplyTitle | ||
| && currentRoute is CupertinoPageRoute |
There was a problem hiding this comment.
it's a pity this class has hard-coded knowledge of CupertinoPageRoute but i don't have a better solution
There was a problem hiding this comment.
Ya, as long as 'title' isn't a generic ModalRoute concept. We can introduce more abstraction like RouteTitleProvider.of(route) and have CupertinoPageRoute implement it but I think it's probably ok that the route and the nav bar is a bound concept like the uinavigationcontroller and the uinavigationitems inside uiviewcontrollers are bound concepts.
There was a problem hiding this comment.
yeah i think it's fine as you have it, just a minor blemish on an otherwise nice design.
| ); | ||
| } else { | ||
| return const SizedBox(height: 0.0, width: 0.0); | ||
| } |
There was a problem hiding this comment.
lots of returns-after-else in the last 30 lines
There was a problem hiding this comment.
Done. I left the if-else if-else at the end which seems more compact than a series of exits
| } else if (route is CupertinoPageRoute<dynamic>) { | ||
| final CupertinoPageRoute<dynamic> cupertinoRoute = route; | ||
| return new ValueListenableBuilder<String>( | ||
| valueListenable: cupertinoRoute.previousTitle, |
There was a problem hiding this comment.
this will always be a frame behind.
There was a problem hiding this comment.
I'm not super sure I get this one. Isn't the route push/replace/etc -> didChangePrevious -> ValueNotifier.set -> notifyListeners -> setState chain all happening one frame before the widget being first built?
There was a problem hiding this comment.
you're right, i was wrong. for some reason i was thinking the listenable interface notified on microtasks, but that's streams, not listenables.
There was a problem hiding this comment.
Added some code comments and a test
| /// See also: | ||
| /// | ||
| /// * [AnimatedBuilder], which invokes a builder on [Animation] ticks rather | ||
| /// than a [ValueListenable] changing value. |
There was a problem hiding this comment.
Specifically, this seems wrong. AnimatedBuilder doesn't invoke things based on Animation ticks, it's in fact more general than this class. It ticks on any Listenable.
There was a problem hiding this comment.
(this comment was meant to be on the other PR that includes this code)
There was a problem hiding this comment.
Right. Changed (in the other PR)
d112f5b to
55fe8ee
Compare
|
Looks like you have a merge error here (see e.g. the top change on your PR). |
f1f3866 to
ed31d97
Compare
|
Cleaned up the const lints |
|
|
Diffbases #19729
xster/flutter@value_listenable_builder...xster:nav-bar-title-2
First step for #9446