withText method

ShapeDefinition withText(
  1. DiagramTextDefinition text, {
  2. String? slot,
})

A copy whose text parts hold text, such as an extension's text in place of plain: every text part, or only the part filling slot. The shape declares its parts; which text fills them is this explicit configuration, never a condition inside the shape.

The copy keeps this type, so an application installs it in its own extension to replace this definition, a core shape's included:

DiagramExtension(
  id: 'app.shapes',
  shapes: [ShapeLibraries.standard.shape(Shapes.comment).withText(text)],
)

Every text type a shape holds must be installed by an extension. Throws an ArgumentError when the shape has no text part, or none filling slot.

Implementation

ShapeDefinition withText(DiagramTextDefinition text, {String? slot}) {
  final slots = {
    for (final layer in expandedLayers.whereType<ShapeTextLayerDefinition>())
      layer.slotId,
  };
  if (slot == null ? slots.isEmpty : !slots.contains(slot)) {
    throw ArgumentError(
      slot == null
          ? '$type has no text part.'
          : '$type has no text part filling $slot.',
    );
  }
  return ShapeDefinition._(
    _collapsed,
    texts: slot == null ? {null: text} : {..._texts, slot: text},
    type: type,
    name: name,
    size: size,
    minimumSize: minimumSize,
    style: style,
    shadow: shadow,
    outline: outline,
    body: body,
    values: values,
    previewValues: previewValues,
    adjustments: adjustments,
    connection: connection,
    container: container,
    collapse: collapse,
    behavior: behavior,
    fontSizeRange: fontSizeRange,
    textCreation: textCreation,
    verbs: verbs,
    affordances: affordances,
    properties: properties,
    inspector: inspector,
  );
}