【问题标题】:How can I put a widget above another widget in Flutter?如何在 Flutter 中将一个小部件放在另一个小部件之上?
【发布时间】:2019-01-30 14:21:24
【问题描述】:

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

【问题讨论】:

标签: flutter dart widget flutter-layout flutter-dependencies


【解决方案1】:
@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: (){}),
    )
  ],
  ),
);
}

【讨论】:

    【解决方案2】:

    您可以使用Stack 小部件。

    Stack(
      children: [
        /*your_widget_1*/,
        /*your_widget_2*/,
      ],
    );
    

    【讨论】:

      【解决方案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: () {},
                            ),
                          ),
                        )
                      ],
                    ),
      

      【讨论】:

        【解决方案4】:

        如果您希望根据索引仅显示其中一个孩子,也可以使用IndexedStack

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

        【讨论】:

          猜你喜欢
          • 2011-01-18
          • 2022-08-03
          • 2021-12-01
          • 2021-03-17
          • 2021-12-09
          • 2019-02-19
          • 1970-01-01
          • 2021-05-15
          • 1970-01-01
          相关资源
          最近更新 更多