tool_bar.dart 2.63 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:sky/src/widgets/theme.dart';
6

7
import 'package:sky/painting.dart';
8 9 10 11 12
import 'package:sky/src/rendering/flex.dart';
import 'package:sky/src/widgets/basic.dart';
import 'package:sky/src/widgets/default_text_style.dart';
import 'package:sky/src/widgets/framework.dart';
import 'package:sky/src/widgets/icon.dart';
13 14 15
import 'package:sky/theme/shadows.dart';
import 'package:sky/theme/typography.dart' as typography;
import 'package:sky/theme/view_configuration.dart';
16 17 18 19

class ToolBar extends Component {

  ToolBar({
20
    Key key,
21 22 23 24 25 26 27 28 29 30 31 32 33 34
    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;
35 36
    TextStyle centerStyle = typography.white.title;
    TextStyle sideStyle = typography.white.body1;
37 38 39 40
    if (toolbarColor == null) {
      ThemeData themeData = Theme.of(this);
      toolbarColor = themeData.primaryColor;
      if (themeData.primaryColorBrightness == ThemeBrightness.light) {
41 42
        centerStyle = typography.black.title;
        sideStyle = typography.black.body2;
43 44 45 46 47 48 49
        iconThemeData = const IconThemeData(color: IconThemeColor.black);
      } else {
        iconThemeData = const IconThemeData(color: IconThemeColor.white);
      }
    }

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

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

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

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

    Widget content = new Container(
      child: new DefaultTextStyle(
71
        style: sideStyle,
72
        child: new Column([
73
            new Container(
74
              child: new Row(children),
75 76 77 78
              height: kToolBarHeight
            ),
          ],
          justifyContent: FlexJustifyContent.end
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
        )
      ),
      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;
  }

}