Commit 3cd58547 authored by Ian Hickson's avatar Ian Hickson

Clean up and document icon button color logic

parent 285c696f
...@@ -22,6 +22,11 @@ import 'theme.dart'; ...@@ -22,6 +22,11 @@ import 'theme.dart';
/// in your project's `flutter.yaml` file. This ensures that the /// in your project's `flutter.yaml` file. This ensures that the
/// MaterialIcons font is included in your application. This font is /// MaterialIcons font is included in your application. This font is
/// used to display the icons. /// used to display the icons.
///
/// See also:
///
/// * [IconButton], for interactive icons
/// * [Icons], for the list of available icons for use with this class
class Icon extends StatelessWidget { class Icon extends StatelessWidget {
Icon({ Icon({
Key key, Key key,
...@@ -41,6 +46,12 @@ class Icon extends StatelessWidget { ...@@ -41,6 +46,12 @@ class Icon extends StatelessWidget {
final IconData icon; final IconData icon;
/// The color to use when drawing the icon. /// The color to use when drawing the icon.
///
/// Defaults to the current [IconTheme] color, if any. If there is
/// no [IconTheme], then it defaults to white if the theme is dark
/// and black if the theme is light. See [Theme] to set the current
/// theme and [ThemeData.brightness] for setting the current theme's
/// brightness.
final Color color; final Color color;
Color _getDefaultColorForThemeBrightness(ThemeBrightness brightness) { Color _getDefaultColorForThemeBrightness(ThemeBrightness brightness) {
......
...@@ -20,12 +20,18 @@ import 'tooltip.dart'; ...@@ -20,12 +20,18 @@ import 'tooltip.dart';
/// ///
/// If the [onPressed] callback is not specified or null, then the button will /// If the [onPressed] callback is not specified or null, then the button will
/// be disabled, will not react to touch. /// be disabled, will not react to touch.
///
/// See also:
///
/// * [Icons]
/// * [AppBar]
class IconButton extends StatelessWidget { class IconButton extends StatelessWidget {
const IconButton({ const IconButton({
Key key, Key key,
this.size: 24.0, this.size: 24.0,
this.icon, this.icon,
this.color, this.color,
this.disabledColor,
this.onPressed, this.onPressed,
this.tooltip this.tooltip
}) : super(key: key); }) : super(key: key);
...@@ -39,9 +45,22 @@ class IconButton extends StatelessWidget { ...@@ -39,9 +45,22 @@ class IconButton extends StatelessWidget {
/// The icon to display inside the button. /// The icon to display inside the button.
final IconData icon; final IconData icon;
/// The color to use for the icon inside the button. /// The color to use for the icon inside the button, if the icon is enabled.
/// Defaults to the current color, as defined by [Icon.color].
///
/// The icon is enabled if [onPressed] is not null.
///
/// See also [disabledColor].
final Color color; final Color color;
/// The color to use for the icon inside the button, if the icon is disabled.
/// Defaults to the [ThemeData.disabledColor] of the current [Theme].
///
/// The icon is disabled if [onPressed] is null.
///
/// See also [color].
final Color disabledColor;
/// The callback that is invoked when the button is tapped or otherwise activated. /// The callback that is invoked when the button is tapped or otherwise activated.
/// ///
/// If this is set to null, the button will be disabled. /// If this is set to null, the button will be disabled.
...@@ -56,12 +75,17 @@ class IconButton extends StatelessWidget { ...@@ -56,12 +75,17 @@ class IconButton extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
assert(debugCheckHasMaterial(context)); assert(debugCheckHasMaterial(context));
Color currentColor;
if (onPressed != null)
currentColor = color;
else
currentColor = disabledColor ?? Theme.of(context).disabledColor;
Widget result = new Padding( Widget result = new Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: new Icon( child: new Icon(
size: size, size: size,
icon: icon, icon: icon,
color: onPressed != null ? color : Theme.of(context).disabledColor color: currentColor
) )
); );
if (tooltip != null) { if (tooltip != null) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment