Fix single action banner to ensure button alignment (#39583)

This commit is contained in:
rami-a
2019-09-04 09:41:46 -04:00
committed by GitHub
parent 72cacb4040
commit af9f210443
2 changed files with 46 additions and 1 deletions

View File

@@ -143,7 +143,7 @@ class MaterialBanner extends StatelessWidget {
padding: leadingPadding,
child: leading,
),
Flexible(
Expanded(
child: DefaultTextStyle(
style: textStyle,
child: content,

View File

@@ -100,6 +100,51 @@ void main() {
expect(contentBottomLeft.dx, lessThan(actionsTopRight.dx));
});
// Regression test for https://github.com/flutter/flutter/issues/39574
testWidgets('Single action laid out beside content but aligned to the trailing edge', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: MaterialBanner(
content: const Text('Content'),
actions: <Widget>[
FlatButton(
child: const Text('Action'),
onPressed: () { },
),
],
),
),
);
final Offset actionsTopRight = tester.getTopRight(find.byType(ButtonBar));
final Offset bannerTopRight = tester.getTopRight(find.byType(MaterialBanner));
expect(actionsTopRight.dx, bannerTopRight.dx);
});
// Regression test for https://github.com/flutter/flutter/issues/39574
testWidgets('Single action laid out beside content but aligned to the trailing edge - RTL', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: Directionality(
textDirection: TextDirection.rtl,
child: MaterialBanner(
content: const Text('Content'),
actions: <Widget>[
FlatButton(
child: const Text('Action'),
onPressed: () { },
),
],
),
),
),
);
final Offset actionsTopLeft = tester.getTopLeft(find.byType(ButtonBar));
final Offset bannerTopLeft = tester.getTopLeft(find.byType(MaterialBanner));
expect(actionsTopLeft.dx, bannerTopLeft.dx);
});
testWidgets('Actions laid out below content if forced override', (WidgetTester tester) async {
const String contentText = 'Content';