grid_tile.dart 1.73 KB
Newer Older
Hans Muller's avatar
Hans Muller committed
1 2 3 4 5 6
// Copyright 2016 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.

import 'package:flutter/widgets.dart';

7 8 9 10 11 12 13 14 15 16 17
/// A tile in a material design grid list.
///
/// A grid list is a [ScrollableGrid] of tiles in a vertical and horizontal
/// array. Each tile typically contains some visually rich content (e.g., an
/// image) together with a [GridTileBar] in either a [header] or a [footer].
///
/// See also:
///
///  * [ScrollableGrid]
///  * [GridTileBar]
///  * <https://www.google.com/design/spec/components/grid-lists.html>
18
class GridTile extends StatelessWidget {
19 20 21
  /// Creates a grid tile.
  ///
  /// Must have a child. Does not typically have both a header and a footer.
Hans Muller's avatar
Hans Muller committed
22 23 24 25
  GridTile({ Key key, this.header, this.footer, this.child }) : super(key: key) {
    assert(child != null);
  }

26
  /// The widget to show over the top of this grid tile.
Hans Muller's avatar
Hans Muller committed
27
  final Widget header;
28 29

  /// The widget to show over the bottom of this grid tile.
Hans Muller's avatar
Hans Muller committed
30
  final Widget footer;
31 32

  /// The widget that fills the tile.
Hans Muller's avatar
Hans Muller committed
33 34
  final Widget child;

35
  @override
Hans Muller's avatar
Hans Muller committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
  Widget build(BuildContext context) {
    if (header == null && footer == null)
      return child;

    final List<Widget> children = <Widget>[
      new Positioned(
        top: 0.0,
        left: 0.0,
        bottom: 0.0,
        right: 0.0,
        child: child
      )
    ];
    if (header != null) {
      children.add(new Positioned(
        top: 0.0,
        left: 0.0,
        right: 0.0,
        child: header
      ));
    }
    if (footer != null) {
      children.add(new Positioned(
        left: 0.0,
        bottom: 0.0,
        right: 0.0,
        child: footer
      ));
    }
    return new Stack(children: children);
  }
}