diff --git a/packages/flutter/lib/src/material/banner.dart b/packages/flutter/lib/src/material/banner.dart index b90930f010..0f8c315c9a 100644 --- a/packages/flutter/lib/src/material/banner.dart +++ b/packages/flutter/lib/src/material/banner.dart @@ -120,6 +120,7 @@ class MaterialBanner extends StatefulWidget { this.overflowAlignment = OverflowBarAlignment.end, this.animation, this.onVisible, + this.minActionBarHeight = 52.0, }) : assert(elevation == null || elevation >= 0.0); /// The content of the [MaterialBanner]. @@ -156,6 +157,11 @@ class MaterialBanner extends StatefulWidget { /// Typically an [Icon] widget. final Widget? leading; + /// The optional minimum action bar height. + /// + /// Default to 52.0. + final double minActionBarHeight; + /// The color of the surface of this [MaterialBanner]. /// /// If `null`, [MaterialBannerThemeData.backgroundColor] is used. If that is @@ -252,6 +258,7 @@ class MaterialBanner extends StatefulWidget { actions: actions, elevation: elevation, leading: leading, + minActionBarHeight: minActionBarHeight, backgroundColor: backgroundColor, surfaceTintColor: surfaceTintColor, shadowColor: shadowColor, @@ -346,7 +353,7 @@ class _MaterialBannerState extends State { ?? const EdgeInsetsDirectional.only(end: 16.0); final Widget actionsBar = ConstrainedBox( - constraints: const BoxConstraints(minHeight: 52.0), + constraints: BoxConstraints(minHeight: widget.minActionBarHeight), child: Padding( padding: const EdgeInsets.symmetric(horizontal: 8), child: Align( diff --git a/packages/flutter/test/material/banner_test.dart b/packages/flutter/test/material/banner_test.dart index ca68ffb84c..54ae2eca0d 100644 --- a/packages/flutter/test/material/banner_test.dart +++ b/packages/flutter/test/material/banner_test.dart @@ -1150,6 +1150,66 @@ void main() { /// Compare the offset of banner from top left expect(topLeft.dx, margin.left); }); + + testWidgets('minActionBarHeight is respected', (WidgetTester tester) async { + const double minActionBarHeight = 20.0; + await tester.pumpWidget( + MaterialApp( + home:Scaffold( + appBar: AppBar(), + body: const MaterialBanner( + minActionBarHeight: minActionBarHeight, + padding: EdgeInsets.zero, + margin: EdgeInsets.zero, + content: SizedBox.shrink(), + actions: [ + SizedBox.shrink(), + ], + ), + ) + ), + ); + + final Size size = tester.getSize(find.byType(MaterialBanner)); + expect(size.height, equals(minActionBarHeight)); + }); + + testWidgets('minimumActionBarHeight is respected when presented by ScaffoldMessenger', (WidgetTester tester) async { + const Key tapTarget = Key('tap-target'); + const double minActionBarHeight = 20.0; + await tester.pumpWidget(MaterialApp( + home: Scaffold( + body: Builder( + builder: (BuildContext context) { + return GestureDetector( + key: tapTarget, + onTap: () { + ScaffoldMessenger.of(context).showMaterialBanner(const MaterialBanner( + content: SizedBox.shrink(), + padding: EdgeInsets.zero, + margin: EdgeInsets.zero, + minActionBarHeight: minActionBarHeight, + actions: [ + SizedBox.shrink() + ], + )); + }, + behavior: HitTestBehavior.opaque, + child: const SizedBox( + height: 100.0, + width: 100.0, + ), + ); + }, + ), + ), + )); + await tester.tap(find.byKey(tapTarget)); + await tester.pumpAndSettle(); + + final Size materialBarSize = tester.getSize(find.byType(MaterialBanner)); + expect(materialBarSize.height, equals(minActionBarHeight)); + }); } Material _getMaterialFromBanner(WidgetTester tester) {