Unverified Commit b8629bab authored by Hans Muller's avatar Hans Muller Committed by GitHub

Made Card's margin configurable (#16203)

parent 6c896ae1
...@@ -65,6 +65,7 @@ class Card extends StatelessWidget { ...@@ -65,6 +65,7 @@ class Card extends StatelessWidget {
this.color, this.color,
this.elevation, this.elevation,
this.shape, this.shape,
this.margin: const EdgeInsets.all(4.0),
this.child, this.child,
}) : super(key: key); }) : super(key: key);
...@@ -91,6 +92,14 @@ class Card extends StatelessWidget { ...@@ -91,6 +92,14 @@ class Card extends StatelessWidget {
/// radius of 4.0. /// radius of 4.0.
final ShapeBorder shape; final ShapeBorder shape;
/// The empty space that surrounds the card.
///
/// Defines the card's outer [Container.margin].
///
/// The default margin is 4.0 logical pixels on all sides:
/// `EdgeInsets.all(4.0)`.
final EdgeInsetsGeometry margin;
/// The widget below this widget in the tree. /// The widget below this widget in the tree.
/// ///
/// {@macro flutter.widgets.child} /// {@macro flutter.widgets.child}
...@@ -101,7 +110,7 @@ class Card extends StatelessWidget { ...@@ -101,7 +110,7 @@ class Card extends StatelessWidget {
return new Semantics( return new Semantics(
container: true, container: true,
child: new Container( child: new Container(
margin: const EdgeInsets.all(4.0), margin: margin ?? const EdgeInsets.all(4.0),
child: new Material( child: new Material(
type: MaterialType.card, type: MaterialType.card,
color: color ?? Theme.of(context).cardColor, color: color ?? Theme.of(context).cardColor,
......
...@@ -68,4 +68,51 @@ void main() { ...@@ -68,4 +68,51 @@ void main() {
semantics.dispose(); semantics.dispose();
}); });
testWidgets('Card margin', (WidgetTester tester) async {
const Key contentsKey = const ValueKey<String>('contents');
await tester.pumpWidget(
new Container(
alignment: Alignment.topLeft,
child: new Card(
child: new Container(
key: contentsKey,
color: const Color(0xFF00FF00),
width: 100.0,
height: 100.0,
),
),
),
);
// Default margin is 4
expect(tester.getTopLeft(find.byType(Card)), const Offset(0.0, 0.0));
expect(tester.getSize(find.byType(Card)), const Size(108.0, 108.0));
expect(tester.getTopLeft(find.byKey(contentsKey)), const Offset(4.0, 4.0));
expect(tester.getSize(find.byKey(contentsKey)), const Size(100.0, 100.0));
await tester.pumpWidget(
new Container(
alignment: Alignment.topLeft,
child: new Card(
margin: EdgeInsets.zero,
child: new Container(
key: contentsKey,
color: const Color(0xFF00FF00),
width: 100.0,
height: 100.0,
),
),
),
);
// Specified margin is zero
expect(tester.getTopLeft(find.byType(Card)), const Offset(0.0, 0.0));
expect(tester.getSize(find.byType(Card)), const Size(100.0, 100.0));
expect(tester.getTopLeft(find.byKey(contentsKey)), const Offset(0.0, 0.0));
expect(tester.getSize(find.byKey(contentsKey)), const Size(100.0, 100.0));
});
} }
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