首页 > 解决方案 > 不透明的不透明问题扑朔迷离

问题描述

我无法弄清楚如何实现不透明度,以便它不会影响其中的文本......我只是希望背景完全消失并留下文本。我不能把它留白,因为应用程序本身有背景

而且我也找不到有关如何在下面创建一条跨越屏幕的线以将瓷砖彼此分开的文档

这是我的清单

? new ListView.builder(
                    itemCount: controlHeadings.length,
                    itemBuilder: (BuildContext context, int index) {
                      return new Opacity(
                        opacity: 0.9,
                        child: new Card(
                          color: Theme.CompanyColors.coolGrey,
                          elevation: 2.0,
                          child: new ListTile(
                              leading: new Text(
                                "${controlHeadings[index]['id']}",
                                style: new TextStyle(
                                  color: Colors.white,
                                  fontWeight: FontWeight.bold,
                                ),
                              ),
                              title: new Text(
                                "${controlHeadings[index]['title']}",
                                style: new TextStyle(
                                  color: Colors.white,
                                  fontWeight: FontWeight.bold,
                                  fontSize: 15.0,
                                ),
                              ),

标签: flutter

解决方案


考虑Opacity作为过滤器。它完全影响它的孩子。考虑到这一点,您所要求的是“不可能的”。

相反,您应该提取需要绕过的内容,以Opacity确保它不是Opacity. 您可以通过使用来实现这一点Stack

Stack(
  children: [
    Positioned.fill(
      child: Opacity(
        opacity: .9,
        child: Card(color: Colors.red),
      ),
    ),
    Text("Not affected"),
  ],
)

或者,您可以更改CardusingwithOpacity方法的背景颜色:

Card(
  color: Colors.red.withOpacity(.9),
  child: Text("foo"),
)

推荐阅读