首页 > 解决方案 > 颤振中的框架布局替代方案

问题描述

我想在另一个容器顶部添加一个颤振容器,顶部容器将是透明的。基本上我在原生 Android 中使用 FrameLayout 来做到这一点。如何在 Flutter 中实现这一点?

标签: androidflutterflutter-layout

解决方案


Stack很可能是你想要的。

Stack允许将小部件放在其他人的顶部,但是你喜欢。并且,结合Positioned,具有自定义职位。

让我们在颤振中绘制一个真实的框架:

在此处输入图像描述

Stack(
  alignment: Alignment.center,
  children: <Widget>[
    Container(
      width: 200.0,
      height: 300.0,
      decoration: BoxDecoration(
        color: Colors.black12,
        border: Border.all(
          color: Colors.black,
          width: 3.0,
        ),
      ),
    ),
    Container(
      width: 100.0,
      height: 100.0,
      color: Colors.blue,
    ),
    Positioned(
      bottom: 10.0,
      right: 10.0,
      child: Card(
        child: Padding(
          padding: const EdgeInsets.all(8.0),
          child: Text("Title"),
        ),
      ),
    )
  ],
),

推荐阅读