grid_tile.dart 1.87 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
/// A tile in a Material Design grid list.
8
///
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
    super.key,
25 26
    this.header,
    this.footer,
27
    required this.child,
28
  }) : assert(child != null);
Hans Muller's avatar
Hans Muller committed
29

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

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

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

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

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
  }
}