diff --git a/packages/flutter/lib/src/widgets/navigation_toolbar.dart b/packages/flutter/lib/src/widgets/navigation_toolbar.dart index 4840a4f4a34..951a1ee86b8 100644 --- a/packages/flutter/lib/src/widgets/navigation_toolbar.dart +++ b/packages/flutter/lib/src/widgets/navigation_toolbar.dart @@ -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; } diff --git a/packages/flutter/test/material/app_bar_test.dart b/packages/flutter/test/material/app_bar_test.dart index 620d6478600..acf54c2eadd 100644 --- a/packages/flutter/test/material/app_bar_test.dart +++ b/packages/flutter/test/material/app_bar_test.dart @@ -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 [ + 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); + }); }