如何在 Flutter 中将一个小部件放在另一个小部件之上?

How can I put a widget above another widget in Flutter?

我想在背景视图之上叠加一个圆形视图,就像下面的截图一样。

您可以使用 Stack 小部件。

Stack(
  children: [
    /*your_widget_1*/,
    /*your_widget_2*/,
  ],
);
@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: (){}),
    )
  ],
  ),
);
}

             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: () {},
                      ),
                    ),
                  )
                ],
              ),

如果您希望根据索引仅显示 children 之一,您也可以使用 IndexedStack

IndexedStack(
  index: 0,
  children: [
    FooWidget(), // Visible if index = 0
    BarWidget(), // Visible if index = 1
  ],
)