For previous siblings, it works. But How to make widget appear on top next siblings in Row
and Column
?
I know that I can just force to make it work by moving the widget on top to the next siblings and make it appear on top on the previous siblings to achieve the same effect, but it just seems odd to me that Row
and Column
are actually Stack
but just with children displaced, not actually flat widgets with the same elevation
. I hope my understanding is wrong.
Widget _test() {
return StackTappableOutside( // change to Stack for testing
clipBehavior: Clip.none,
children: [
Container(
child: FlutterLogo(size: 80),
decoration: BoxDecoration(
color: Colors.deepOrange,
border: Border.all(color: Colors.yellow),
),
),
Positioned(
bottom: -22,
// right: -22,
child: TextButton(
child: Text("Close me"),
onPressed: () => print("You tapped me"),
),
),
],
);
}
Widget _body() {
// return Container(child: _test());
return Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(child: _test(),key: Key('first'),),
Container(child: _test(),key: Key('second'),),
Container(child: _test(),key: Key('thrid'),),
Container(child: _test(),key: Key('forth'),),
],
);
}
2
Answers
You can use
Transfrom.translate
,Align
withheightFactor
andwidthFactor
.A quick workaround is to set the
textDirection
of your widget toTextDirection.rtl
. You’ll also need to adjustmainAxisAlignment
toMainAxisAlignment.end
and reverse the order of your children. Your code will look like this:Row
andColumn
both extendFlex
, which stacks their children along the z-axis, similar toStack
. There’s an open issue on Flutter’s GitHub that discusses customizing this behavior.