Add minimum height for MaterialBanner (#153951)
This pr allows defining custom minimum height for material banner fixes this https://github.com/flutter/flutter/issues/153666
This commit is contained in:
@@ -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<MaterialBanner> {
|
||||
?? 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(
|
||||
|
||||
@@ -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: <Widget>[
|
||||
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: <Widget>[
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user