Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stack inside Stack in flutter

I want to place Stack inside Stack in flutter, it dosen't work if I change position of inner Stack's positioned widgets.

works:

Stack(
    children: [
      Positioned(
        top: 150.0,
        child: Text("Text#1"),
      ),
      Positioned(
        top: 100.0,
        child: Stack(
          children: [
            Positioned(
              child: Text("Text#2"),
            )
          ],
        ),
      )
    ],
  )

If I add "top: 200.0" inside inner Stack's positioned, inner Stack disappears and flutter throws error

Stack(
    children: [
      Positioned(
        top: 150.0,
        child: Text("Text#1"),
      ),
      Positioned(
        top: 100.0,
        child: Stack(
          children: [
            Positioned(
              top:200.0,
              child: Text("Text#2"),
            )
          ],
        ),
      )
    ],
like image 887
Rafal Avatar asked Oct 22 '18 19:10

Rafal


People also ask

How do you Stack inside Stack in Flutter?

Yes, it is possible to wrap stack inside stack in Flutter. We can do this by wrapping the second stack inside the container with height and width property.

Can we use Stack inside column in Flutter?

Stack doesn't work inside Column - Flutter.

How do you Stack positions in Flutter?

Here's how you do it:Step 1: Wrap the Stack's child widget inside the Position widget. Step 2: Inside the Position widget, add the top , right , bottom , left property and give it a value. For example, setting top:15 and right:0 will position a widget on the top right of your screen with 15 px space from the top.

How do you make an overlay in Flutter?

The Overlay in Flutter makes it easy to create visual elements on top of other widgets by adding them to the Overlay's stack. OverlayEntry is used to insert a widget into the Overlay, then Positioned or AnimatedPositioned is used to determine where it will enter within the Overlay.


1 Answers

you can wrap your second Stack With Container with height and width property.

Stack fill height and width of parent widget but in your case height and width of parent widget is not define as it is a Stack Widget. if you define the size of parent widget so that stack widget can Positioned their child widget from their start point.

  Stack(
    children: [
      Positioned(
        top: 350.0,
        child: Text("Text#1"),
      ),
      Positioned(
        top: 100.0,
        child: Container(
          height: mediaQueryData.size.height,
          width: mediaQueryData.size.width,
          child: Stack(
            children: [
              Positioned(
                top:200.0,
                child: Text("Text#2"),
              )
            ],
          ),
        ),
      )
    ],
  ),
like image 60
Viren V Varasadiya Avatar answered Sep 23 '22 21:09

Viren V Varasadiya