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"),
)
],
),
)
],
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.
Stack doesn't work inside Column - 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.
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.
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"),
)
],
),
),
)
],
),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With