close

Flutter position stack widget in center

Stacks versus Absolute/Fixed Positioning

A Stack permits you to stack components on top of one another, with the last component in the cluster taking the most noteworthy prority. You can utilize Align, Positioned or Container to situate the offspring of a stack.

Adjust

Gadgets are moved by setting the arrangement with Alignment, which has static properties like topCenter, bottomRight, etc. Or then again you can take full control and set Alignment(1.0, – 1.0), which takes x,y values going from 1.0 to – 1.0, with (0,0) being the focal point of the screen.

Stack(
    children: [
        MyWidget(),
        Align(
            alignment: Alignment.topCenter,
            child: MyWidget(),
        ),
        Container(
            alignment: Alignment(-0.9, -0.9),
            child: MyWidget(),
        )  
    ]
);
Image for post

Situated

As a choice to adjust, you can situate kids comparative with the parent gadget.

Stack(
    children: [
        MyWidget(),
        Positioned(
            bottom: 20,
            left: 20,
            child: MyWidget(color: Colors.blue),
        ),
        Positioned(
            top: 50,
            right: 50,
            child: MyWidget(color: Colors.red)
        )
    ]
)
Image for post

Furthermore, with CSS supreme situating.

.positioned {
    position: absolute;
    bottom: 20,
    left: 20,
}

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also Read

Leave a Comment