iamSahdeep / seo_renderer

A Flutter Web Plugin to display Text Widget as Html for SEO purpose
MIT License
114 stars 15 forks source link

support specifying heading elements without importing dart:html #10

Closed clragon closed 2 years ago

clragon commented 2 years ago

It would be nice if Header elements could be specified for TextRenderer without having to import dart:html. This would allow making sure certain things are rendered as Headers when needed without making the code dependent on web.

One approach for doing this would be to replace the element parameter on TextRenderer with an Enum like this:

enum ```dart enum HtmlTextType { paragraph, header1, header2, header3, header4, header5, header6, } ```

Both the web text renderer and the vm text renderer could accept this parameter and handle it differently: by converting it into a Html Heading element on web and ignoring it on VM.

type conversion ```dart HtmlElement typeToElement(HtmlTextType? type) { switch (type) { case HtmlTextType.header1: return HeadingElement.h1(); case HtmlTextType.header2: return HeadingElement.h2(); case HtmlTextType.header3: return HeadingElement.h3(); case HtmlTextType.header4: return HeadingElement.h4(); case HtmlTextType.header5: return HeadingElement.h5(); case HtmlTextType.header6: return HeadingElement.h6(); case HtmlTextType.paragraph: default: return ParagraphElement(); } } ```
iamSahdeep commented 2 years ago

Thanks @clragon I will surely work on it as it seems a very nice way to make people not import dart:html in their code. If you want to work on it and raise a PR let me know, otherwise I'll take it probably this weekend.