Unverified Commit 0de1ca27 authored by Bernardo Ferrari's avatar Bernardo Ferrari Committed by GitHub

Fix AppBar centerTitle position with actions. (#106256)

parent 2d93697c
......@@ -153,7 +153,7 @@ class _ToolbarLayout extends MultiChildLayoutDelegate {
if (centerMiddle) {
middleStart = (size.width - middleSize.width) / 2.0;
if (middleStart + middleSize.width > size.width - trailingWidth) {
middleStart = size.width - trailingWidth - middleSize.width;
middleStart = size.width - trailingWidth - middleSize.width - middleSpacing;
} else if (middleStart < middleStartMargin) {
middleStart = middleStartMargin;
}
......
......@@ -401,7 +401,7 @@ void main() {
const SizedBox(width: 48.0),
];
await tester.pumpWidget(buildApp());
expect(tester.getTopLeft(title).dx, 800 - 620 - 48 - 48);
expect(tester.getTopLeft(title).dx, 800 - 620 - 48 - 48 - 16);
expect(tester.getSize(title).width, equals(620.0));
});
......@@ -456,7 +456,7 @@ void main() {
const SizedBox(width: 48.0),
];
await tester.pumpWidget(buildApp());
expect(tester.getTopRight(title).dx, 620 + 48 + 48);
expect(tester.getTopRight(title).dx, 620 + 48 + 48 + 16);
expect(tester.getSize(title).width, equals(620.0));
});
......@@ -3575,4 +3575,34 @@ void main() {
expect(preferredHeight, 64);
expect(preferredSize.height, 64);
});
testWidgets('AppBar title with actions should have the same position regardless of centerTitle', (WidgetTester tester) async {
final Key titleKey = UniqueKey();
bool centerTitle = false;
Widget buildApp() {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
centerTitle: centerTitle,
title: Container(
key: titleKey,
constraints: BoxConstraints.loose(const Size(1000.0, 1000.0)),
),
actions: const <Widget>[
SizedBox(width: 48.0),
],
),
),
);
}
await tester.pumpWidget(buildApp());
final Finder title = find.byKey(titleKey);
expect(tester.getTopLeft(title).dx, 16.0);
centerTitle = true;
await tester.pumpWidget(buildApp());
expect(tester.getTopLeft(title).dx, 16.0);
});
}
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