Michael
Michael

Reputation: 593

Positioned inside stack

How can I position widgets correctly?

I supposed the positioning should be by some template and not by the eye.

Lets say i want the white square will be in the top center of the black container, half inside the black container and half outside, How can i do this?

enter image description here

The code:

Positioned(
                top: 80,
                right: 30,
                left: 30,
                child: Container(
                  height: 200,
                  width: 400.0,
                  color: Colors.black,
                  child: Column(
                    children: <Widget>[],
                  ),
                ),
              ),
              Positioned(
                top: 40,
                child: Container(
                  height: 100.0,
                  width: 100.0,
                  color: Colors.white,
                ),
              ),

Upvotes: 0

Views: 48

Answers (1)

Arthur Khabirov
Arthur Khabirov

Reputation: 146

You can try like this

Stack(
      alignment: Alignment.center,
      children: <Widget>[
          Positioned(
            top: 80,
            right: 30,
            left: 30,
            child: Container(
              height: 200,
              width: 400.0,
              color: Colors.black,
              child: Column(
                children: <Widget>[],
              ),
            ),
          ),
          Positioned(
            top: 40,
            child: Container(
              height: 100.0,
              width: 100.0,
              color: Colors.white,
            ),
          ),
      ],
    )

Upvotes: 1

Related Questions