美文网首页Flutter
Flutter(十六)Container

Flutter(十六)Container

作者: 天色将变 | 来源:发表于2019-07-17 15:56 被阅读1次

Container是由多个widget组合而成的一个综合widget,内部可以实现很多功能。

属性
Container({
    Key key,
    this.alignment,// 指定child的位置
    this.padding,//内边距
    Color color,//背景色
    Decoration decoration,//装饰,与color互斥
    this.foregroundDecoration,// 前景装饰
    double width,
    double height,
    BoxConstraints constraints,//约束
    this.margin,//外边距
    this.transform,// 矩阵变换
    this.child,
  }) 
image.png
class _MyHomePageState extends State<MyHomePage> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Container(
          alignment: Alignment.center,// 指定child的位置
          width: 300,
          height: 200,
//          color: Colors.blue[200],
          padding: EdgeInsets.all(30),// 内边距
          transform: Matrix4.rotationZ(0.2),//旋转
          decoration: BoxDecoration(
            gradient: LinearGradient(colors: [Colors.green,Colors.orange]),
            borderRadius: BorderRadius.circular(15),
            border: Border.all(color: Colors.red[200],width: 4),
            boxShadow: <BoxShadow>[
              BoxShadow(
                color: Colors.blue,
                offset: Offset(10, 10),
                blurRadius: 10,
              )
            ]
          ),
          child: Container(
            alignment: Alignment.bottomRight,
            constraints: BoxConstraints.tightFor(width: 100,height: 100),
            decoration: BoxDecoration(
              shape: BoxShape.circle,
              color: Colors.black
            ),
            child: Text('box',style: TextStyle(color: Colors.red,fontSize: 20),),
          ),
        ),
      ),
    );
  }
}

相关文章

网友评论

    本文标题:Flutter(十六)Container

    本文链接:https://www.haomeiwen.com/subject/cbtclctx.html