如何使小部件在颤动中相互漂浮

how to make widgets float over each other in flutter

如何使这两个(如图所示)以这种方式漂浮在卡片上(稍微对齐卡片边框)。

the requested design

这是小部件代码

卡片( 形状:RoundedRectangleBorder( 边界半径:BorderRadius.circular(20), ), 海拔:3, //颜色:Colors.orange, child:容器(宽度:140,高度:140, child: Image.asset('assets/c1.png', scale:1,), ), ),

试试 Stack class - 看起来您想将小部件排列在彼此之上。

https://api.flutter.dev/flutter/widgets/Stack-class.html

下面的代码用于创建它。红牌可以是图像,并相应地定位。

 Stack(
      overflow: Overflow.visible,
      children: [
        Positioned(
            top: 10,
            right: -20,
            child: Card(
              elevation: 3,
              color: Colors.red.withOpacity(0.5),
              child: Container(width: 30, height: 50),
            )),
        Card(
          elevation: 1,
          color: Colors.purple,
          child: Container(
            width: 250,
            height: 250,
          ),
        ),
        Positioned(
            top: 20,
            left: -20,
            child: Card(
              elevation: 3,
              color: Colors.orange,
          child: Container(width: 80, height: 80),
        )),

        Positioned(
            top: 20,
            right: -20,
            child: Card(
              elevation: 3,
              color: Colors.red,
              child: Container(width: 120, height: 50),
            ))
      ],
    )