Fix AppBar centerTitle position with actions. (#106256)

This commit is contained in:
Bernardo Ferrari 2022-08-17 16:20:15 -03:00 committed by GitHub
parent 2d93697c3b
commit 0de1ca2744
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 3 deletions

View File

@ -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;
}

View File

@ -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);
});
}