flat_button.dart 2.68 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 'button.dart';
8
import 'theme.dart';
9

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
/// A material design "flat button".
///
/// A flat button is a section printed on a [Material] widget that reacts to
/// touches by filling with color.
///
/// Use flat buttons on toolbars, in dialogs, or inline with other content but
/// offset from that content with padding so that the button's presence is
/// obvious. Flat buttons intentionally do not have visible borders and must
/// therefore rely on their position relative to other content for context. In
/// dialogs and cards, they should be grouped together in one of the bottom
/// corners. Avoid using flat buttons where they would blend in with other
/// content, for example in the middle of lists.
///
/// If the [onPressed] callback is not specified or null, then the button will
/// be disabled, will not react to touch, and will be colored as specified by
/// the [disabledColor] property instead of the [color] property. If you are
/// trying to change the button's [color] and it is not having any effect, check
/// that you are passing a non-null [onPressed] handler.
///
/// See also:
///  * [RaisedButton] class
///  * https://www.google.com/design/spec/components/buttons.html
32 33
class FlatButton extends MaterialButton {
  FlatButton({
34
    Key key,
35
    Widget child,
36 37 38 39 40 41
    ButtonColor textTheme,
    Color textColor,
    Color disabledTextColor,
    this.color,
    this.colorBrightness,
    this.disabledColor,
42
    VoidCallback onPressed
43 44
  }) : super(key: key,
             child: child,
45 46 47
             textTheme: textTheme,
             textColor: textColor,
             disabledTextColor: disabledTextColor,
48 49
             onPressed: onPressed);

50 51
  /// The color of the button, as printed on the [Material]. Defaults to null,
  /// meaning transparent.
52
  final Color color;
53 54 55 56

  /// The color of the button when the button is disabled. Buttons are disabled
  /// by default. To enable a button, set its [onPressed] property to a non-null
  /// value.
57 58 59 60 61
  final Color disabledColor;

  /// Controls the default text color if the text color isn't explicit set.
  final ThemeBrightness colorBrightness;

62
  _FlatButtonState createState() => new _FlatButtonState();
63 64
}

65
class _FlatButtonState extends MaterialButtonState<FlatButton> {
66

Hans Muller's avatar
Hans Muller committed
67
  int get elevation => 0;
68

69 70 71 72
  Color getColor(BuildContext context) {
    if (!config.enabled)
      return config.disabledColor;
    return config.color;
73 74
  }

75
  ThemeBrightness getColorBrightness(BuildContext context) {
76
    return config.colorBrightness ?? Theme.of(context).brightness;
77 78
  }

79
}