Made Card's margin configurable (#16203)
This commit is contained in:
@@ -65,6 +65,7 @@ class Card extends StatelessWidget {
|
||||
this.color,
|
||||
this.elevation,
|
||||
this.shape,
|
||||
this.margin: const EdgeInsets.all(4.0),
|
||||
this.child,
|
||||
}) : super(key: key);
|
||||
|
||||
@@ -91,6 +92,14 @@ class Card extends StatelessWidget {
|
||||
/// radius of 4.0.
|
||||
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.
|
||||
///
|
||||
/// {@macro flutter.widgets.child}
|
||||
@@ -101,7 +110,7 @@ class Card extends StatelessWidget {
|
||||
return new Semantics(
|
||||
container: true,
|
||||
child: new Container(
|
||||
margin: const EdgeInsets.all(4.0),
|
||||
margin: margin ?? const EdgeInsets.all(4.0),
|
||||
child: new Material(
|
||||
type: MaterialType.card,
|
||||
color: color ?? Theme.of(context).cardColor,
|
||||
|
||||
@@ -68,4 +68,51 @@ void main() {
|
||||
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));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user