Flutter组件学习一(Text、Container)

1、Text

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

TextStyle 中的参数:

名称功能
decoration文字装饰线(none 没有线,lineThrough 删 除线,overline 上划线,underline 下划线)
decorationColor文字装饰线颜色
decorationStyle文字装饰线风格([dashed,dotted]虚线, double 两根线,solid 一根实线,wavy 波浪 线)
wordSpacing单词间隙(如果是负值,会让单词变得更紧凑
letterSpacing字母间隙(如果是负值,会让字母变得更紧凑)
fontStyle文字样式(italic 斜体,normal 正常体)
fontSize文字大小
color文字颜色
fontWeight字体粗细(bold 粗体,normal 正常体)

实例代码

void main() => runApp(MyMaterialApp());

class MyMaterialApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
        title: "test",
        home: new Scaffold(
          // 设置title
          appBar: AppBar(title: Text("jeklsjflk")),
          body: MyView(),
        ));
  }
}


// Text 的基本使用
class MyView extends StatelessWidget {
  @override
  Widget build(BuildContext context) {

    var text = "测试数据九分裤老地方角度来看fjkldfjdslkfjal;fjdklfjdslkfjdsklfjsdflkdsjf";
    return Text(
      // 要显示是文字
      text,
      style: TextStyle(
          color: Colors.yellow,
          fontStyle: FontStyle.normal,
          fontSize: 14, fontWeight: FontWeight.normal),

      textAlign: TextAlign.right,
      overflow: TextOverflow.clip,
    );
  }
}

2、Container

名称功能
alignmenttopCenter:顶部居中对齐
topLeft:顶部左对齐
topRight:顶部右对齐
center:水平垂直居中对齐
centerLeft:垂直居中水平居左对齐
centerRight:垂直居中水平居右对齐
bottomCenter 底部居中对齐
bottomLeft:底部居左对齐
bottomRight:底部居右对齐
decorationdecoration: BoxDecoration(
color: Colors.blue,
border: Border.all(color: Colors.red, width: 2.0,),
borderRadius: BorderRadius.all(Radius.circular(8.0) )
marginmargin 属性是表示 Container 与外部其他 组件的距离。 EdgeInsets.all(20.0),
paddingpadding 就是 Container 的内边距,指 Container 边缘与 Child 之间的距离 padding: EdgeInsets.all(10.0)
transform让 Container 容易进行一些旋转之类的transform: Matrix4.rotationZ(0.2)
height容器高度
width容器宽度
child容器子元素

更多找文档 https://api.flutter.dev/flutter/widgets/Container-class.html

void main() => runApp(MyMaterialApp());

class MyMaterialApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
        title: "test",
        home: new Scaffold(
          // 设置title
          appBar: AppBar(title: Text("jeklsjflk")),
          body: MyContainer(),
        ));
  }
}

///自定义的Container
class MyContainer extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Container(
      /// 四周10大小的margin
      margin: EdgeInsets.all(10.0),

      height: 120,
      width: 500,

      ///透明黑色遮罩
      decoration: new BoxDecoration(

        ///弧度为4.0
          borderRadius: BorderRadius.all(Radius.circular(4.0)),

          ///color: Colors.black.withAlpha(20),
          ///设置了decoration的color,就不能设置Container的color。
          color: Colors.black,

          ///边框
          border: new Border.all(color: Colors.red, width: 0.3)),
      child: new Text(
        "fjdklfdjlfkd",
        //设置字体样式:颜色灰色,字体大小14.0
        style: new TextStyle(color: Colors.white, fontSize: 14.0),
      ),
    );
  }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值