Column中的主轴方向是垂直方向
mainAxisAlignment:MainAxisAlignment-主轴对齐方向
crossAxisAlignment:CrossAxisAlignment-交叉轴对齐方向
children:内容
class ColumnRowDemo extends StatelessWidget {
const ColumnRowDemo({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
color: Colors.lightGreen,
width: double.infinity,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(Icons.access_alarm,size: 50),
Icon(Icons.accessible_forward,size: 50),
Icon(Icons.settings,size: 50),
Icon(Icons.add_a_photo,size: 50),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Icon(Icons.access_alarm,size: 50),
Icon(Icons.accessible_forward,size: 50),
Icon(Icons.settings,size: 50),
Icon(Icons.add_a_photo,size: 50),
],
)
],
),
);
}
}
direction(声明主轴方向)
mainAxisAlignment(声明主轴对齐方向)
textDirection(声明水平方向的排列顺序)
crossAxisAlignment(声明交叉方向轴对齐方式)
verticalDirection(声明垂直方向的排列顺序)
children(声明子组件)
class FlexDemo extends StatelessWidget {
const FlexDemo({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Column(
children: [
Row(
children: [
Container(
color: Colors.lightBlue,
height: 50,
width: 50,
),
Expanded(
child: Container(
color: Colors.lightGreen,
height: 50,
),
)
],
),
Flex(
direction: Axis.horizontal,
mainAxisAlignment: MainAxisAlignment.spaceAround,
textDirection: TextDirection.rtl,
children: [
Icon(Icons.access_alarm, size: 50),
Icon(Icons.accessible_forward, size: 50),
Icon(Icons.settings, size: 50),
Icon(Icons.add_a_photo, size: 50),
],
),
Flex(
direction: Axis.horizontal,
children: [
Expanded(
child: Container(
color: Colors.tealAccent,
height: 50,
width: 50,
),
flex: 2,
),
Expanded(
child: Container(
color: Colors.yellow,
height: 50,
width: 50,
),
flex: 1,
)
],
),
Container(
height: 100,
margin: EdgeInsets.all(50),
child: Flex(
direction: Axis.vertical,
verticalDirection: VerticalDirection.up,
children: [
Expanded(
child: Container(
color: Colors.tealAccent,
height: 50,
width: 50,
),
flex: 2,
),
Spacer(
flex: 1,
),
Expanded(
child: Container(
color: Colors.yellow,
height: 50,
width: 50,
),
flex: 1,
)
],
),
)
],
);
}
}
spacing (主轴方向子组件的间距)
runSpacing (纵轴方向子组件的间距)
alignment (主轴方向子组件的对齐方式)
runAlignment (纵轴方向子组件的对齐方式)
class WrapDemo extends StatelessWidget {
List<String> _list=[
'曹操','司马懿','曹仁','曹洪','张辽','许褚'
];
List<Widget> _weiGuo(){
return _list.map((item) => Chip(
avatar: CircleAvatar(
backgroundColor: Colors.red,
child: Text('魏'),
),
label: Text(item),
)).toList();
}
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Wrap(
children: _weiGuo(),
spacing: 18.0,
runSpacing: 100,
alignment: WrapAlignment.spaceAround,
runAlignment: WrapAlignment.spaceAround,
),
Wrap(
children: [
Chip(
avatar: CircleAvatar(
backgroundColor: Colors.blue,
child: Text('蜀'),
),
label: Text('刘备'),
),
Chip(
avatar: CircleAvatar(
backgroundColor: Colors.blue,
child: Text('蜀'),
),
label: Text('关羽'),
),
Chip(
avatar: CircleAvatar(
backgroundColor: Colors.blue,
child: Text('蜀'),
),
label: Text('张飞'),
),
Chip(
avatar: CircleAvatar(
backgroundColor: Colors.blue,
child: Text('蜀'),
),
label: Text('赵云'),
),
Chip(
avatar: CircleAvatar(
backgroundColor: Colors.blue,
child: Text('蜀'),
),
label: Text('诸葛亮'),
),
Chip(
avatar: CircleAvatar(
backgroundColor: Colors.blue,
child: Text('蜀'),
),
label: Text('黄忠'),
),
],
)
],
);
}
}
class Stackdemo extends StatelessWidget {
const Stackdemo({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
child: Stack(
textDirection: TextDirection.rtl,
alignment: AlignmentDirectional.bottomEnd,
children: [
CircleAvatar(
backgroundImage: NetworkImage('https://s1.ax1x.com/2022/10/31/xTY0Bt.jpg'),
radius: 200,
),
Positioned(
child: Container(
color: Colors.black12,
padding: EdgeInsets.all(10),
child: Text(
'薇尔莉特',
style: TextStyle(
color: Colors.white,
fontSize: 20
),
),
),
top: 50,
right: 40,
),
Text(
'hello',
style: TextStyle(
color: Colors.black,
fontSize: 20
),
),
],
),
);
}
}
class CartDemo extends StatelessWidget {
const CartDemo({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Column(
children: [
Card(
margin: EdgeInsets.all(30),
color: Colors.green[100],
shadowColor: Colors.yellow,
elevation: 20,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(40),
side: BorderSide(
color: Colors.yellow,
width: 3,
)
),
child: Column(
children: const [
ListTile(
leading: Icon(
Icons.accessible_forward_sharp,
size: 50,
),
title: Text(
"OTTO",
style: TextStyle(fontSize: 20),
),
subtitle: Text(
"吉吉国王",
style: TextStyle(fontSize: 20),
),
),
Divider(),
ListTile(
title: Text(
"电话:000000000",
style: TextStyle(
fontSize: 20
),
),
),
ListTile(
title: Text(
"地址:xxxxxxx",
style: TextStyle(
fontSize: 20
),
),
)
],
),
),
Card(child: Column(
children: const [
ListTile(
leading: Icon(
Icons.accessible_forward_sharp,
size: 50,
),
title: Text(
"OTTO",
style: TextStyle(fontSize: 20),
),
subtitle: Text(
"吉吉国王",
style: TextStyle(fontSize: 20),
),
),
Divider(),
ListTile(
title: Text(
"电话:000000000",
style: TextStyle(
fontSize: 20
),
),
),
ListTile(
title: Text(
"地址:xxxxxxx",
style: TextStyle(
fontSize: 20
),
),
)
],
),)
],
);
}
}