drawer_header.dart 2.9 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
const double _kDrawerHeaderHeight = 160.0 + 1.0; // bottom edge
11

12
/// The top-most region of a material design drawer. The header's [child]
13 14
/// widget, if any, is placed inside a [Container] whose [decoration] can be
/// passed as an argument, inset by the given [padding].
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
///  * [Drawer]
23 24
///  * [UserAccountsDrawerHeader], a variant of [DrawerHeader] that is
///    specialized for showing user accounts.
25 26
///  * [DrawerItem]
///  * <https://www.google.com/design/spec/patterns/navigation-drawer.html>
27
class DrawerHeader extends StatelessWidget {
28 29 30
  /// Creates a material design drawer header.
  ///
  /// Requires one of its ancestors to be a [Material] widget.
31 32 33
  const DrawerHeader({
    Key key,
    this.decoration,
34 35 36
    this.padding: const EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 8.0),
    this.duration: const Duration(milliseconds: 250),
    this.curve: Curves.fastOutSlowIn,
37 38
    this.child
  }) : super(key: key);
39

40 41
  /// Decoration for the main drawer header [Container]; useful for applying
  /// backgrounds.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
  ///
  /// This decoration will extend under the system status bar.
  ///
  /// If this is changed, it will be animated according to [duration] and [curve].
  final Decoration decoration;

  /// The padding by which to inset [child].
  ///
  /// The [DrawerHeader] additionally offsets the child by the height of the
  /// system status bar.
  ///
  /// If the child is null, the padding has no effect.
  final EdgeInsets padding;

  /// The duration for animations of the [decoration].
  final Duration duration;

  /// The curve for animations of the [decoration].
  final Curve curve;
61

62
  /// A widget to be placed inside the drawer header, inset by the [padding].
63
  final Widget child;
64

65
  @override
66
  Widget build(BuildContext context) {
67
    assert(debugCheckHasMaterial(context));
68
    final ThemeData theme = Theme.of(context);
69
    final double statusBarHeight = MediaQuery.of(context).padding.top;
70
    return new Container(
71
      height: statusBarHeight + _kDrawerHeaderHeight,
72
      margin: const EdgeInsets.only(bottom: 8.0),
73
      decoration: new BoxDecoration(
74 75 76
        border: new Border(
          bottom: new BorderSide(
            color: theme.dividerColor,
77 78 79 80
            width: 1.0
          )
        )
      ),
81 82
      child: new AnimatedContainer(
        padding: padding + new EdgeInsets.only(top: statusBarHeight),
83
        decoration: decoration,
84 85 86
        duration: duration,
        curve: curve,
        child: child == null ? null : new DefaultTextStyle(
87
          style: theme.textTheme.body2,
88 89
          child: child
        )
90 91 92 93
      )
    );
  }
}