我怎样才能在扑朔迷离中将孩子从堆中取出?

时间:2019-04-23 13:50:55

标签: flutter

我正在快速创建WebView。我想在页面加载时将CircularProgressIndicator显示为覆盖。为此,我使用了一个堆栈,其中顶部的子项是在Center中带有CircularProgressIndicator的Container,而WebView加载为底部的子项。现在,我在WebView中看到一个名为onPageFinished的回调,我想使用该回调来删除堆栈顶部的Container。我似乎没有找到从堆栈中删除子项的方法。我该如何实施呢?

Stack(
  children: <Widget>[
    WebView(
      initialUrl: 'https://www.google.com',
      javascriptMode: JavascriptMode.unrestricted,
      onPageFinished: hideLoader,
    ),
    Container(
      decoration: BoxDecoration(
        color: Color.fromRGBO(0, 0, 0, 0.5),
      ),
      child: Center(
        child: CircularProgressIndicator(),
      ),
    )
  ],
)),

void hideLoader(String url) {}

1 个答案:

答案 0 :(得分:1)

尝试以下代码

    Stack(
      children: <Widget>[
        WebView(
          initialUrl: 'https://www.google.com',
          javascriptMode: JavascriptMode.unrestricted,
          onPageFinished: hideLoader,
        ),
        this._hideLoader == true
        ? Container(
            decoration: BoxDecoration(
              color: Color.fromRGBO(0, 0, 0, 0.5),
            ),
            child: Center(
              child: CircularProgressIndicator(),
            ),
          )
        : Container()
      ],
    )),
  bool _hideLoader = false;
  void hideLoader(String url) {
    setState(() {
      this._hideLoader = false;
    });
  }
相关问题