WidgetModifier<Content extends Widget, Body extends Widget> class
abstract
A modifier that you apply to a widget or another widget modifier, producing a different version of the original value. Adopt the WidgetModifier protocol when you want to create a reusable modifier that you can apply to any widget. The example below combines several modifiers to create a new modifier that you can use to add background:
class BackgroundModifier implements WidgetModifier<Widget, DecoratedBox> { BackgroundModifier(this.color);
Color color;
@override DecoratedBox body(Widget content) { return DecoratedBox( decoration: BoxDecoration( color: color, ), child: content, ); } }
You can apply modifier(:) directly to a widget, but a more common and idiomatic approach uses modifier(:) to define an extension to widget itself that incorporates the widget modifier:
extension BackgroundExt on Widget { DecoratedBox background(Color color) { return modifier(BackgroundModifier(color)); } }
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
body(
Content content) → Body -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited