Skip to content

Conversation

@xster
Copy link
Member

@xster xster commented May 26, 2017

#7508

Wasn't trivial to make the middle widget fill the rest of the space and still center itself wrt to the parent. Pull out the layout delegate thing to widget.

@xster xster force-pushed the common-nav-bar branch from 839810d to 3206361 Compare May 26, 2017 02:30

/// Widget to place at the start of the horizontal toolbar.
final Widget leading;
/// Widget to place in the middle of the horizontal toolbar, occupying
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: blank line between fields

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

const double _kMiddleMargin = 16.0;

class _ToolbarLayout extends MultiChildLayoutDelegate {
_ToolbarLayout({ this.centerMiddle });
Copy link
Contributor

Choose a reason for hiding this comment

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

this can probably be const?

Copy link
Member Author

Choose a reason for hiding this comment

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

I might be wrong but it could be a bigger refactor, since the super has some non final fields.

if (hasChild(_ToolbarSlot.leading)) {
final BoxConstraints constraints = new BoxConstraints(
minWidth: 0.0,
maxWidth: size.width / 3, // The leading widget shouldn't take up more than 1/3 of the space.
Copy link
Contributor

Choose a reason for hiding this comment

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

3.0 to avoid int/double conversion

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah thanks!

Should be a linter for this :)

}

if (hasChild(_ToolbarSlot.middle)) {
final double maxWidth = math.max(size.width - leadingWidth - trailingWidth - _kMiddleMargin * 2, 0.0);
Copy link
Contributor

Choose a reason for hiding this comment

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

  • 2.0 for same reason

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. Thanks

expect(tester.getTopLeft(title).dx, 72.0);
// The toolbar's contents are padded on the right by 4.0
expect(tester.getSize(title).width, equals(800.0 - 72.0 - 4.0));
expect(tester.getSize(title).width, equals(800.0 - 4.0 - 16.0 - 56.0 - 16.0));
Copy link
Contributor

Choose a reason for hiding this comment

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

why did this change?

Copy link
Member Author

Choose a reason for hiding this comment

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

72.0 was a bunch of stuff previously bundled together. Was a bit too implicit.
It was also previously missing a margin on the right side between the title and the actions. Readjusted slightly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, cool.

If you're updating the actual layout algorithm as well, please also regenerate https://github.com/flutter/assets-for-api-docs/blob/master/material/app_bar.png (there's a dart file in that directory that you can drop into a flutter create app and run to generate the image, you'll need imagemagick and optipng).

Copy link
Contributor

Choose a reason for hiding this comment

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

You could improve this further by explaining what the 16s and the 56 mean (you could even use kToolbarHeight where that's appropriate).

800.0 - 4.0 - 16.0 - 56.0 - 16.0 = 708
800.0 - 72.0 - 4.0 = 724
What changed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added comments. Added a right side padding to the title that was missing before

@Hixie
Copy link
Contributor

Hixie commented May 26, 2017

@HansMuller should review this, but LGTM.

@xster xster requested a review from HansMuller May 31, 2017 19:01
@override
bool shouldRelayout(_ToolbarLayout oldDelegate) => centerTitle != oldDelegate.centerTitle;
}
const double _kLeadingWidth = 56.0; // So it's square with kToolbarHeight.
Copy link
Contributor

Choose a reason for hiding this comment

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

The value should be kToolbarHeight

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, done

_ToolbarLayout({ this.centerMiddle });

// If false the middle widget should be left or right justified within the space
// between the leading and trailing widgets, depending on the locale's writing
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see the support for writing-direction alignment. I think what you need is a TODO above the _ToolbarSlot.middle layout section. Then document the feature when it's supported.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ya, premature documentation. Changed to todos

import 'basic.dart';
import 'framework.dart';

/// [NavigationToolbar] is an unthemed layout helper to position 3 groups
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need to say "unthemed" here? I don't think we qualify any widgets this way.

This widget doesn't position 3 groups of widgets, it positions three widgets.

Copy link
Contributor

Choose a reason for hiding this comment

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

The third slot is a list, so that's not quite accurate either.

Copy link
Contributor

Choose a reason for hiding this comment

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

never mind i was confused

Copy link
Member Author

Choose a reason for hiding this comment

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

Reworded stuff

/// Either directly use the themed app bars such as the Material [AppBar] or
/// the iOS [CupertinoNavigationBar] or wrap this widget with more theming
/// specifications for your own custom app bar.
class NavigationToolbar extends StatelessWidget {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wish this had a more generic name, since it's just a layout widget, albeit a somewhat specialized one. That said, I don't have any great ideas (ThreeBar? Ugh).

Copy link
Member Author

Choose a reason for hiding this comment

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

somewhat. Though I think we still want this to be opinionated about navigation toolbars in that the toggable center and paddings will be toolbar specific

@HansMuller
Copy link
Contributor

LGTM too although I did find a few minor things to crab about.

@xster xster merged commit a8777ce into flutter:master Jun 1, 2017
@xster xster deleted the common-nav-bar branch June 1, 2017 23:24
@Hixie
Copy link
Contributor

Hixie commented Jun 2, 2017

@xster
Copy link
Member Author

xster commented Jun 3, 2017

I checked it out. It wouldn't alter the output. It's just an safeguard to make sure the title didn't run into the actions. (e.g. if the 'Abc' title was just long enough to touch actions, it won't look unpadded)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants