Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Framelayout alternative in flutter

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?

like image 250
Yeahia2508 Avatar asked Jul 09 '18 19:07

Yeahia2508


2 Answers

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 :

enter image description here

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"),
        ),
      ),
    )
  ],
),
like image 55
Rémi Rousselet Avatar answered Oct 23 '22 05:10

Rémi Rousselet


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:

enter image description here

like image 42
CopsOnRoad Avatar answered Oct 23 '22 05:10

CopsOnRoad