populateProperty method

TableRow populateProperty(
  1. List<Inspectable> owners,
  2. String propertyName,
  3. int level
)

Builds a single TableRow for propertyName, resolving the editor to use via the editors map.

Resolution order:

  1. Exact type match in editors.
  2. Fall back to Enum editor when the exact type is not registered but the property type is an enum subtype.
  3. Fall back to the read-only EditorBase when no editor is found.

The level parameter increases the left-side indentation for nested sub-properties.

Implementation

TableRow populateProperty(
  List<Inspectable> owners,
  String propertyName,
  int level,
) {
  TableRow toReturn;
  EditorBase? editor;

  if (!keys.containsKey(propertyName)) {
    keys[propertyName] = GlobalKey();
  }
  Key? k = keys[propertyName];

  var property = owners[0].getProperty(propertyName) as InspectableProperty;
  //dynamic t = property.getValue(owners[0]);
  Type type = property.type;
  var editorBuilder = editors[type];
  if (editorBuilder == null && type is Enum) {
    type = Enum;
    editorBuilder = editors[type];
  }
  if (editorBuilder != null) {
    editor = editorBuilder(
      key: k,
      owners: owners,
      propertyName: propertyName,
      customData: widget.customData,
      onUpdatedProperty: propertyUpdated,
    );
  } else {
    editor = EditorBase(
      key: k,
      owners: owners,
      propertyName: propertyName,
      customData: widget.customData,
      onUpdatedProperty: propertyUpdated,
    );
  }

  toReturn = TableRow(
    key: UniqueKey(),
    children: [
      Padding(
        padding: EdgeInsets.only(left: 4.0, right: 4.0 + level * 4.0),
        child: Align(
          alignment: Alignment.centerRight,
          child: Text(propertyName),
        ),
      ),
      Padding(
        padding: const EdgeInsets.only(left: 4.0, right: 4.0),
        child: editor.getWidget(context),
      ),
    ],
  );

  /*if (property.getSubProperties != null) {
    var subProperties = property.getSubProperties!(obj);
    toReturn.addAll(populateProperties(obj, subProperties, level+1));
  }*/

  return toReturn;
}