如何在颤振中创建透明容器

时间:2021-02-06 16:11:25

标签: flutter dart flutter-layout flutter-web

我想让一个容器像这样透明:enter image description here

这是容器代码:

let dayChangePublisher = NotificationCenter.default
    .publisher(for: UIApplication.significantTimeChangeNotification)

$entities.combineLatest(
   dayChangePublisher
      .map { _ in }
      .prepend(()) // make sure to prepend a () value
    )
    .map(\.0) // Only pass on the entity for further operations
    .map { entities -> MyEntity? in
        let today = todaysDate()
        return entities?.first(where: { $0.id == today })
    }
    //... 

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

如何使容器透明?

2 个答案:

答案 0 :(得分:1)

尝试对 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,
      ),
   ],
),

答案 1 :(得分:0)

尝试将其包裹在 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),
   ),
)