build method

  1. @override
Widget build(
  1. BuildContext context
)
override

Builds an expanded DropdownButton whose items come from InspectableProperty.values.

The selected value is read from the first owner on every build, so the dropdown always reflects the current state. Changes are applied to all owners simultaneously.

Implementation

@override
Widget build(BuildContext context) {
  Enum? value;
  var property =
      widget.owners[0].getProperty(widget.propertyName)
          as InspectableProperty<Enum>?;
  var values = property!.values!();
  value = property.getValue(widget.owners[0]);

  var items = values
      .map((e) => DropdownMenuItem(value: e, child: Text(e.name)))
      .toList();
  if (nullable) {
    items.add(DropdownMenuItem(value: null, child: Text('')));
  }

  return DropdownButton(
    items: items,
    isDense: true,
    isExpanded: true,
    value: value,
    onChanged: (value) {
      if (!readOnlyProperty) {
        for (var owner in widget.owners) {
          var property =
              owner.getProperty(widget.propertyName)
                  as InspectableProperty<Enum>?;
          //if (property != null && property.setValue != null) {
          property!.setValue!(owner, value, widget.customData);
          //}
        }
        if (widget.onUpdateProperty != null) {
          widget.onUpdateProperty!(value);
        }
        if (mounted) {
          setState(() {});
        }
      }
    },
  );
}