dvStudioStyled function

Widget dvStudioStyled(
  1. DVPageNode node,
  2. Widget built, {
  3. bool withAction = true,
})

Folds node's properties onto built as a DVModifier.

Every entry here is a control the builder's inspector can offer. A property the renderer ignores is one the inspector cannot meaningfully expose, so this list is the page builder's actual styling vocabulary.

withAction is false on the editing surface. The styling has to travel there and the behaviour must not: a canvas that navigates away when somebody taps the card they are editing is worse than one that shows the card unstyled.

Implementation

Widget dvStudioStyled(
  DVPageNode node,
  Widget built, {
  bool withAction = true,
}) {
  // A button is a button whatever it is styled with. Its semantics were a
  // modifier of the leaf's own, and a modifier replaces the one before it,
  // so the first colour somebody gave a button made it plain text to a
  // screen reader.
  final bool button = node.type == 'button';
  var modifier = button
      ? const DVModifier().semanticButton().minimumTapTarget()
      : const DVModifier();
  var modified = button;
  final Map<String, Object?> properties = dvStudioEffectiveProperties(node);

  for (final property in dvStudioProperties) {
    final applied = property.apply(
      modifier,
      properties[property.name],
      properties,
    );
    if (applied != null) {
      modifier = applied;
      modified = true;
    }
  }

  final action = node.action;
  if (withAction && action != null && action['type'] == 'navigate') {
    if (!dvStudioNodeHasText(properties)) {
      modifier = modifier.tooltip(dvStudioActionName(node, properties));
    }
    modifier = modifier.onPressed(
      DV.Navigation.to(DVRouteTarget('${action['to']}')),
    );
    modified = true;
  }

  if (!modified) return built;
  if (built is DVText) return built.modifier(modifier);
  if (built is DVBox) return built.modifier(modifier);
  return DVBox(built).modifier(modifier);
}