card.dart 1.6 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
///  * [ListItem], 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 26 27
    this.color,
    this.elevation: 2,
    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
  /// The z-coordinate at which to place this card.
  ///
38
  /// The following elevations have defined shadows: 1, 2, 3, 4, 6, 8, 9, 12, 16, 24
39 40
  ///
  /// Defaults to 2, the appropriate elevation for cards.
41 42
  final int elevation;

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