Fix AppBar centerTitle position with actions. (#106256)
This commit is contained in:
parent
2d93697c3b
commit
0de1ca2744
@ -153,7 +153,7 @@ class _ToolbarLayout extends MultiChildLayoutDelegate {
|
|||||||
if (centerMiddle) {
|
if (centerMiddle) {
|
||||||
middleStart = (size.width - middleSize.width) / 2.0;
|
middleStart = (size.width - middleSize.width) / 2.0;
|
||||||
if (middleStart + middleSize.width > size.width - trailingWidth) {
|
if (middleStart + middleSize.width > size.width - trailingWidth) {
|
||||||
middleStart = size.width - trailingWidth - middleSize.width;
|
middleStart = size.width - trailingWidth - middleSize.width - middleSpacing;
|
||||||
} else if (middleStart < middleStartMargin) {
|
} else if (middleStart < middleStartMargin) {
|
||||||
middleStart = middleStartMargin;
|
middleStart = middleStartMargin;
|
||||||
}
|
}
|
||||||
|
@ -401,7 +401,7 @@ void main() {
|
|||||||
const SizedBox(width: 48.0),
|
const SizedBox(width: 48.0),
|
||||||
];
|
];
|
||||||
await tester.pumpWidget(buildApp());
|
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));
|
expect(tester.getSize(title).width, equals(620.0));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -456,7 +456,7 @@ void main() {
|
|||||||
const SizedBox(width: 48.0),
|
const SizedBox(width: 48.0),
|
||||||
];
|
];
|
||||||
await tester.pumpWidget(buildApp());
|
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));
|
expect(tester.getSize(title).width, equals(620.0));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -3575,4 +3575,34 @@ void main() {
|
|||||||
expect(preferredHeight, 64);
|
expect(preferredHeight, 64);
|
||||||
expect(preferredSize.height, 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);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user