我需要像这样堆叠小部件:

coins

我写了下面的代码.然而,这些硬币一个接一个地出现,带有一些默认的填充物.我怎样才能得到像上图这样的东西?

Row(
  children: <Widget>[
    Icon(
      Icons.monetization_on, size: 36.0, 
      color: const Color.fromRGBO(218, 165, 32, 1.0),
    ),
    Icon(
      Icons.monetization_on, size: 36.0,
      color: const Color.fromRGBO(218, 165, 32, 1.0),
    ),
  ],
),

推荐答案

您可以使用StackPositioned来实现以下目标:

enter image description here

class StackExample extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(),
      body:  new Container(
        padding: const EdgeInsets.all(8.0),
          height: 500.0,
          width: 500.0,
          // alignment: FractionalOffset.center,
          child: new Stack(
            //alignment:new Alignment(x, y)
            children: <Widget>[
              new Icon(Icons.monetization_on, size: 36.0, color: const Color.fromRGBO(218, 165, 32, 1.0)),
              new Positioned(
                left: 20.0,
                child: new Icon(Icons.monetization_on, size: 36.0, color: const Color.fromRGBO(218, 165, 32, 1.0)),
              ),
              new Positioned(
                left:40.0,
                child: new Icon(Icons.monetization_on, size: 36.0, color: const Color.fromRGBO(218, 165, 32, 1.0)),
              )

            ],
          ),
        ),
      )
    ;
  }
}

这就是你如何得到一些漂亮的阴影,使图标更加突出:

enter image description here

class StackExample extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(),
      body:  new Container(
        padding: const EdgeInsets.all(8.0),
          height: 500.0,
          width: 500.0,
          // alignment: FractionalOffset.center,
          child: new Stack(
            //alignment:new Alignment(x, y)
            children: <Widget>[
              new Container(
                decoration: new BoxDecoration(
                  borderRadius: BorderRadius.circular(25.0),
                  boxShadow: [
                    new BoxShadow(
                      blurRadius: 5.0,
                      offset: const Offset(3.0, 0.0),
                      color: Colors.grey,
                    )
                  ]
                ),
                child: new Icon(Icons.monetization_on, size: 36.0, color: const Color.fromRGBO(218, 165, 32, 1.0))),
              new Positioned(
                left: 20.0,
                child: new Container(
                  decoration: new BoxDecoration(
                  borderRadius: BorderRadius.circular(25.0),
                  boxShadow: [
                    new BoxShadow(
                      blurRadius: 5.0,
                      offset: const Offset(3.0, 0.0),
                      color: Colors.grey,
                    )
                  ]
                ),
                  child: new Icon(Icons.monetization_on, size: 36.0, color: const Color.fromRGBO(218, 165, 32, 1.0))),
              ),
              new Positioned(
                left:40.0,
                child: new Container(
                  decoration: new BoxDecoration(
                  borderRadius: BorderRadius.circular(25.0),
                  boxShadow: [
                    new BoxShadow(
                      blurRadius: 5.0,
                      offset: const Offset(3.0, 0.0),
                      color: Colors.grey,
                    )
                  ]
                )
                  ,child: new Icon(Icons.monetization_on, size: 36.0, color: const Color.fromRGBO(218, 165, 32, 1.0))),
              )

            ],
          ),
        ),
      )
    ;
  }
}

Flutter相关问答推荐

Flutter iOS日期 Select 器UI中限制日期范围?

从Flutter应用程序解释蓝牙BLE数据:了解Sylvania压力值

FCM通知显示两次通知(&A)

使用GO_ROUTER在模式内导航

如何在容器小部件中的图像旁边添加文本?

将列表<;Events>;从Flutter 应用程序中的函数传回EventLoader属性时出错

Flutter 块消费者仅对特定的状态属性更改做出react

如何画三角形的圆角?

当我转到其他屏幕并按下后退按钮时,屏幕将不会刷新

如何使用providerContainer监听/写入FutureProvider?

点击后,将按钮的 colored颜色 禁用/更改一段时间

Flutter 中的 Provider 不会在第一次构建 App 时返回

围绕父组件旋转位置组件

我可以在列表图块下方添加其他小部件吗

如何更改 DropDownMenu 的显示方向?

应用程序包含嵌入式私钥或密钥库文件

有什么办法可以消除Flutter 中的传递依赖?

出现错误;运算符[]不是为对象类型定义的?功能()'

如何判断 text.contains() 是否包含多个值

将容器扩展到安全区域 - Flutter