tool_bar.dart 2.57 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// 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.

import 'package:sky/widgets/theme.dart';

import 'package:sky/painting/text_style.dart';
import 'package:sky/rendering/flex.dart';
import 'package:sky/theme/shadows.dart';
import 'package:sky/theme/typography.dart' as typography;
import 'package:sky/theme/view_configuration.dart';
import 'package:sky/widgets/basic.dart';
import 'package:sky/widgets/default_text_style.dart';
import 'package:sky/widgets/icon.dart';

class ToolBar extends Component {

  ToolBar({
19
    Key key,
20 21 22 23 24 25 26 27 28 29 30 31 32 33
    this.left,
    this.center,
    this.right,
    this.backgroundColor
  }) : super(key: key);

  final Widget left;
  final Widget center;
  final List<Widget> right;
  final Color backgroundColor;

  Widget build() {
    Color toolbarColor = backgroundColor;
    IconThemeData iconThemeData;
34 35
    TextStyle centerStyle = typography.white.title;
    TextStyle sideStyle = typography.white.body1;
36 37 38 39
    if (toolbarColor == null) {
      ThemeData themeData = Theme.of(this);
      toolbarColor = themeData.primaryColor;
      if (themeData.primaryColorBrightness == ThemeBrightness.light) {
40 41
        centerStyle = typography.black.title;
        sideStyle = typography.black.body2;
42 43 44 45 46 47 48
        iconThemeData = const IconThemeData(color: IconThemeColor.black);
      } else {
        iconThemeData = const IconThemeData(color: IconThemeColor.white);
      }
    }

    List<Widget> children = new List<Widget>();
49 50

    // left children
51 52 53
    if (left != null)
      children.add(left);

54
    // center children (left-aligned, but takes all remaining space)
55 56 57
    children.add(
      new Flexible(
        child: new Padding(
58
          child: center != null ? new DefaultTextStyle(child: center, style: centerStyle) : null,
59 60 61 62 63
          padding: new EdgeDims.only(left: 24.0)
        )
      )
    );

64
    // right children
65 66 67 68 69
    if (right != null)
      children.addAll(right);

    Widget content = new Container(
      child: new DefaultTextStyle(
70
        style: sideStyle,
71
        child: new Column([
72
            new Container(
73
              child: new Row(children),
74 75 76 77
              height: kToolBarHeight
            ),
          ],
          justifyContent: FlexJustifyContent.end
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
        )
      ),
      padding: new EdgeDims.symmetric(horizontal: 8.0),
      decoration: new BoxDecoration(
        backgroundColor: toolbarColor,
        boxShadow: shadows[2]
      )
    );

    if (iconThemeData != null)
      content = new IconTheme(data: iconThemeData, child: content);
    return content;
  }

}