asjqkkkk / markdown_widget

📖Rendering markdown by flutter!Welcome for pr and issue.
MIT License
321 stars 93 forks source link

How to center a custom tag? #99

Closed NicolasLaube closed 1 year ago

NicolasLaube commented 1 year ago

This isn't a feature request... I just wanted to add this remark because it took me a few minutes to figure out how to center a custom tag.

Say you have a custom tag.

To center the widget associated with this tag, just add: alignment: PlaceholderAlignment.middle to your custom WidgetSpan.

For example:


class DropPassiveNode extends SpanNode {
  final Map<String, String> attribute;

  DropPassiveNode(this.attribute);

  @override
  InlineSpan build() {
    final String identification = attribute['id'] ?? '';
    return WidgetSpan(
      child: GapDropPassive(identification),
      alignment: PlaceholderAlignment.middle,
    );
  }
}

SpanNodeGeneratorWithTag GENERATOR_DROP_PASSIVE = SpanNodeGeneratorWithTag(
  tag: _dropTag,
  generator: (e, config, visitor) => DropPassiveNode(e.attributes),
);
``

I hope it might help someone :)