Widget build(BuildContext context) {returnnew Column(children: <Widget>[new Container(padding: new EdgeInsets.only(top:100.0),child: new Text('这是一个组件')),new Container(decoration: new BoxDecoration(border: new Border.all(width:1.0,color: Colors.blue)),padding: new EdgeInsets.all(20.0),child: new Text('来自输入框:'+active))],);}
复制代码
// 对于嵌套容器,如果父级的宽度小于子级宽度,则子级容器将自行调整大小以匹配父级。
var container = new Container(child: new Center(child: new Text("Lorem ipsum"),decoration: new BoxDecoration( ... ), // constraints属性,创建一个新的BoxConstraints来设置minWidth或maxWidthwidth: 240.0, // 对应左边的 max-width),width:300.0),
复制代码
旋转组件:
.box { transform: rotate(15deg); }
复制代码
复制代码
var container = new Container( // gray boxchild: new Transform( // 对应左边的 transformchild: new Container( ... ),alignment: Alignment.center, // 对应左边的 transformtransform: new Matrix4.identity() // 对应左边的 transform..rotateZ(15 * 3.1415927 / 180),), )
);
复制代码
缩放组件:
.box {transform: scale(1.5);
}
复制代码
复制代码
var container = new Container( // gray boxchild: new Transform( // 对应左边的 transformchild: new Container( ... ),alignment: Alignment.center, // 对应左边的 transform的中心transform: new Matrix4.identity() // 对应左边的 transform..scale(1.5),), )
);
复制代码
var container = new Container( // grey boxchild: new Center(child: new Container( // red boxchild: new Text( ... ),decoration: new BoxDecoration( gradient: new LinearGradient( // 对应左边的 background: linear-gradientbegin: const Alignment(0.0, -1.0),end: const Alignment(0.0, 0.6),colors: [const Color(0xffef5350),const Color(0x00ef5350)],),)),)
);
复制代码
复制代码
圆角:
.box {border-radius: 8px;
}
复制代码
复制代码
var container = new Container( // grey boxchild: new Center(child: new Container( // red circlechild: new Text( ... ),decoration: new BoxDecoration(borderRadius: new BorderRadius.all(const Radius.circular(8.0),), )),)
);
复制代码
var container = new Container( // grey boxchild: new Center(child: new Container( // red boxchild: new Text( ... ),decoration: new BoxDecoration(boxShadow: [ // 对应左边的 box-shadownew BoxShadow (color: const Color(0xcc000000),offset: new Offset(0.0, 2.0),blurRadius: 4.0,),new BoxShadow (color: const Color(0x80000000),offset: new Offset(0.0, 6.0),blurRadius: 20.0,),], )),)
);
复制代码
var container = new Container( // grey boxchild: new Center(child: new Container( // red circlechild: new Text( ... ),decoration: new BoxDecoration(color: Colors.red[400],shape: BoxShape.circle, // 画圆和圆角不太一样,用的是BoxShape绘制图像能力),width: 160.0,height: 160.0, ),)
);
复制代码
var container = new Container( // grey boxchild: new Center(child: new Container( // red boxchild: new RichText(text: new TextSpan(style: bold24Roboto,children: [new TextSpan(text: "Lorem "), // 继承内联样式new TextSpan(text: "ipsum",style: new TextStyle( // 具有自定义样式的单独样式fontWeight: FontWeight.w300,fontStyle: FontStyle.italic,fontSize: 48.0,),),],),),),)
);
复制代码