Commit 34a6e48a authored by xster's avatar xster Committed by GitHub

16 dp title margin when there’s no leading button (#8344)

parent 7201c8c9
...@@ -47,7 +47,8 @@ class _ToolbarLayout extends MultiChildLayoutDelegate { ...@@ -47,7 +47,8 @@ class _ToolbarLayout extends MultiChildLayoutDelegate {
final bool centerTitle; final bool centerTitle;
static const double kLeadingWidth = 56.0; // So it's square with kToolbarHeight. static const double kLeadingWidth = 56.0; // So it's square with kToolbarHeight.
static const double kTitleLeft = 72.0; // As per https://material.io/guidelines/layout/metrics-keylines.html#metrics-keylines-keylines-spacing. static const double kTitleLeftWithLeading = 72.0; // As per https://material.io/guidelines/layout/metrics-keylines.html#metrics-keylines-keylines-spacing.
static const double kTitleLeftWithoutLeading = 16.0;
@override @override
void performLayout(Size size) { void performLayout(Size size) {
...@@ -69,11 +70,13 @@ class _ToolbarLayout extends MultiChildLayoutDelegate { ...@@ -69,11 +70,13 @@ class _ToolbarLayout extends MultiChildLayoutDelegate {
} }
if (hasChild(_ToolbarSlot.title)) { if (hasChild(_ToolbarSlot.title)) {
final double maxWidth = math.max(size.width - kTitleLeft - actionsWidth, 0.0); final double titleLeftMargin =
hasChild(_ToolbarSlot.leading) ? kTitleLeftWithLeading : kTitleLeftWithoutLeading;
final double maxWidth = math.max(size.width - titleLeftMargin - actionsWidth, 0.0);
final BoxConstraints constraints = new BoxConstraints.loose(size).copyWith(maxWidth: maxWidth); final BoxConstraints constraints = new BoxConstraints.loose(size).copyWith(maxWidth: maxWidth);
final Size titleSize = layoutChild(_ToolbarSlot.title, constraints); final Size titleSize = layoutChild(_ToolbarSlot.title, constraints);
final double titleY = (size.height - titleSize.height) / 2.0; final double titleY = (size.height - titleSize.height) / 2.0;
double titleX = kTitleLeft; double titleX = titleLeftMargin;
// If the centered title will not fit between the leading and actions // If the centered title will not fit between the leading and actions
// widgets, then align its left or right edge with the adjacent boundary. // widgets, then align its left or right edge with the adjacent boundary.
...@@ -81,8 +84,8 @@ class _ToolbarLayout extends MultiChildLayoutDelegate { ...@@ -81,8 +84,8 @@ class _ToolbarLayout extends MultiChildLayoutDelegate {
titleX = (size.width - titleSize.width) / 2.0; titleX = (size.width - titleSize.width) / 2.0;
if (titleX + titleSize.width > size.width - actionsWidth) if (titleX + titleSize.width > size.width - actionsWidth)
titleX = size.width - actionsWidth - titleSize.width; titleX = size.width - actionsWidth - titleSize.width;
else if (titleX < kTitleLeft) else if (titleX < titleLeftMargin)
titleX = kTitleLeft; titleX = titleLeftMargin;
} }
positionChild(_ToolbarSlot.title, new Offset(titleX, titleY)); positionChild(_ToolbarSlot.title, new Offset(titleX, titleY));
......
...@@ -13,10 +13,10 @@ void main() { ...@@ -13,10 +13,10 @@ void main() {
theme: new ThemeData(platform: TargetPlatform.android), theme: new ThemeData(platform: TargetPlatform.android),
home: new Scaffold( home: new Scaffold(
appBar: new AppBar( appBar: new AppBar(
title: new Text('X') title: new Text('X'),
) ),
) ),
) ),
); );
Finder title = find.text('X'); Finder title = find.text('X');
...@@ -32,10 +32,10 @@ void main() { ...@@ -32,10 +32,10 @@ void main() {
theme: new ThemeData(platform: TargetPlatform.iOS), theme: new ThemeData(platform: TargetPlatform.iOS),
home: new Scaffold( home: new Scaffold(
appBar: new AppBar( appBar: new AppBar(
title: new Text('X') title: new Text('X'),
) ),
) ),
) ),
); );
center = tester.getCenter(title); center = tester.getCenter(title);
...@@ -51,7 +51,7 @@ void main() { ...@@ -51,7 +51,7 @@ void main() {
home: new Scaffold( home: new Scaffold(
appBar: new AppBar( appBar: new AppBar(
centerTitle: true, centerTitle: true,
title: new Text('X') title: new Text('X'),
) )
) )
) )
...@@ -65,16 +65,35 @@ void main() { ...@@ -65,16 +65,35 @@ void main() {
expect(center.x, lessThan(400 + size.width / 2.0)); expect(center.x, lessThan(400 + size.width / 2.0));
}); });
testWidgets('AppBar centerTitle:false title left edge is 72.0 ', (WidgetTester tester) async { testWidgets('AppBar centerTitle:false title left edge is 16.0 ', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
new MaterialApp( new MaterialApp(
home: new Scaffold( home: new Scaffold(
appBar: new AppBar( appBar: new AppBar(
centerTitle: false, centerTitle: false,
title: new Text('X') title: new Text('X'),
) ),
) ),
) ),
);
expect(tester.getTopLeft(find.text('X')).x, 16.0);
});
testWidgets(
'AppBar centerTitle:false leading button title left edge is 72.0 ',
(WidgetTester tester) async {
await tester.pumpWidget(
new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
centerTitle: false,
title: new Text('X'),
),
// A drawer causes a leading hamburger.
drawer: new Drawer(),
),
),
); );
expect(tester.getTopLeft(find.text('X')).x, 72.0); expect(tester.getTopLeft(find.text('X')).x, 72.0);
...@@ -85,7 +104,7 @@ void main() { ...@@ -85,7 +104,7 @@ void main() {
// between the leading and actions widgets. // between the leading and actions widgets.
Key titleKey = new UniqueKey(); Key titleKey = new UniqueKey();
Widget leading; Widget leading = new Container();
List<Widget> actions; List<Widget> actions;
Widget buildApp() { Widget buildApp() {
...@@ -96,11 +115,11 @@ void main() { ...@@ -96,11 +115,11 @@ void main() {
centerTitle: false, centerTitle: false,
title: new Container( title: new Container(
key: titleKey, key: titleKey,
constraints: new BoxConstraints.loose(const Size(1000.0, 1000.0)) constraints: new BoxConstraints.loose(const Size(1000.0, 1000.0)),
), ),
actions: actions actions: actions,
) ),
) ),
); );
} }
...@@ -146,11 +165,11 @@ void main() { ...@@ -146,11 +165,11 @@ void main() {
centerTitle: true, centerTitle: true,
title: new Container( title: new Container(
key: titleKey, key: titleKey,
constraints: new BoxConstraints.loose(new Size(titleWidth, 1000.0)) constraints: new BoxConstraints.loose(new Size(titleWidth, 1000.0)),
), ),
actions: actions actions: actions,
) ),
) ),
); );
} }
...@@ -188,11 +207,11 @@ void main() { ...@@ -188,11 +207,11 @@ void main() {
width: 0.0, width: 0.0,
child: new Scaffold( child: new Scaffold(
appBar: new AppBar( appBar: new AppBar(
title: new Text('X') title: new Text('X'),
) ),
) ),
) ),
) ),
); );
Finder title = find.text('X'); Finder title = find.text('X');
...@@ -219,7 +238,7 @@ void main() { ...@@ -219,7 +238,7 @@ void main() {
], ],
), ),
), ),
) ),
); );
// The vertical center of the widget with key, in global coordinates. // The vertical center of the widget with key, in global coordinates.
...@@ -240,8 +259,8 @@ void main() { ...@@ -240,8 +259,8 @@ void main() {
title: new Text('X'), title: new Text('X'),
), ),
drawer: new Column(), // Doesn't really matter. Triggers a hamburger regardless. drawer: new Column(), // Doesn't really matter. Triggers a hamburger regardless.
) ),
) ),
); );
Finder hamburger = find.byTooltip('Open navigation menu'); Finder hamburger = find.byTooltip('Open navigation menu');
...@@ -271,8 +290,8 @@ void main() { ...@@ -271,8 +290,8 @@ void main() {
), ),
], ],
), ),
) ),
) ),
); );
Finder addButton = find.byTooltip('Add'); Finder addButton = find.byTooltip('Add');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment