Reputation: 89
I'm using Positioned
widget nested in Stack
widget and giving it the values right and bottom.
It worked nicely until I tried it on other screens with different sizes as I should've expected.
After Googling and stackoverflow-ing all the answers I've found advise to calculate the position depending on the device screen width
and height
.
I'm wondering if there is any way to position a widget relatively to its parent or to the stack widget - something like position: relative
; in CSS -
Stack(
fit: StackFit.expand,
children: <Widget>[
Positioned(
child: Icon(
Icons.touch_app,
color: Colors.blueAccent,
),
right: 110.0,
bottom: 300.0,
),
GestureDetector(
child: Chart(occData),
onTap: _setDetailedView,
),
],
)
Upvotes: 4
Views: 177
Reputation: 1404
This would be align
Container(
child: Align(
alignment: Alignment.bottomRight,
child: Text("Comment")
),
),
or
Container(
child: Align(
alignment: Alignment(x, y), // <-- from 0 to 1, ex. 0.5, 0.5
child: Text("Comment")
),
),
you can align stuff in a Stack
like:
Stack(
children: <Widget>[
Align(
alignment: Alignment(0.5, 0.3),
child: Text("Comment: $comment")
),
],
),
Upvotes: 1