grid_tile.dart 1.88 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
Hans Muller's avatar
Hans Muller committed
2 3 4 5 6
// 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
/// A tile in a material design grid list.
///
9
/// A grid list is a [GridView] of tiles in a vertical and horizontal
10 11 12 13 14
/// 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:
///
15
///  * [GridView], which is a scrollable grid of tiles.
16 17
///  * [GridTileBar], which is typically used in either the [header] or
///    [footer].
18
///  * <https://material.io/design/components/image-lists.html>
19
class GridTile extends StatelessWidget {
20 21 22
  /// Creates a grid tile.
  ///
  /// Must have a child. Does not typically have both a header and a footer.
23
  const GridTile({
24
    Key? key,
25 26
    this.header,
    this.footer,
27
    required this.child,
28 29
  }) : assert(child != null),
       super(key: key);
Hans Muller's avatar
Hans Muller committed
30

31
  /// The widget to show over the top of this grid tile.
32 33
  ///
  /// Typically a [GridTileBar].
34
  final Widget? header;
35 36

  /// The widget to show over the bottom of this grid tile.
37 38
  ///
  /// Typically a [GridTileBar].
39
  final Widget? footer;
40 41

  /// The widget that fills the tile.
42
  ///
43
  /// {@macro flutter.widgets.ProxyWidget.child}
Hans Muller's avatar
Hans Muller committed
44 45
  final Widget child;

46
  @override
Hans Muller's avatar
Hans Muller committed
47 48 49 50
  Widget build(BuildContext context) {
    if (header == null && footer == null)
      return child;

51 52 53 54 55 56 57 58 59 60
    return Stack(
      children: <Widget>[
        Positioned.fill(
          child: child,
        ),
        if (header != null)
          Positioned(
            top: 0.0,
            left: 0.0,
            right: 0.0,
61
            child: header!,
62 63 64 65 66 67
          ),
        if (footer != null)
          Positioned(
            left: 0.0,
            bottom: 0.0,
            right: 0.0,
68
            child: footer!,
69 70 71
          ),
      ],
    );
Hans Muller's avatar
Hans Muller committed
72 73
  }
}