27.Flutter的Stack组件的使用

2020-06-10  本文已影响0人  凯司机

classMyHomeBodyextendsStatelessWidget{

  @override

  Widget build(BuildContext context) {

    return Stack(

      children: <Widget>[

        Container(

          color: Colors.purple,

          width: 300,

          height: 300,

        ),

        Positioned(

          left: 20,

          top: 20,

          child: Icon(Icons.favorite, size: 50, color: Colors.white)

        ),

        Positioned(

          bottom: 20,

          right: 20,

          child: Text("你好啊,KSJ", style: TextStyle(fontSize: 20, color: Colors.white)),

        )

      ],

    );

  }

}

⚠️:**注意:**Positioned组件只能在Stack中使用。

上一篇 下一篇

猜你喜欢

热点阅读