Flutter_widget_from_html: Border css not working

Created on 22 Aug 2020  路  7Comments  路  Source: daohoangson/flutter_widget_from_html

In this code all the shown inline styles are working except border:

...
        return HtmlWidget(
          text,
          enableCaching: false,
          customStylesBuilder: (element) {
            final styles = <String>[];

            if (element.localName == 'blockquote')
              styles.addAll([
                'margin',
                '0',
                'padding',
                '10px 15px',
                'border',
                '1px solid red',
              ]);

            if (element.localName == 'blockquote' &&
                element.className == 'blue')
              styles.addAll(
                ['background-color', themeState.aayahBlockquoteBlueBg],
              );
...

            return styles;
          },
          textStyle: TextStyle(
            fontSize: state.fontSize,
            height: 1.6,
            color: themeState.htmlTextColor,
          ),
          hyperlinkColor: Theme.of(context).primaryColor,
        );
...
enhancement

All 7 comments

This is expected. Only table border and inline top/bottom borders are supported for now. See list of all supported styling here.

For v0.5, it will probably won't include border generic support. Maybe 0.6 or later.

Actually border-top doesn't work either. In source code I've seen border and I thought that it means both top and bottom borders.

Hmm, it should work. Considering this widget:

test.dart

import 'package:flutter/material.dart';
import 'package:flutter_widget_from_html/flutter_widget_from_html.dart';

class Test extends StatelessWidget {
  @override
  Widget build(BuildContext context) => Scaffold(
        appBar: AppBar(title: Text('Issue 289')),
        body: SingleChildScrollView(
          child: Padding(
            child: HtmlWidget(kHtml),
            padding: const EdgeInsets.all(8.0),
          ),
        ),
      );
}

const kHtml = """
<span>
  Inline borders:
  <span style="border-top: 1px solid red">
    top

    <span style="border-bottom: 1px solid red">top+bottom</span>

    top
  </span>
  nothing.
</span>
""";

It will look like this:

Screen Shot 2020-08-23 at 10 06 51 PM

Which is pretty close to how Chrome renders it:

Screen Shot 2020-08-23 at 10 07 22 PM

Thanks @daohoangson for replies. I guess the problem is with customStylesBuilder. I took your code from here, added border-top style and it doesn't work. The repo with the test is here.

Hmm, I have just cloned your repo and ran it. It seemed to work?

@daohoangson Thank you for test. Upgraded flutter from 1.20.1 to 1.20.2 (and make flutter clean) and a border has appeared.

That's great to hear. I didn't test with 1.20.1 specifically (this feature has been done a long time ago). But maybe the .2 version fixed something right there 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SoFo12 picture SoFo12  路  4Comments

forever84721 picture forever84721  路  4Comments

ahmadkhedr picture ahmadkhedr  路  7Comments

ahmadkhedr picture ahmadkhedr  路  6Comments

theneshofficial picture theneshofficial  路  4Comments