Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The background color before display. #23

Closed
blackredscarf opened this issue Mar 30, 2020 · 6 comments
Closed

The background color before display. #23

blackredscarf opened this issue Mar 30, 2020 · 6 comments

Comments

@blackredscarf
Copy link

blackredscarf commented Mar 30, 2020

Though I set the background color, background color before display is white on a tick. If my app background is no white, even is black, it will be disharmony.

尽管设置了背景颜色,但在视图显示之前,会有一瞬间的白色。如果我的APP背景颜色不是白色,甚至是黑色,将导致严重的色差冲突。

@entronad
Copy link
Owner

This is caused by the forced white background of webview in webview_flutter plugin. Now we don't have any workaround to avoid the white blink before the chart is loaded. Many people are following this issue of webview_flutter: flutter/flutter#29300
We hope this will be fixed soon.

这是由于 webview_flutter 强制 webview 的背景颜色为白色(而不是透明),
目前没有好的办法解决因此导致的加载完成前一瞬间的白色,很多人也在跟进 webview_flutter 的这个问题:flutter/flutter#29300
希望在下个版本中会改进

@blackredscarf
Copy link
Author

blackredscarf commented Mar 30, 2020

@entronad
OK. My temporary solution is to use Opacity to make Echarts invisiable, and waiting a tick when Echarts starts to render, after that making Echarts visiable.

Opacity(
  opacity: opacity,
  child: Container(
	child: Echarts(
	  key: chartKey,
	  onMessage: (emsg) {
		if(emsg == 'rendered') {
		  if(opacity == 0) {  // wait the render of chart
			Future.delayed(Duration(milliseconds: 50), () {
			  opacity = 1;
                          setState({});
			  // or bloc.add();
			});
		  }
		}
	  },
	  extraScript: '''
		  chart.on('rendered', () => {
			Messager.postMessage('rendered');
		  });
		''',

@entronad
Copy link
Owner

@blackredscarf
Dose this work on iOS?
We have thought about this way, but according to my experiment and this user's case: #18 (comment) , echarts dosen't work well in Opacity.

@blackredscarf
Copy link
Author

blackredscarf commented Apr 1, 2020

@entronad
I only test it on Android now. I will have a try on iOS in a few months later.

@hakaari
Copy link

hakaari commented Jan 23, 2021

Wrapping chart with opacity doesn't work for me on iOS. A workaround I found until flutter/plugins#3431 is merged is to use stack & cover the chart until is starts to render.

    Stack(
      children: [
        Echarts(
          option: data,
          onMessage: (message) {
            if (opacity == 1) {
              setState(() {
                opacity = 0.0;
              });
            }
          },
          extraScript: '''
  chart.on('rendered', function () {
    Messager.postMessage('chart rendered');
  });
''',
        ),
        Opacity(
          opacity: opacity,
          child: Container(
            color: Colors.black,
            width: MediaQuery.of(context).size.width,
            height: MediaQuery.of(context).size.height,
          ),
        )
      ],
    );

@volgin
Copy link

volgin commented Feb 26, 2021

You don't need opacity. Simply show a Container on top of a chart with an "if" statement. For example,

bool _hideChart = true;
static const String _extraScript = '''
  chart.on('rendered', function () {
    Messager.postMessage('chart rendered');
  });
''';
...
return Stack(
        children: [
          Echarts(
            option: _dataString,
            extraScript: _hideChart ? _extraScript : null,
            onMessage: (message) {
              if (mounted && _hideChart) {
                setState(() {
                  _hideChart = false;
                });
              }
            },
          ),
          if (_hideChart)
            Container(
              color: Colors.black,
              width: MediaQuery.of(context).size.width,
              height: MediaQuery.of(context).size.height,
            ),
        ],
      );

This way you don't render an unnecessary widget with every refresh of a chart.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants