Flutter组件分为基础组件、单一子元素组件和多子元素组件。
基础组件
- Text 文本控件,类似于Android中的TextView
属性 | 说明 |
---|---|
textAlign | 对齐方式 |
maxLines | 最大行数 |
textScaleFactor | 缩放因子,默认值为1.0 |
style | TextStyle可以设置color、fontFamily、background、fontSize、decoration等 |
overflow | 配合maxLines使用,超出最大行数时,可以用省略号或渐变效果隐藏 |
textSpan | 配合Text.rich使用,可以实现富文本效果 |
Text(
'我是Text',
maxLines: 1,
overflow:TextOverflow.ellipsis,
style:TextStyle(
color:Colors.green,
fontSize:12,
decoration:TextDecoration.overline
),
)
- IconButton是一个图标控件
const IconButton(
icon: Icon(Icons.margin),
onPressed: () {},
)
- FloatingActionButton是Material Design风格的按钮
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
)
- Image
Image(
image: AssetImage('images/home_icon.png'),
width: 500,
alignment: Alignment.centerLeft,
fit: BoxFit.none,
colorBlendMode: BlendMode.color,
)