drawer_header.dart 2.2 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 'debug.dart';
8
import 'theme.dart';
9

10 11
const double _kDrawerHeaderHeight = 140.0;

12 13 14
/// The top-most region of a material design drawer. The header's [background]
/// widget extends behind the system status bar and its [content] widget is
/// stacked on top of the background and below the status bar.
15 16 17 18 19 20
///
/// Part of the material design [Drawer].
///
/// Requires one of its ancestors to be a [Material] widget.
///
/// See also:
21
///
22 23 24
///  * [Drawer]
///  * [DrawerItem]
///  * <https://www.google.com/design/spec/patterns/navigation-drawer.html>
25
class DrawerHeader extends StatelessWidget {
26 27 28
  /// Creates a material design drawer header.
  ///
  /// Requires one of its ancestors to be a [Material] widget.
29
  const DrawerHeader({ Key key, this.background, this.content }) : super(key: key);
30

31 32 33 34 35 36 37
  /// A widget that extends behind the system status bar and is stacked
  /// behind the [content] widget.
  final Widget background;

  /// A widget that's positioned below the status bar and stacked on top of the
  /// [background] widget. Typically a view of the user's id.
  final Widget content;
38

39
  @override
40
  Widget build(BuildContext context) {
41
    assert(debugCheckHasMaterial(context));
42
    final double statusBarHeight = MediaQuery.of(context).padding.top;
43
    return new Container(
44
      height: statusBarHeight + _kDrawerHeaderHeight,
45
      margin: const EdgeInsets.only(bottom: 7.0), // 8 less 1 for the bottom border.
46 47 48 49 50 51 52 53
      decoration: new BoxDecoration(
        border: const Border(
          bottom: const BorderSide(
            color: const Color(0xFFD1D9E1),
            width: 1.0
          )
        )
      ),
54
      child: new Stack(
55
        children: <Widget>[
56 57 58 59 60 61
          background ?? new Container(),
          new Positioned(
            top: statusBarHeight + 16.0,
            left: 16.0,
            right: 16.0,
            bottom: 8.0,
62
            child: new DefaultTextStyle(
63
              style: Theme.of(context).textTheme.body2,
64
              child: content
65
            )
66
          )
67
        ]
68 69 70 71
      )
    );
  }
}