Sub6Resources / flutter_html

A Flutter widget for rendering static html as Flutter widgets (Will render over 80 different html tags!)
https://pub.dev/packages/flutter_html
MIT License
1.79k stars 860 forks source link

[QUESTION] How to match p tag with the new customRenderer #1308

Closed tobiasht closed 1 year ago

tobiasht commented 1 year ago

I want to remove the color from a p-tag, so i use a customRenderer. But I am unsure how to use the matcher with the new customRenderer to achieve this. This is what i have tried so far.

MatcherExtension(
  matcher: (p0) {
    return p0.element?.localName == 'p';
  },
  builder: (extensionContext) {
    return Container(
      width: double.infinity,
      color: Theme.of(context).scaffoldBackgroundColor,
      child: Text(
        extensionContext.element!.text,
        style: const TextStyle(
          color: BaseScheme.foregroundPrimary,
          height: 1.5,
          fontSize: 16,
          fontWeight: FontWeight.w400,
        ),
      ),
    );
  },
),
TagExtension(
  tagsToExtend: {"p"},
  builder: (extensionContext) {
    return Container(
      width: double.infinity,
      color: Theme.of(context).scaffoldBackgroundColor,
      child: Text(
        extensionContext.element!.text,
        style: const TextStyle(
          color: BaseScheme.foregroundPrimary,
          height: 1.5,
          fontSize: 16,
          fontWeight: FontWeight.w400,
        ),
      ),
    );
  },
),
tobiasht commented 1 year ago

Apparently it was working, i just had an error in my code. The second example is the correct way to do it.