I need to stack widgets like this:
I wrote the code below. However the coins are coming one after another with some default padding. How can I get something like the image above?
Row( children: <Widget>[ Icon( Icons.monetization_on, size: 36.0, color: const Color.fromRGBO(218, 165, 32, 1.0), ), Icon( Icons.monetization_on, size: 36.0, color: const Color.fromRGBO(218, 165, 32, 1.0), ), ], ),
A Stack widget allows us to make multiple widgets overlay each other.
In the first Container, the text is 'One', and the alignment is set to Alignment. topRight, which puts the Text widget in the top-right corner. In the second Container, the text is 'Two', and the alignment is set to Alignment. bottom left, which put the child which is the Text in the bottom-left corner.
You can use a Stack
with Positioned
to achieve this:
class StackExample extends StatelessWidget { @override Widget build(BuildContext context) { return new Scaffold( appBar: new AppBar(), body: new Container( padding: const EdgeInsets.all(8.0), height: 500.0, width: 500.0, // alignment: FractionalOffset.center, child: new Stack( //alignment:new Alignment(x, y) children: <Widget>[ new Icon(Icons.monetization_on, size: 36.0, color: const Color.fromRGBO(218, 165, 32, 1.0)), new Positioned( left: 20.0, child: new Icon(Icons.monetization_on, size: 36.0, color: const Color.fromRGBO(218, 165, 32, 1.0)), ), new Positioned( left:40.0, child: new Icon(Icons.monetization_on, size: 36.0, color: const Color.fromRGBO(218, 165, 32, 1.0)), ) ], ), ), ) ; } }
And this how you get some nice shadow drop so the icon stands out more:
class StackExample extends StatelessWidget { @override Widget build(BuildContext context) { return new Scaffold( appBar: new AppBar(), body: new Container( padding: const EdgeInsets.all(8.0), height: 500.0, width: 500.0, // alignment: FractionalOffset.center, child: new Stack( //alignment:new Alignment(x, y) children: <Widget>[ new Container( decoration: new BoxDecoration( borderRadius: BorderRadius.circular(25.0), boxShadow: [ new BoxShadow( blurRadius: 5.0, offset: const Offset(3.0, 0.0), color: Colors.grey, ) ] ), child: new Icon(Icons.monetization_on, size: 36.0, color: const Color.fromRGBO(218, 165, 32, 1.0))), new Positioned( left: 20.0, child: new Container( decoration: new BoxDecoration( borderRadius: BorderRadius.circular(25.0), boxShadow: [ new BoxShadow( blurRadius: 5.0, offset: const Offset(3.0, 0.0), color: Colors.grey, ) ] ), child: new Icon(Icons.monetization_on, size: 36.0, color: const Color.fromRGBO(218, 165, 32, 1.0))), ), new Positioned( left:40.0, child: new Container( decoration: new BoxDecoration( borderRadius: BorderRadius.circular(25.0), boxShadow: [ new BoxShadow( blurRadius: 5.0, offset: const Offset(3.0, 0.0), color: Colors.grey, ) ] ) ,child: new Icon(Icons.monetization_on, size: 36.0, color: const Color.fromRGBO(218, 165, 32, 1.0))), ) ], ), ), ) ; } }
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