How can I put a widget above another widget in Flutter?
Asked Answered
S

5

36

I would like to overlay a Round view on top of a background View just like in this screenshot below.

Getting like this

Saritasarkaria answered 24/8, 2018 at 6:36 Comment(1)
docs.flutter.io/flutter/widgets/Stack-class.htmlWiesbaden
P
71
@override
Widget build(BuildContext context) {
// TODO: implement build
return new Container(
  width: 150.0,
  height: 150.0,
  child: new Stack(children: <Widget>[
    new Container(
      alignment: Alignment.center,
      color: Colors.redAccent,
      child: Text('Hello'),
    ),
    new Align(alignment: Alignment.bottomRight,
      child: FloatingActionButton(
        child: new Icon(Icons.add),
          onPressed: (){}),
    )
  ],
  ),
);
}

above UI will look like this

Photoperiod answered 24/8, 2018 at 6:59 Comment(0)
K
19

You can use the Stack widget.

Stack(
  children: [
    /*your_widget_1*/,
    /*your_widget_2*/,
  ],
);
Keyte answered 24/8, 2018 at 6:58 Comment(1)
The correct Stack class URL: api.flutter.dev/flutter/widgets/Stack-class.htmlSterner
S
3
             Stack(
                alignment: Alignment.topRight,
                children: <Widget>[
                  Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: ClipRRect(
                      child: Image.network(
                        image,
                        height: 150,
                        width: 100,
                        fit: BoxFit.fitHeight,
                      ),
                      borderRadius: new BorderRadius.circular(8.0),
                    ),
                  ),
                  new Align(alignment: Alignment.topRight,
                    child:ClipRRect(
                      borderRadius: BorderRadius.only(
                          bottomRight: Radius.circular(30),
                          bottomLeft: Radius.circular(30),
                          topRight: Radius.circular(30)),
                      child: RaisedButton(
                        elevation: 1,
                        color: Color(0xFF69C86C),
                        child: Text(
                          "Name",
                          style: TextStyle(color: Colors.white),
                        ),
                        onPressed: () {},
                      ),
                    ),
                  )
                ],
              ),
Seta answered 31/8, 2019 at 13:7 Comment(0)
I
2

You can also use IndexedStack if you wish to show only one of the children based on the index.

IndexedStack(
  index: 0,
  children: [
    FooWidget(), // Visible if index = 0
    BarWidget(), // Visible if index = 1
  ],
)
Impose answered 1/7, 2021 at 15:0 Comment(0)
P
0

solution 1

can use be_widgets for overlaying widget as label or badge. It is similar to stack but has very flexible and badge or label draw over the child widget which helps to ignore the size of overlaying widget.

solution 2

You can use assorted_layout_widgets and use RowSuper or ColumnSuper internal spacing (innerDistance) in negative value for overlay

Proscribe answered 27/12, 2023 at 14:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.