daohoangson / flutter_widget_from_html

Flutter package to render html as widgets that supports hyperlink, image, audio, video, iframe and many other tags.
https://pub.dev/packages/flutter_widget_from_html
MIT License
635 stars 235 forks source link

How can I justify all the content? #1124

Closed hortigado closed 10 months ago

hortigado commented 10 months ago

Hi in the package Html() i can do the following Html( style: { 'html': Style(textAlign: TextAlign.justify), }, ) Thanks

daohoangson commented 10 months ago

Assuming your HTML has the P tag. You can use customStylesBuilder to specify the text alignment. Something like this:

    HtmlWidget(
      html,
      customStylesBuilder: (e) {
        if (e.localName == 'p') {
          return {'text-align': 'justify'};
        }

        return null;
      },
    );
hortigado commented 10 months ago

@daohoangson Thanks and if the html not have a tag and it is only text. I am reading a database where different values are returned, some just text and others in html text with tags.

daohoangson commented 10 months ago

If you have no control then it's probably easiest to just wrap it inside a div to apply some global style.

final withStyle = '<div style="text-align: justify">$html</div>';
hortigado commented 10 months ago

Thank you, its working good.