MaterialStateBorderSide class Null safety
Defines a BorderSide whose value depends on a set of MaterialStates which represent the interactive state of a component.
To use a MaterialStateBorderSide, you should create a subclass of a
MaterialStateBorderSide and override the abstract resolve
method.
This example defines a subclass of MaterialStateBorderSide, that resolves
to a red border side when its widget is selected.
To create a local project with this code sample, run:
flutter create --sample=material.MaterialStateBorderSide.1 mysample
flutter create --sample=material.MaterialStateBorderSide.1 mysample
This example defines a subclass of MaterialStateBorderSide, that resolves
to a red border side when its widget is selected.
class RedSelectedBorderSide extends MaterialStateBorderSide {
@override
BorderSide? resolve(Set<MaterialState> states) {
if (states.contains(MaterialState.selected)) {
return BorderSide(
width: 1,
color: Colors.red,
);
}
return null; // Defer to default value on the theme or widget.
}
}
// ...
bool isSelected = true;
Widget build(BuildContext context) {
return FilterChip(
label: Text('Select chip'),
selected: isSelected,
onSelected: (bool value) {
setState(() {
isSelected = value;
});
},
side: RedSelectedBorderSide(),
);
}
This class should only be used for parameters which are documented to take MaterialStateBorderSide, otherwise only the default state will be used.
- Inheritance
- Object
- BorderSide
- MaterialStateBorderSide
- Implemented types
Constructors
- MaterialStateBorderSide()
-
Creates a MaterialStateBorderSide.
const
Properties
- color → Color
-
The color of this side of the border.
final, inherited
- hashCode → int
-
The hash code for this object. [...]
read-only, inherited
- runtimeType → Type
-
A representation of the runtime type of the object.
read-only, inherited
- style → BorderStyle
-
The style of this side of the border. [...]
final, inherited
- width → double
-
The width of this side of the border, in logical pixels. [...]
final, inherited
Methods
-
copyWith(
{Color? color, double? width, BorderStyle? style}) → BorderSide -
Creates a copy of this border but with the given fields replaced with the new values.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a non-existent method or property is accessed. [...]
inherited
-
resolve(
Set< MaterialState> states) → BorderSide? -
Returns a BorderSide that's to be used when a Material component is
in the specified state. Return null to defer to the default value of the
widget or theme.
override
-
scale(
double t) → BorderSide -
Creates a copy of this border side description but with the width scaled
by the factor
t
. [...]inherited -
toPaint(
) → Paint -
Create a Paint object that, if used to stroke a line, will draw the line
in this border's style. [...]
inherited
-
toString(
) → String -
A string representation of this object. [...]
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator. [...]
inherited