简体   繁体   中英

How to use Positioned widget to position at top right corner on stack

I want to position my object on top right corner in a stack. This is what I have. I know if I set all(LTRB) to 0.0 the image is placed in the center. Is there a simpler way for me to place the image on the upper right corner ?

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: () {
                        }), //
                ),
            );
    }

Just remove the left and bottom parameters from Positioned widget to align your widget to the top right corner.

Example:

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: () {}),
  ),
)

在此处输入图片说明

You can use the Align widget:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM