build method

  1. @override
Widget build({
  1. required BuildContext context,
  2. required FormMapper mapper,
  3. required TypeProperty property,
  4. 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}) {
  final value = mapper.getValue(property);

  // Expected: args["items"] is List<String> or List<Map<String, dynamic>>
  final items = (args["items"] ?? <dynamic>[]).map<DropdownMenuItem>((item) {
    if (item is Map<String, dynamic>) {
      return DropdownMenuItem(
        value: item["value"],
        child: Text(item["label"] ?? item["value"].toString()),
      );
    } else {
      return DropdownMenuItem(value: item, child: Text(item.toString()));
    }
  }).toList();

  final dropdown = DropdownButton(
    key: ValueKey("$name:${property.path}"),
    value: value,
    items: items,
    isExpanded: args["expanded"] ?? true,
    hint: args["hint"] != null ? Text(args["hint"]) : null,
    onChanged: (newValue) {
      (context as Element).markNeedsBuild();
      mapper.notifyChange(property: property, value: newValue);
    },
  );

  mapper.map(property: property, widget: dropdown, adapter: this);

  return dropdown;
}