diff --git a/sdk/BUILD.gn b/sdk/BUILD.gn index 513c79e59ec..41ac24cd09c 100644 --- a/sdk/BUILD.gn +++ b/sdk/BUILD.gn @@ -106,11 +106,13 @@ dart_pkg("sdk") { "lib/widgets/drawer.dart", "lib/widgets/drawer_header.dart", "lib/widgets/fixed_height_scrollable.dart", + "lib/widgets/flat_button.dart", "lib/widgets/floating_action_button.dart", "lib/widgets/icon.dart", "lib/widgets/icon_button.dart", "lib/widgets/ink_well.dart", "lib/widgets/material.dart", + "lib/widgets/material_button.dart", "lib/widgets/menu_divider.dart", "lib/widgets/menu_item.dart", "lib/widgets/modal_overlay.dart", diff --git a/sdk/lib/widgets/flat_button.dart b/sdk/lib/widgets/flat_button.dart new file mode 100644 index 00000000000..a312537dadc --- /dev/null +++ b/sdk/lib/widgets/flat_button.dart @@ -0,0 +1,36 @@ +// 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 '../theme2/colors.dart'; +import 'basic.dart'; +import 'material_button.dart'; + +export 'material_button.dart' show MaterialButtonTheme; + +class FlatButton extends MaterialButton { + FlatButton({ + String key, + Widget child, + bool enabled: true, + Function onPressed, + MaterialButtonTheme theme: MaterialButtonTheme.light + }) : super(key: key, + child: child, + enabled: enabled, + onPressed: onPressed, + theme: theme); + + Color get color { + if (!enabled || !highlight) + return null; + switch (theme) { + case MaterialButtonTheme.light: + return Grey[400]; + case MaterialButtonTheme.dark: + return Grey[200]; + } + } + + int get level => null; +} diff --git a/sdk/lib/widgets/material_button.dart b/sdk/lib/widgets/material_button.dart new file mode 100644 index 00000000000..616a2d32eca --- /dev/null +++ b/sdk/lib/widgets/material_button.dart @@ -0,0 +1,59 @@ +// 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 'basic.dart'; +import 'button_base.dart'; +import 'ink_well.dart'; +import 'material.dart'; + +enum MaterialButtonTheme { light, dark } + +// Rather than using this class directly, please use FlatButton or RaisedButton. +abstract class MaterialButton extends ButtonBase { + + MaterialButton({ + String key, + this.child, + this.enabled: true, + this.onPressed, + this.theme: MaterialButtonTheme.light + }) : super(key: key); + + Widget child; + bool enabled; + Function onPressed; + MaterialButtonTheme theme; + + void syncFields(MaterialButton source) { + child = source.child; + enabled = source.enabled; + onPressed = source.onPressed; + theme = source.theme; + super.syncFields(source); + } + + Color get color; + int get level; + + Widget buildContent() { + Widget contents = new Container( + padding: new EdgeDims.symmetric(horizontal: 8.0), + child: new Center(child: child) // TODO(ianh): figure out a way to compell the child to have gray text when disabled... + ); + return new EventListenerNode( + new Container( + height: 36.0, + constraints: new BoxConstraints(minWidth: 88.0), + margin: new EdgeDims.all(8.0), + child: new Material( + child: enabled ? new InkWell(child: contents) : contents, + level: level, + color: color + ) + ), + onGestureTap: (_) { if (onPressed != null && enabled) onPressed(); } + ); + } + +} diff --git a/sdk/lib/widgets/raised_button.dart b/sdk/lib/widgets/raised_button.dart index b3a742a3488..623b9ca072b 100644 --- a/sdk/lib/widgets/raised_button.dart +++ b/sdk/lib/widgets/raised_button.dart @@ -3,75 +3,45 @@ // found in the LICENSE file. import '../theme2/colors.dart'; -import '../theme2/edges.dart'; import 'basic.dart'; -import 'button_base.dart'; -import 'ink_well.dart'; -import 'material.dart'; +import 'material_button.dart'; -enum RaisedButtonTheme { light, dark } +export 'material_button.dart' show MaterialButtonTheme; -class RaisedButton extends ButtonBase { +class RaisedButton extends MaterialButton { RaisedButton({ String key, - this.child, - this.enabled: true, - this.onPressed, - this.theme: RaisedButtonTheme.light - }) : super(key: key); + Widget child, + bool enabled: true, + Function onPressed, + MaterialButtonTheme theme: MaterialButtonTheme.light + }) : super(key: key, + child: child, + enabled: enabled, + onPressed: onPressed, + theme: theme); - Widget child; - bool enabled; - Function onPressed; - RaisedButtonTheme theme; - - void syncFields(RaisedButton source) { - child = source.child; - enabled = source.enabled; - onPressed = source.onPressed; - theme = source.theme; - super.syncFields(source); - } - - Widget buildContent() { - Widget contents = new Container( - padding: new EdgeDims.symmetric(horizontal: 8.0), - child: new Center(child: child) // TODO(ianh): figure out a way to compell the child to have gray text when disabled... - ); - Color color; + Color get color { if (enabled) { switch (theme) { - case RaisedButtonTheme.light: + case MaterialButtonTheme.light: if (highlight) - color = Grey[350]; + return Grey[350]; else - color = Grey[300]; + return Grey[300]; break; - case RaisedButtonTheme.dark: + case MaterialButtonTheme.dark: if (highlight) - color = Blue[700]; + return Blue[700]; else - color = Blue[600]; + return Blue[600]; break; } } else { - color = Grey[350]; + return Grey[350]; } - return new EventListenerNode( - new Container( - height: 36.0, - constraints: new BoxConstraints(minWidth: 88.0), - margin: new EdgeDims.all(4.0), - child: new Material( - edge: MaterialEdge.card, - child: enabled ? new InkWell(child: contents) : contents, - level: enabled ? (highlight ? 2 : 1) : 0, - color: color - ) - ), - onGestureTap: (_) { if (onPressed != null && enabled) onPressed(); } - ); } + int get level => enabled ? (highlight ? 2 : 1) : 0; }