首页 > 解决方案 > 使 CircularProgressIndicator 的背景在颤动中透明

问题描述

我在登录时在我的应用程序中集成了 CircularProgressIndicator。该指示器根据需要可见,但它用白色覆盖层隐藏了我的登录屏幕。我想让它的背景透明而不是白色。我试图给 CircularProgressIndicator 的背景颜色,但它没有做任何改变。这是我的代码:

    child: !_isLoading ? _loginScreen(loginBloc.state) : Center(
      child: const SizedBox(
        width: 40,
        height: 40,
        child: CircularProgressIndicator(), 
      ),
    )

谢谢你。

标签: flutter

解决方案


您可以Stack在其子项上使用不同的不透明度。

例如

Stack(
      children: <Widget>[
        Opacity(
          opacity: 1, // You can reduce this when loading to give different effect
          child: AbsorbPointer(
            absorbing: _isLoading,
            child: _loginScreen(loginBloc.state),
          ),
        ),
        Opacity(
          opacity: _isLoading ? 1.0 : 0, 
          child: CircularProgressIndicator(),
        ),
      ],
    );

如果您想要有效的解决方案,我会在https://github.com/yagnyam-in/proxy-flutter/blob/master/lib/widgets/loading.darthttps://github.com/yagnyam-中大量使用它在/proxy-flutter/blob/master/lib/widgets/async_helper.dart


推荐阅读