1.Container组件
名称 | 功能 |
alignment |
topCenter:顶部剧中对齐 topRight:顶部居右对齐 center:水平垂直剧中对齐 centerLeft:垂直剧中水平居左对齐 centerRight:垂直剧中水平居右对齐 bottomCenter:底部剧中对齐 bottomLeft:底部剧左对齐 bottomRight:底部剧右对齐 |
decoration |
border:配置边框 borderRadius:设置圆角 boxShadow:设置阴影 gradient:设置背景色渐变 |
margin |
表示Container与外部其他组件的距离.Edgeunsets.all(20.0) |
padding |
就是Container的内边距,指Container边缘与Child之间的距离padding:Edgeunsets.all(20.0) |
transform |
让Container进行一些旋转之类的 |
height |
容器高度 |
width |
容器宽度 |
案例:
void main() {
runApp(MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text("你好Flutter"),
),
body:Column(
children: const [
MyApp(),
MyButton()
],
),
),
));
}
自定义我的容器
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return Center(
child: Container(
alignment:Alignment.center ,//配置Container容器内元素的方位
width: 200,
height: 200,
decoration: BoxDecoration(
color: Colors.yellow,//设置Container容器的背景颜色
border: Border.all(//配置边框
color: Colors.red,//设置边框的颜色
width: 2,//设置边框的宽度
),
borderRadius: BorderRadius.circular(10),//设置圆角,也可以实现圆形
boxShadow:const [//设置阴影效果
BoxShadow(
color: Colors.black,
blurRadius: 30.0,
)],
/*
LinearGradient:线性渐变
RadialGradient:径向渐变
*/
gradient: const LinearGradient(//设置背景色渐变
colors: [
Colors.red,Colors.yellow
]
),
),
child: const Text(//Container容器内添加文字
"你好Flutter",
style: TextStyle(
color: Colors.white,//设置文字的背景颜色
fontSize: 20.0,//设置文字的大小
),
),
),
);
}
}
自定义按钮
class MyButton extends StatelessWidget {
const MyButton({super.key});
@override
Widget build(BuildContext context) {
return Container(
alignment: Alignment.center,
width: 200,
height: 40,
margin:const EdgeInsets.all(10),//设置居上的边距
decoration: BoxDecoration(
color: Colors.blue,//设置容器的背景颜色
borderRadius: BorderRadius.circular(10),//设置容器的圆角
),
child: const Text("按钮",style: TextStyle(
color: Colors.white,
fontSize: 20,
),),
);
}
}
效果图:
2.Text组件
名称 | 功能 |
textAlign |
文本对齐方式 |
textDirection |
文本方向(ltr从左至右,rtl从右至左) |
overflow |
文字超出屏幕后的处理方式(clip裁剪,fade渐隐,ellipsis省略号) |
textScaleFactor |
字体显示倍率 |
maxLines |
文字显示最大行 |
style |
字体的样式设置 |
TextStyle的相关属性
名称 | 功能 |
decoration |
文字装饰线(none没有线,lineThrough删除线,overLine上划线,underline下划线) |
decorationColor |
文字装饰线颜色 |
decorationStyle |
文字装饰线风格(dsshed虚线,double两根线,solid一根实线,wavy波浪线) |
wordSpacing |
单词间隙 |
letterSpacing |
字母间隙(如果是负值,会让字母变得更紧凑) |
fontStyle |
文字样式(italic斜体,normal正常体) |
fontSize |
文字大小 |
color |
文字颜色 |
fontWeight |
字体粗细 |
本文含有隐藏内容,请 开通VIP 后查看