EasyFormGenericField<T> class
abstract
Base class for creating a form field.
It can be used as a basis for creating a custom field for a form, where controller support and processing of value changes are already implemented.
The value property allows you to read the value of the associated controller and change it; when the value changes, the field widget will also be rebuilt.
The descendant at least needs to implement a constructor
and the build
method.
An example of implementing a custom form field for choosing a color, together with the EasyFormFieldController constructor:
class ColorController extends EasyFormFieldController<Color> {
ColorController(Color value) : super(value);
}
class ColorField extends EasyFormGenericField<Color> {
ColorField({
Key key,
@required ColorController controller,
ValueChanged<Color> onChange,
}) : super(
key: key,
controller: controller,
onChange: onChange,
);
void _change() {
value = _getRandomColor();
}
Color _getRandomColor() {
return Color((Random().nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0);
}
@override
Widget build(BuildContext context) {
return Align(
alignment: Alignment.centerLeft,
child: GestureDetector(
onTap: _change,
child: Container(
width: 50,
height: 50,
decoration: BoxDecoration(
color: value,
border: Border.all(
color: Color(0xFF000000),
width: 2,
),
shape: BoxShape.circle,
),
),
),
);
}
}
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- EasyFormGenericField
Constructors
-
EasyFormGenericField({Key? key, required EasyFormFieldController<
T> controller, ValueChanged<T?> ? onChange}) -
const
Properties
-
controller
→ EasyFormFieldController<
T> -
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
-
onChange
→ ValueChanged<
T?> ? -
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- value ↔ T?
-
The current value of the form field.
getter/setter pair
Methods
-
build(
BuildContext context) → Widget -
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → EasyFormGenericFieldState< T> -
Creates the mutable state for this widget at a given location in the tree.
override
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of
DiagnosticsNode
objects describing this node's children.inherited -
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited