Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

flutter

dart

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: () {
                        }), //
                ),
            );
    }
like image 911
MistyD Avatar asked Jan 27 '19 22:01

MistyD


1 Answers

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

enter image description here

like image 197
thedarthcoder Avatar answered Nov 09 '22 02:11

thedarthcoder