//001 Container 可以设置size 边框 颜色==
class ContainerPageextends StatelessWidget {
const ContainerPage({Key? key}) :super(key: key);
@override
Widgetbuild(BuildContext context) {
return MaterialApp(
theme:ThemeData(scaffoldBackgroundColor: Colors.grey),
home:Scaffold(
body:Container(
transform:Matrix4.rotationZ(0.05),//这里是弧度 不是角度
margin:EdgeInsets.all(20),
alignment: Alignment.center,
width:200,
height:200,
//color: Colors.blueGrey,// color 和 decoration 互斥 前者简单设置
decoration:BoxDecoration(
color: Colors.greenAccent,
borderRadius:BorderRadius.circular(20),
border:Border.all(width:3, color: Colors.amberAccent)
),
child:Text("Container Demo",
style:TextStyle(color: Colors.white, fontSize:20),
),
),
),
);
}
}
//002 Center 不能设置size 居中组件 可以使子组件在父容器里面 水平或垂直 居中排列
class CenterPageextends StatelessWidget {
const CenterPage({Key? key}) :super(key: key);
@override
Widgetbuild(BuildContext context) {
return MaterialApp(
home:Scaffold(
appBar:AppBar(
title:Text("Center Title"),
),
body:Center(
child:Container(
//alignment: .center, //这个和下面 child: Center( 一样的功能实现
width:200,
height:200,
color: Colors.blueGrey,
child:Center(
child:Text('center text', style:TextStyle(color: Colors.white, fontSize:20)),
),
)
),
),
);
}
}
//003 Align 对齐组件 控制其子组件在父容器空间内的对其位置 宽度因子和高度因子(子组件宽高乘以该因子)
// Center是Align的一个特例,继承与Align
// Align使用场景,需要将一个组件放在父容器的特定位置。(一个蓝色容器里面一个五角星)
class AlignPageextends StatelessWidget {
const AlignPage({Key? key}) :super(key: key);
@override
Widgetbuild(BuildContext context) {
// TODO: implement build
// return Container(
// child: null,
// );
return MaterialApp(
home:Scaffold(
appBar:AppBar(
title:Text("Align Title"),
),
body:Container(
color: Colors.lightBlueAccent,
child:Align(
widthFactor:2,
heightFactor:1,
alignment: .center,
child:Icon(
Icons.star,
size:50,
color: Colors.yellow,
),
),
)
),
);
}
}
//004 Padding 内边距组件 (一个黄色容器里面嵌套一个蓝色容器 设置边距)
class PaddingPageextends StatelessWidget {
const PaddingPage({Key? key}) :super(key: key);
@override
Widgetbuild(BuildContext context) {
// TODO: implement build
return MaterialApp(
home:Scaffold(
appBar:AppBar(
title:Text("Padding Title"),
),
body:Container(
//padding: EdgeInsets.all(20),//通过Container的属性设置内边距
decoration:BoxDecoration(
color: Colors.amber,
),
child:Padding(
padding:EdgeInsets.all(50),//通过Padding设置内边距
child:Container(
color: Colors.blue,
),
)
)
),
);
}
}