I want to add a Flutter Container in top of another Container and top container will be transparent. Basically I do that in native Android using FrameLayout. How to implement this in Flutter?
Stack
is most likely what you want.
Stack
allows to put widgets on the top of others however you like. And, combined with Positioned
, have custom positions.
Let's draw a real frame in flutter :
Stack(
alignment: Alignment.center,
children: <Widget>[
Container(
width: 200.0,
height: 300.0,
decoration: BoxDecoration(
color: Colors.black12,
border: Border.all(
color: Colors.black,
width: 3.0,
),
),
),
Container(
width: 100.0,
height: 100.0,
color: Colors.blue,
),
Positioned(
bottom: 10.0,
right: 10.0,
child: Card(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text("Title"),
),
),
)
],
),
You can use Align
to better control the position of your widget based on alignment.
Stack(
children: <Widget>[
Align(alignment: Alignment.center, child: Text("Center"),),
Align(alignment: Alignment.topRight, child: Text("Top\nRight"),),
Align(alignment: Alignment.centerRight, child: Text("Center\nRight"),),
Align(alignment: Alignment.bottomRight, child: Text("Bottom\nRight"),),
Align(alignment: Alignment.topLeft, child: Text("Top\nLeft"),),
Align(alignment: Alignment.centerLeft, child: Text("Center\nLeft"),),
Align(alignment: Alignment.bottomLeft, child: Text("Bottom\nLeft"),),
Align(alignment: Alignment.topCenter, child: Text("Top\nCenter"),),
Align(alignment: Alignment.bottomCenter, child: Text("Bottom\nCenter"),),
Align(alignment: Alignment(0.0, 0.5), child: Text("Custom\nPostition", style: TextStyle(color: Colors.red, fontSize: 20.0, fontWeight: FontWeight.w800),),),
],
);
Output:
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