Container

Container是最常用的布局Widget,表示一个容器,其主要属性包括:

  • width

    表示容器的宽度。

  • Height

    表示容器的高度。

  • alignment

    容器中内容的对齐方式,包括:Alignment.topLeft、Alignment.topCenter、Alignment.topRight、Alignment.centerLeft、Alignment.center、Alignment.centerRight、Alignment.bottomLeft、Alignment.bottomCenter、Alignment.bottomRight等。

  • color

    容器的背景颜色。

  • padding

    容器中内边距。

  • decoration

    容器背景装饰,不能和color同时设置,设置此值时可以根据需要将容器设置为圆角矩形、特定边框宽度和颜色等。

  • foregroundDecoration

    容器内容的前景装饰,和背景装饰属性类似,通常可以通过此属性设置内容的半透明图层。

  • margin

    容器的外边距

  • child

    容器中的子Widget,只能设置一个子Widget。

Widget getContainer() {
    return Container(
       200.0,
      height: 200.0,
//      color: Colors.blueAccent,
      alignment: Alignment.center,
      padding: EdgeInsets.all(15.0),
      decoration: BoxDecoration(
        color: Colors.redAccent,
        border: Border.all(color: Colors.blueAccent,  2.0, style: BorderStyle.solid),
        borderRadius: BorderRadius.circular(15.0),
      ),
      foregroundDecoration: BoxDecoration(
        color: Color(0x66000000),
        borderRadius: BorderRadius.circular(15.0),
      ),
      child: Text('Hello'),
      margin: EdgeInsets.all(20.0),
    );
  }
原文地址:https://www.cnblogs.com/timba1322/p/12487271.html