【问题标题】:How to use Positioned widget to position at top right corner on stack如何使用定位小部件定位在堆栈的右上角
【发布时间】:2019-01-27 22:45:34
【问题描述】:

我想将我的对象放在堆栈的右上角。 这就是我所拥有的。我知道如果我将 all(LTRB) 设置为 0.0,图像就会放在中心。有没有更简单的方法让我把图片放在右上角?

Widget _buildRemoveIcon()
    {
        return Positioned(
            top:0.0,
            left:60.0,
            right: 0.0,
            bottom:0.0,
            child: Padding(
                padding: const EdgeInsets.all(8.0),
                child: new IconButton(
                        icon: Icon(
                            Icons.cancel,
                            color: Colors.red,
                            ),
                        onPressed: () {
                        }), //
                ),
            );
    }

【问题讨论】:

    标签: dart flutter


    【解决方案1】:

    只需从Positioned 小部件中删除leftbottom 参数,即可将您的小部件与右上角对齐。

    例子:

    Positioned(
      top:0.0,
      right: 0.0,
      child: Padding(
        padding: const EdgeInsets.all(8.0),
        child: new IconButton(
          icon: Icon(Icons.cancel,color: Colors.red,),
          onPressed: () {}),
      ),
    )
    

    【讨论】:

    • 如何为所有设备动态添加一个加号图标在小部件中另一个循环图像的右上角?就像一个圆形的个人资料图片图标,右上角有一个添加图片。
    • Stack 小部件与profilePic 小部件和plus 按钮一起使用为children。然后将plus 按钮与答案中给出的右上方对齐
    【解决方案2】:

    您可以使用Align 小部件:

    Align(
      alignment: Alignment.topRight,
      child: ...
    );
    

    【讨论】:

      猜你喜欢
      • 2020-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-08
      • 1970-01-01
      • 2021-11-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多