Flutter_widget_from_html: Text color doesn't change with theme

Created on 5 Jun 2020  Â·  7Comments  Â·  Source: daohoangson/flutter_widget_from_html

Hi,

Thanks for creating this awesome widget!

I noticed that HtmlWidget won't change its text color when the app theme changes, and I'm wondering is it expected?

Code

class DemoText extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _DemoTextState();
  }
}

class _DemoTextState extends State<DemoText> {
  bool useText = false;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.light(),
      darkTheme: ThemeData.dark(),
      home: Scaffold(
        appBar: AppBar(
          title: MaterialButton(
            child: Text('Switch'),
            onPressed: () {
              setState(() {
                useText = !useText;
              });
            },
          ),
        ),
        body: Center(
          child: useText
              ? Text('test color when theme change, current : Text Widget')
              : HtmlWidget(
                  '<div>test color when theme change, current : HtmlWidget</div>',
                ),
        ),
      ),
    );
  }
}

demo
https://imgur.com/a/vmMRBRH

version:

flutter_widget_from_html: ^0.4.1-rc.2020052701

Flutter 1.17.3 • channel stable • https://github.com/flutter/flutter.git
Framework • revision b041144f83 (14 hours ago) • 2020-06-04 09:26:11 -0700
Engine • revision ee76268252
Tools • Dart 2.8.4

The closest bug I can find is https://github.com/daohoangson/flutter_widget_from_html/issues/112, which states there's some improvment, but seems like it desn't work for me

(if that's worth mentioning, in my case I need to use HtmlWidget with enableCaching = false since I want to dymanically change customWidgetBuilder based on some user options)

bug

All 7 comments

This looks like a bug, it's different from #112 though. Let me see what is happening. Thank you for the detailed report.

Weird, I just rebuilt the application from a cold restart and can no longer reproduce this issue with enableCaching = false -- which is the setting I'm curretly using in my app(but still reproducible with enableCaching = true -- the setting in bug demo code, which is probably expected, since it's cached?).

That's good to know that it works with enableCaching=false but it should work with enableCaching=true too.

v0.4.1 has been released with a fix for this, please try upgrading and see whether it works for your app. Thank you.

It works! Thanks!

@edwardez , am facing the same issue, my text color doesn't change and according to your posted code, it shows that you where switching between the Text(), and HtmlWidget, my approach was to change the them of the HtmlWidget, but it doesn't seem to work. The version am using is: 0.5.1+5 (latest)

I did this enableCaching=true and this enableCaching=false but no luck still, did I miss something ?

This is my current implementation :

HtmlWidget(
        newsItem.body,
        textStyle: Theme.of(context).textTheme.bodyText2.copyWith(
            fontWeight: FontWeight.w600),
        enableCaching: true,
        webView: true,
        key: ValueKey(Theme.of(context).brightness),
        onTapUrl: (url){
          _launchURL(url);
        },
      ),

cc @daohoangson

@huxaiphaer I have replied to your issue here.

Was this page helpful?
0 / 5 - 0 ratings