How to position children in stack in flutter?
If you want the CircleAvatar to be in front of the Column, you need to put it at the last position in the list passed to Stack.children
.
Stack(
overflow: Overflow.visible,
children: [
Positioned(
left: 10,
child: Column(
children: [...],
),
),
// --- mind the swapped position of CircleAvatar and Column ---
Positioned(
right: 100,
child: CircleAvatar(...),
),
],
),
Does this answer your question?
Muhammad bakr
I am senior student in Faculty of Computers and Artificial Intelligence - Cairo University. Looking to learn new technologies.
Updated on December 02, 2022Comments
-
Muhammad bakr over 1 year
quick questions.. if i have a stack contains 2
Positioned
children widgets , one of them containsCircleAvatar
widget and the other isColumn
widget which contains twoInkWell
widgets so when I add a positionleft:10,
for example the wholeCircleAvatar
andColumn
disappers and i can't figure why the code is like below:Stack( overflow: Overflow.visible, children: [ Positioned( right: 100, child: CircleAvatar( maxRadius: 75, backgroundColor: Colors.white, child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Text( balance.toString(), style: TextStyle( fontSize: 23, fontWeight: FontWeight.bold, color: Colors.black, ), ), Text( 'EGP', style: TextStyle( fontSize: 28, fontWeight: FontWeight.bold, color: Color(0xffa80f14), ), ) ], ), ), ), Positioned( // left:10, child: Column( children: [ SizedBox( height: 18, ), InkWell( onTap: () { //Navigator.popAndPushNamed(context, 'Recharge'); }, child: Container( width: 170, height: 50, decoration: BoxDecoration( color: Color(0xffa80f14), borderRadius: BorderRadius.circular(20), boxShadow: [ BoxShadow( color: Colors.white, offset: Offset(0, 1), spreadRadius: -2, blurRadius: 6, ), ], ), child: Center( child: Text( "Recharge", style: TextStyle( color: Color(0xFFFFFFFF), fontSize: 20, fontWeight: FontWeight.bold, fontStyle: FontStyle.italic, ), ), ), ), ), SizedBox( height: 15, ), InkWell( onTap: () { //Navigator.pushNamed(context, 'MyTickets'); }, child: Container( width: 170, height: 50, decoration: BoxDecoration( color: Color(0xffa80f14), borderRadius: BorderRadius.circular(20), boxShadow: [ BoxShadow( color: Colors.white, offset: Offset(0, 1), spreadRadius: -2, blurRadius: 6, ), ], ), child: Center( child: Text( "My Tickets", style: TextStyle( color: Color(0xFFFFFFFF), fontSize: 20, fontWeight: FontWeight.bold, fontStyle: FontStyle.italic, ), ), ), ), ), ], ), ), ], ),
so if i uncomment
left:10,
the content of thestack
comes away and this error appearsThe following assertion was thrown during performLayout(): 'package:flutter/src/rendering/stack.dart': Failed assertion: line 588 pos 12: 'size.isFinite': is not true.