avatar

目录
从Flutter到原生开发-Container组件,Text组件

Flutter布局-Container组件

名称 功能
alignment topCenter:顶部居中对齐
topLeft:顶部左对齐
topRight:顶部右对齐
center:水平垂直居中对齐
centerLeft:垂直居中左对齐
centerRight:垂直居中右对齐
bottomCenter:底部居中对齐
bottomLeft:底部居左对齐
bottomRight:底部居右对齐
decoration decoration:BoxDecoration(
color:Colors.blue,
border:Border.all(color:Colors.red,width:2.0,),
borderRadius:BorderRadius.all(Radius.circular(9.0)
)
)
margin margin属性设置外边距 EdgeInsets.all(20.0)
padding padding属性设置内边距指Container边缘与Child之间的距离
transform 让Container进行一些二旋转偏移

Container介绍

  • Container:最常用的默认控件,类似于前端的div,但是实际上它是由多个内置控件组成的模版,只能包含一个child,支持 padding,margin,color,宽高,decoration(一般配置边框和阴影)等配置,在 Flutter 中,不是所有的控件都有 宽高、padding、margin、color 等属性,所以才会有 Padding、Center 等 Widget 的存在。
    dart
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    child: Container(
    width: 200.0,
    height: 300.0,
    transform: Matrix4.rotationZ(0.8),
    decoration: new BoxDecoration(
    //弧度为10.0
    borderRadius: BorderRadius.all(Radius.circular(10.0)),
    //设置了decoration的color,就不能设置Container的color。
    color: Colors.black,
    //边框
    border: new Border.all(color: Colors.blue, width: 0.3)),
    child:new Text("xixi")

Flutter布局-Text组件

名称 功能
textAlign 文本对齐方式(Center,left,right,justfy(两端对齐))
textDirection 文本方向(ltr:从左到右,rtl:从右到左)
overflow 文字超出屏幕之后的处理方式(clip裁剪,fade渐隐,ellipsis省略号)
textScaleFactor 字体显示倍率
maxLines 文字显示最大行数
style 字体的样式设置(TextStyle)

TextStyle的参数

名称 功能
decoration 文字装饰线(none没有线,lineThrough删除线,overline上划线,underline下划线)
decorationColor 文字装饰线颜色
decorationStyle 文字装饰线风格([dashed,dotted]虚线,double两根线,solid一根实线,wavy波浪线)
wordSpacing 单词间隙(如果为负值,会让单词变得更紧凑)
letterSpacing 字母间隙(如果为负值,会让字母变得更紧凑)
fontStyle 文字样式(italic斜体,normal正常体)
fontSize 文字大小
color 文字颜色
fontWeight 文字粗细(bold粗体,normal正常体)
dart
1
2
3
4
5
6
7
8
9
child: Text(
'文本文本文本22文本文本文本文本文本文本文本11111111',
textAlign: TextAlign.left,
overflow: TextOverflow.fade,
maxLines: 1,
style: TextStyle(
fontSize: 20.0,
),
)
打赏
  • 微信
    微信
  • 支付寶
    支付寶

评论