27.Flutter的Stack组件的使用

classMyHomeBodyextendsStatelessWidget{

  @override

  Widget build(BuildContext context) {

    return Stack(

      children: [

        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中使用。

你可能感兴趣的:(27.Flutter的Stack组件的使用)