iamSahdeep / seo_renderer

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

Add conditional imports to support including the widgets in VM builds. #4

Closed rydmike closed 3 years ago

rydmike commented 3 years ago

A quick example to demonstrate how to conditionally import different versions of the seo_renderer widgets that makes it possible to add the seo_renderer widgets also to VM builds. It only returns stubs that don't do anything useful on VM, and only adds the SEO renderer divs on the Web build.

Using a shared abstract class could be nice improvement to ensure they always use the same interface.

The changes might seem big, but are not. I just had to move the content in link_renderer.dart to link_renderer_web.dart and text_renderer.dart to text_renderer_web.dart and make them conditionally import the original file of the "web" version in web builds and the added "_vm" stub version for inclusion in none web builds.

Also added runners for all platforms to the example, so I could try the build on other platforms too.

Now it builds on them too and you can include the seo_renderer on desired widgets also in cross platform projects. It does not add much overhead on VM builds, other than a bit extra "noise" in the tree, but if you need it for your Web cross-platform build, it is well worth the added "noise".

iamSahdeep commented 3 years ago

Thanks @rydmike This is great and working fine. I will add it as v0.1.0 soon.