androidflutterdartflutter-html

Spaces between tags are ignored when rendering HTML to Flutter


Let’s say I have a function that receives a string that represents a text in HTML format and I want to show this text in Flutter. Some words in the text are supposed to be bold. If I have a few bold words in a row, the spaces between the tags are ignored. How can I show the text without it ignoring spaces?

For example if I use this code and wrap the text with the Html widget:

Html(data: "<b>hello</b> <b>world</b>"),

It shows helloworld but I want it to show hello world .
(If I don’t wrap it in Html the spaces are printed but I do need to render Html to a Flutter widget)

I would really appreciate your help.


Solution

  • Use a non-breaking space entity (&nbsp;).
    I don't know if it will work or not, but you should try this.

    Html(data: "<b>hello</b>&nbsp;<b>world</b>"),