card.dart 1.52 KB
Newer Older
1 2 3 4
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'package:flutter/widgets.dart';
6 7

import 'material.dart';
8

9
/// A material design card. A card has slightly rounded corners and a shadow.
10 11 12
///
/// A card is a sheet of [Material] used to represent some related information,
/// for example an album, a geographical location, a meal, contact details, etc.
13
///
14 15
/// See also:
///
16
///  * [ListTile], to display icons and text in a card.
17 18 19
///  * [ButtonBar], to display buttons at the bottom of a card. Typically these
///    would be styled using a ButtonTheme created with [new ButtonTheme.bar].
///  * [showDialog], to display a modal card.
20
///  * <https://material.google.com/components/cards.html>
21
class Card extends StatelessWidget {
22 23 24
  /// Creates a material design card.
  const Card({
    Key key,
25
    this.color,
26
    this.elevation: 2.0,
27
    this.child
28
  }) : super(key: key);
29

30
  /// The widget below this widget in the tree.
31
  final Widget child;
32 33

  /// The color of material used for this card.
34 35
  final Color color;

36 37 38
  /// The z-coordinate at which to place this card.
  ///
  /// Defaults to 2, the appropriate elevation for cards.
39
  final double elevation;
40

41
  @override
42
  Widget build(BuildContext context) {
43
    return new Container(
44
      margin: const EdgeInsets.all(4.0),
45 46 47
      child: new Material(
        color: color,
        type: MaterialType.card,
48
        elevation: elevation,
49
        child: child
50 51 52 53
      )
    );
  }
}