1.颜色
class Color_Property_Colors extends StatelessWidget{
@override
Widget build(BuildContext context) {
return Center(
child: Container(
//color: Colors.green,//正常颜色
//color:Colors.green[200],//带有阴影(相当于是透明度)
color: Colors.green.shade200,//同上
),
);
}
}
2.子控件
class Child_Property extends StatelessWidget{
@override
Widget build(BuildContext context) {
return Center(
child: Container(
color: Color.fromRGBO(66, 165, 245, 1.0),
child: Text("Flutter Cheatsheet"),
),
);
}
}
3.布局
class Alignment_Property extends StatelessWidget{
@override
Widget build(BuildContext context) {
return Center(
child: Container(
color: Color.fromARGB(255, 66, 165, 245),
child: Text("Flutter Cheatsheet",
style: TextStyle(
fontSize: 30.0
),
),
//不加这句话,Container会自适应child大小;加上以后会充满屏幕
//alignment: Alignment(0.0, 0.0),
alignment: Alignment.center,//等价于上面
),
);
}
}
class Alignment_FractionalOffset extends StatelessWidget{
@override
Widget build(BuildContext context) {
return Center(
child: Container(
color: Color.fromARGB(255, 66, 165, 245),
child: Text("Flutter Cheatsheet",
style: TextStyle(
fontSize: 30.0
),
),
//不加这句话,Container会自适应child大小;加上以后会充满屏幕
//alignment: FractionalOffset(0.5, 0.5),
alignment: FractionalOffset.center,//等价于上面
),
);
}
}
//Container属性之AlignmentDirectional
class Alignment_AlignmentDirectional extends StatelessWidget{
@override
Widget build(BuildContext context) {
return Center(
child: Container(
color: Color.fromARGB(255, 66, 165, 245),
child: Text("Flutter",
style: TextStyle(
fontSize: 15.0
),
//textDirection: TextDirection.ltr,//正常,从左向右(不影响alignment)
textDirection: TextDirection.ltr,//从右向左(不影响alignment)
),
//不加这句话,Container会自适应child大小;加上以后会充满屏幕
alignment:AlignmentDirectional(-1.0, 1.0),
//alignment: AlignmentDirectional.bottomStart,//等价于上面
),
);
}
}
4.约束
class Constraints_Property extends StatelessWidget{
@override
Widget build(BuildContext context) {
return Center(
child: Container(
color: Color.fromARGB(255, 66, 165, 245),
alignment: AlignmentDirectional(0.0, 0.0),
child: Container(
color: Colors.green,
constraints: BoxConstraints(
maxHeight: 300,
maxWidth: 200,
minWidth: 150,
minHeight: 150,
),
),
),
);
}
}
class Constraints_Property_HasChild extends StatelessWidget{
@override
Widget build(BuildContext context) {
return Center(
child: Container(
color: Color.fromARGB(255, 66, 165, 245),
alignment: AlignmentDirectional(0.0, 0.0),
child: Container(
color: Colors.green,
child: Text("Flutter"),
constraints: BoxConstraints(
maxHeight: 300,
maxWidth: 200,
minWidth: 150,
minHeight: 150,
),
),
),
);
}
}
5.内外边距
class Margin_Property_EdgeInsets_all extends StatelessWidget{
@override
Widget build(BuildContext context) {
return Center(
child: Container(
color: Color.fromARGB(255, 66, 165, 245),
alignment: AlignmentDirectional(0.0, 0.0),
child: Container(
color: Colors.green,
margin: EdgeInsets.all(20.0),
),
),
);
}
}
class Padding_Property_EdgeInsets_all extends StatelessWidget{
@override
Widget build(BuildContext context) {
return Center(
child: Container(
color: Color.fromARGB(255, 66, 165, 245),
alignment: AlignmentDirectional(0.0, 0.0),
child: Container(
margin: EdgeInsets.only(
left: 20.0,
bottom: 40.0,
top: 50.0,
),
padding: EdgeInsets.all(10.0),//设置内部Text控件边距
color: Colors.green,
child: Text("Flutter Cheatsheet"),
//不设置这个Container和子控件一样大小、这样margin设置也就没有意义了
constraints: BoxConstraints.expand(),
),
),
);
}
}
网友评论