diff --git a/packages/flutter/lib/src/material/banner.dart b/packages/flutter/lib/src/material/banner.dart index b3364c9fea..5f603f3795 100644 --- a/packages/flutter/lib/src/material/banner.dart +++ b/packages/flutter/lib/src/material/banner.dart @@ -143,7 +143,7 @@ class MaterialBanner extends StatelessWidget { padding: leadingPadding, child: leading, ), - Flexible( + Expanded( child: DefaultTextStyle( style: textStyle, child: content, diff --git a/packages/flutter/test/material/banner_test.dart b/packages/flutter/test/material/banner_test.dart index 1e68476071..f3bcc680a6 100644 --- a/packages/flutter/test/material/banner_test.dart +++ b/packages/flutter/test/material/banner_test.dart @@ -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: [ + 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: [ + 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';