如何使用定位小部件定位在堆栈的右上角

Mis*_*tyD 8 dart flutter

我想将我的对象放在堆栈的右上角。这就是我所拥有的。我知道如果我将 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: () {
                        }), //
                ),
            );
    }
Run Code Online (Sandbox Code Playgroud)

Sid*_*kar 13

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

例子:

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: () {}),
  ),
)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明


cre*_*not 5

您可以使用Align小部件:

Align(
  alignment: Alignment.topRight,
  child: ...
);
Run Code Online (Sandbox Code Playgroud)