WidgetStateColor class abstract
Defines a Color that is also a WidgetStateProperty.
This class exists to enable widgets with Color valued properties to also accept WidgetStateProperty<Color> values. A widget state color property represents a color which depends on a widget's "interactive state". This state is represented as a Set of WidgetStates, like WidgetState.pressed, WidgetState.focused and WidgetState.hovered.
WidgetStateColor should only be used with widgets that document their support, like TimePickerThemeData.dayPeriodColor.
To use a WidgetStateColor, you can either:
- Create a subclass of WidgetStateColor and implement the abstract
resolve
method. - Use WidgetStateColor.resolveWith and pass in a callback that will be used to resolve the color in the given states.
- Use WidgetStateColor.fromMap to assign a value using a WidgetStateMap.
If a WidgetStateColor is used for a property or a parameter that doesn't support resolving WidgetStateProperty<Color>s, then its default color value will be used for all states.
To define a const
WidgetStateColor, you'll need to extend
WidgetStateColor and override its resolve method. You'll also need
to provide a defaultValue
to the super constructor, so that we can know
at compile-time what its default color is.
class MyColor extends WidgetStateColor {
const MyColor() : super(_defaultColor);
static const int _defaultColor = 0xcafefeed;
static const int _pressedColor = 0xdeadbeef;
@override
Color resolve(Set<WidgetState> states) {
if (states.contains(WidgetState.pressed)) {
return const Color(_pressedColor);
}
return const Color(_defaultColor);
}
}
See also:
- MaterialStateColor, the Material specific version of
WidgetStateColor
.
- Inheritance
- Implemented types
Constructors
- WidgetStateColor(int defaultValue)
-
Abstract const constructor. This constructor enables subclasses to provide
const constructors so that they can be used in const expressions.
const
-
WidgetStateColor.fromMap(WidgetStateMap<
Color> map) -
Creates a WidgetStateColor from a WidgetStateMap<Color>.
constfactory
-
WidgetStateColor.resolveWith(WidgetPropertyResolver<
Color> callback) -
Creates a WidgetStateColor from a WidgetPropertyResolver<Color>
callback function.
factory
Properties
- a → double
-
The alpha channel of this color.
finalinherited
- alpha → int
-
The alpha channel of this color in an 8 bit value.
no setterinherited
- b → double
-
The blue channel of this color.
finalinherited
- blue → int
-
The blue channel of this color in an 8 bit value.
no setterinherited
- colorSpace → ColorSpace
-
The color space of this color.
finalinherited
- g → double
-
The green channel of this color.
finalinherited
- green → int
-
The green channel of this color in an 8 bit value.
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- opacity → double
-
The alpha channel of this color as a double.
no setterinherited
- r → double
-
The red channel of this color.
finalinherited
- red → int
-
The red channel of this color in an 8 bit value.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- value → int
-
A 32 bit value representing this color.
no setterinherited
Methods
-
computeLuminance(
) → double -
Returns a brightness value between 0 for darkest and 1 for lightest.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
resolve(
Set< WidgetState> states) → Color -
Returns a Color that's to be used when a component is in the specified
state.
override
-
toString(
) → String -
A string representation of this object.
inherited
-
withAlpha(
int a) → Color -
Returns a new color that matches this color with the alpha channel
replaced with
a
(which ranges from 0 to 255).inherited -
withBlue(
int b) → Color -
Returns a new color that matches this color with the blue channel replaced
with
b
(which ranges from 0 to 255).inherited -
withGreen(
int g) → Color -
Returns a new color that matches this color with the green channel
replaced with
g
(which ranges from 0 to 255).inherited -
withOpacity(
double opacity) → Color -
Returns a new color that matches this color with the alpha channel
replaced with the given
opacity
(which ranges from 0.0 to 1.0).inherited -
withRed(
int r) → Color -
Returns a new color that matches this color with the red channel replaced
with
r
(which ranges from 0 to 255).inherited -
withValues(
{double? alpha, double? red, double? green, double? blue, ColorSpace? colorSpace}) → Color -
Returns a new color that matches this color with the passed in components
changed.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Constants
- transparent → const WidgetStateColor
- A constant whose value is transparent for all states.