Unverified Commit 7d3b762d authored by Hasnen Tai's avatar Hasnen Tai Committed by GitHub

Fix: Added `margin` parameter for `MaterialBanner` class (#119005)

* Fix: Added Margin Parameter for Material Banner

* Fix: Comment for default value added and test improved

* Fix: Comment updated

* Fix: Comment added
parent c9affdba
...@@ -106,6 +106,7 @@ class MaterialBanner extends StatefulWidget { ...@@ -106,6 +106,7 @@ class MaterialBanner extends StatefulWidget {
this.shadowColor, this.shadowColor,
this.dividerColor, this.dividerColor,
this.padding, this.padding,
this.margin,
this.leadingPadding, this.leadingPadding,
this.forceActionsBelow = false, this.forceActionsBelow = false,
this.overflowAlignment = OverflowBarAlignment.end, this.overflowAlignment = OverflowBarAlignment.end,
...@@ -185,6 +186,12 @@ class MaterialBanner extends StatefulWidget { ...@@ -185,6 +186,12 @@ class MaterialBanner extends StatefulWidget {
/// `EdgeInsetsDirectional.only(start: 16.0, top: 2.0)`. /// `EdgeInsetsDirectional.only(start: 16.0, top: 2.0)`.
final EdgeInsetsGeometry? padding; final EdgeInsetsGeometry? padding;
/// Empty space to surround the [MaterialBanner].
///
/// If the [margin] is null then this defaults to
/// 0 if the banner's [elevation] is 0, 10 otherwise.
final EdgeInsetsGeometry? margin;
/// The amount of space by which to inset the [leading] widget. /// The amount of space by which to inset the [leading] widget.
/// ///
/// This defaults to `EdgeInsetsDirectional.only(end: 16.0)`. /// This defaults to `EdgeInsetsDirectional.only(end: 16.0)`.
...@@ -237,6 +244,7 @@ class MaterialBanner extends StatefulWidget { ...@@ -237,6 +244,7 @@ class MaterialBanner extends StatefulWidget {
leading: leading, leading: leading,
backgroundColor: backgroundColor, backgroundColor: backgroundColor,
padding: padding, padding: padding,
margin: margin,
leadingPadding: leadingPadding, leadingPadding: leadingPadding,
forceActionsBelow: forceActionsBelow, forceActionsBelow: forceActionsBelow,
overflowAlignment: overflowAlignment, overflowAlignment: overflowAlignment,
...@@ -318,6 +326,7 @@ class _MaterialBannerState extends State<MaterialBanner> { ...@@ -318,6 +326,7 @@ class _MaterialBannerState extends State<MaterialBanner> {
); );
final double elevation = widget.elevation ?? bannerTheme.elevation ?? 0.0; final double elevation = widget.elevation ?? bannerTheme.elevation ?? 0.0;
final EdgeInsetsGeometry margin = widget.margin ?? EdgeInsets.only(bottom: elevation > 0 ? 10.0 : 0.0);
final Color backgroundColor = widget.backgroundColor final Color backgroundColor = widget.backgroundColor
?? bannerTheme.backgroundColor ?? bannerTheme.backgroundColor
?? defaults.backgroundColor!; ?? defaults.backgroundColor!;
...@@ -334,7 +343,7 @@ class _MaterialBannerState extends State<MaterialBanner> { ...@@ -334,7 +343,7 @@ class _MaterialBannerState extends State<MaterialBanner> {
?? defaults.contentTextStyle; ?? defaults.contentTextStyle;
Widget materialBanner = Container( Widget materialBanner = Container(
margin: EdgeInsets.only(bottom: elevation > 0 ? 10.0 : 0.0), margin: margin,
child: Material( child: Material(
elevation: elevation, elevation: elevation,
color: backgroundColor, color: backgroundColor,
......
...@@ -1105,6 +1105,28 @@ void main() { ...@@ -1105,6 +1105,28 @@ void main() {
), ),
); );
}); });
testWidgets('Custom Margin respected', (WidgetTester tester) async {
const EdgeInsets margin = EdgeInsets.all(30);
await tester.pumpWidget(
MaterialApp(
home: MaterialBanner(
margin: margin,
content: const Text('I am a banner'),
actions: <Widget>[
TextButton(
child: const Text('Action'),
onPressed: () { },
),
],
),
),
);
final Offset topLeft = tester.getTopLeft(find.descendant(of: find.byType(MaterialBanner), matching: find.byType(Material)).first);
/// Compare the offset of banner from top left
expect(topLeft.dx, margin.left);
});
} }
Material _getMaterialFromBanner(WidgetTester tester) { Material _getMaterialFromBanner(WidgetTester tester) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment