1

Is something wrong with this snippet? The positioned element isn't showing up but the others are. deviceHeight is defined elsewhere as the height of the device.

The first container holds the other two containers under it. The second container appears at the top correctly, but the third one (positioned) which should be under the second one doesn't appear. Welcome to hear any alternatives.

Align(
    alignment: Alignment.bottomCenter,
    child: Stack(children: <Widget>[
      Container(
        color: Color(bgDark),
        height: deviceHeight / 100 * 40,
      ),
      Container(color: Colors.red, height: deviceHeight / 18),
      Positioned(
          top: 50,
          child: Container(
              color: Colors.green, height: deviceHeight / 1))
    ]))
1
  • Adding a width to the Positioned Container made it visible. I assumed random height and width values for example answer given below. Commented Jun 20, 2020 at 9:32

2 Answers 2

3

Adding a width to the Positioned Container made it visible.

Align(
      alignment: Alignment.bottomCenter,
      child: Stack(
        children: <Widget>[
          Container(
            color: Colors.blue,
            height: 300,
          ),
          Container(
            color: Colors.red,
            height: 200,
          ),
          Positioned(
            top: 50,
            child: Container(
              color: Colors.green,
              height: 100,
              width:100,
            ),
          ),
        ],
      ),
    );

I am not sure about the exact cause of the issue but it seems Positioned needed both height and width dimensions.

Sign up to request clarification or add additional context in comments.

Comments

0

You need to set up a width to the container, either if is width property or adding left: 0, right:0 (take all horizontal space possible) to the positioned widget

Align(
  alignment: Alignment.bottomCenter,
  child: Stack(
    children: <Widget>[
      Container(
        color: Color(bgDark),
        height: deviceHeight / 100 * 40,
      ),
      Container(
        color: Colors.red,
        height: deviceHeight / 18
      ),
      Positioned(
        top: 50,
        left: 0,
        right: 0,
        child: Container(
          color: Colors.green,
          height: deviceHeight / 1
        ),
      ),
    ],
  ),
);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.