【问题标题】:How to create a transparent container in flutter如何在颤振中创建透明容器
【发布时间】:2021-05-10 17:19:35
【问题描述】:

我想让一个容器像这样透明:

这是容器代码:

: Container(child: Column(
    children: [
             Container(child: Text('Address: '), alignment: Alignment.centerLeft,),
             Divider(color: Colors.grey,),
             Container(child: Text('$address'), alignment: Alignment.centerLeft,),
             ],
            ),
   color: Color(0xFF005D6C),
   );

如果我给 color: Color(0xFF005D6C).withOpacity(0.5) 那么,它只是让颜色像这样

如何让容器透明?

【问题讨论】:

    标签: flutter dart flutter-layout flutter-web


    【解决方案1】:

    尝试将其包裹在 Opacity Widget 中

    Opacity(
      opacity: 0.5,
      child: Container(child: Column(
        children: [
                 Container(child: Text('Address: '), alignment: Alignment.centerLeft,),
                 Divider(color: Colors.grey,),
                 Container(child: Text('$address'), alignment: Alignment.centerLeft,),
                 ],
                ),
       color: Color(0xFF005D),
       ),
    )
    

    【讨论】:

    • 现在容器的背景颜色不来了。
    • 你的背景中有某种图像吗?因为如果你下面只有一个白色的背景,颜色会显得更浅
    • 目前我没有任何背景图片。
    • 所以这可能是问题所在......尝试在背景中添加一些东西,如果你的容器变得透明,它会更容易看到
    • 我已经给背景赋予了白色,所以,如果我给容器赋予绿色并具有一定的不透明度,它应该使容器透明
    【解决方案2】:

    尝试将Colors.transparent + withOpacity 用于Container

    Container(
      color: Colors.transparent.withOpacity(0.5),
      child: Column(
        children: [
          Container(
            child: Text('Address: '),
            alignment: Alignment.centerLeft,
          ),
          Divider(
            color: Colors.grey,
          ),
          Container(
            child: Text('$address'),
            alignment: Alignment.centerLeft,
          ),
       ],
    ),
    

    【讨论】:

      猜你喜欢
      • 2022-01-23
      • 2020-01-28
      • 2021-05-01
      • 1970-01-01
      • 2019-03-10
      • 1970-01-01
      • 2021-05-09
      • 2018-07-21
      • 2020-10-13
      相关资源
      最近更新 更多