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.75k stars 805 forks source link

How to use ImageExtension ? #1409

Open zxl777 opened 3 months ago

zxl777 commented 3 months ago

I previously added rounded corners to <img> tags in an older version of flutter_html, but how should I achieve the same effect with the new ImageExtension?

                    customRender: {
                      'img': (context, child) {
                        return ClipRRect(
                          borderRadius: BorderRadius.circular(5.0),
                          child: (context.tree as ImageContentElement).toWidget(context),
                        );
                      }
                    }
azeunkn0wn commented 2 weeks ago

Try this:

 ImageExtension(
     builder: (extensionContext) {
          final element = extensionContext.styledElement as ImageElement;

          return ClipRRect(
              borderRadius: BorderRadius.circular(5.0),                         
              child: Image.network(
                  element.src,
                ),
              );
            },
          ),