build method
Widget
build({
- required BuildContext context,
- required FormMapper mapper,
- required TypeProperty property,
- required Keywords args,
override
build and bind the corresponding widget
context a FormMapper
mapper the FormMapper
property a TypeProperty
args and parameters that will be handled by the adapter
Implementation
@override
Widget build({required BuildContext context, required FormMapper mapper, required TypeProperty property, required Keywords args}) {
WidgetProperty? widgetProperty = mapper.findWidgetById("$name:${property.path}"); // TODO
var (displayValue, parseValue, validate, textInputType, inputFormatters) = customize(property);
TextEditingController? controller;
FocusNode? focusNode;
if ( widgetProperty != null) {
controller = widgetProperty.args["controller"];
focusNode = widgetProperty.args["focusNode"];
}
else {
controller = TextEditingController();
focusNode = FocusNode();
controller.addListener(() {
mapper.notifyChange(property: property, value: parseValue(controller!.text));
});
} // else
TextFormField result = TextFormField(
key: ValueKey("$name:${property.path}"), // TODO was path
controller: controller,
focusNode: focusNode,
style: args.get<TextStyle>('style'),
validator: validate,
keyboardType: textInputType,
inputFormatters: inputFormatters
);
mapper.map(property: property, widget: result, adapter: this, displayValue: displayValue, parseValue: parseValue);
if ( widgetProperty == null) {
widgetProperty = mapper.findWidgetById("$name:${property.path}")!;
widgetProperty.args["controller"] = controller;
widgetProperty.args["focusNode"] = focusNode;
}
return result;
}