12

There is a default padding in flutter_html already when trying to parse text.

Below is the difference between using HTML(data: ...) and Text(...) widgets.

Top: HTML Widget, Bottom: Text Widget
Screenshot Reference

How can I remove the horizontal padding?

Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56
Mihail Iliev
  • 163
  • 1
  • 8

4 Answers4

40

The HTML or body is having a default padding and/or margin.

Try adding

"body": Style(margin: Margins.all(0), ...)

in the style parameter.

Sahil Sonawane
  • 1,144
  • 9
  • 18
6

Html has updated, so I update accepted answer:

          "body": Style(
            padding: EdgeInsets.zero,
            margin: Margins(
              bottom: Margin.zero(),
              left: Margin.zero(),
              top: Margin.zero(),
              right: Margin.zero(),
            ),
          ),
manhtuan21
  • 2,388
  • 2
  • 10
  • 24
1

Add inside the style parameter curly brackets.

 body : Style(margin: Margins.zero) 
Ravindra S. Patil
  • 11,757
  • 3
  • 13
  • 40
Sharon Atim
  • 1,777
  • 16
  • 12
1

The syntax of redeclaring Html defaults changed a bit for the current package version. Now it should be the following:

Html(
    style: {
        "body": Style(
            padding: HtmlPaddings.zero,
            margin: Margins.zero)
        },
    data: text,
    onLinkTap: (url, attributes, element) {
        _onLinkTap(url);
    }
)
Anatolii
  • 21
  • 3