mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
AppBar Menu and action button center alignment (#7280)
This commit is contained in:
parent
dbf1cfdbf0
commit
0d746ff155
@ -55,8 +55,11 @@ class _ToolbarLayout extends MultiChildLayoutDelegate {
|
||||
|
||||
if (hasChild(_ToolbarSlot.actions)) {
|
||||
final BoxConstraints constraints = new BoxConstraints.loose(size);
|
||||
actionsWidth = layoutChild(_ToolbarSlot.actions, constraints).width;
|
||||
positionChild(_ToolbarSlot.actions, new Offset(size.width - actionsWidth, 0.0));
|
||||
final Size actionsSize = layoutChild(_ToolbarSlot.actions, constraints);
|
||||
final double actionsLeft = size.width - actionsSize.width;
|
||||
final double actionsTop = (size.height - actionsSize.height) / 2.0;
|
||||
actionsWidth = actionsSize.width;
|
||||
positionChild(_ToolbarSlot.actions, new Offset(actionsLeft, actionsTop));
|
||||
}
|
||||
|
||||
if (hasChild(_ToolbarSlot.title)) {
|
||||
|
||||
@ -197,4 +197,40 @@ void main() {
|
||||
Finder title = find.text('X');
|
||||
expect(tester.getSize(title).isEmpty, isTrue);
|
||||
});
|
||||
|
||||
testWidgets('AppBar actions are vertically centered', (WidgetTester tester) async {
|
||||
UniqueKey appBarKey = new UniqueKey();
|
||||
UniqueKey leadingKey = new UniqueKey();
|
||||
UniqueKey titleKey = new UniqueKey();
|
||||
UniqueKey action0Key = new UniqueKey();
|
||||
UniqueKey action1Key = new UniqueKey();
|
||||
|
||||
await tester.pumpWidget(
|
||||
new MaterialApp(
|
||||
home: new Scaffold(
|
||||
appBar: new AppBar(
|
||||
key: appBarKey,
|
||||
leading: new SizedBox(key: leadingKey, height: 50.0),
|
||||
title: new SizedBox(key: titleKey, height: 40.0),
|
||||
actions: <Widget>[
|
||||
new SizedBox(key: action0Key, height: 20.0),
|
||||
new SizedBox(key: action1Key, height: 30.0),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
// The vertical center of the widget with key, in global coordinates.
|
||||
double yCenter(Key key) {
|
||||
RenderBox box = tester.renderObject(find.byKey(appBarKey));
|
||||
return box.localToGlobal(new Point(0.0, box.size.height / 2.0)).y;
|
||||
}
|
||||
|
||||
expect(yCenter(appBarKey), equals(yCenter(leadingKey)));
|
||||
expect(yCenter(appBarKey), equals(yCenter(titleKey)));
|
||||
expect(yCenter(appBarKey), equals(yCenter(action0Key)));
|
||||
expect(yCenter(appBarKey), equals(yCenter(action1Key)));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user