flutter text 最大长度_超详细!关于Flutter文本组件Widget的全面解读

116cf182b6ec91eea99657aefff1109f.png

前言

  • Flutter 作为Google出品的一个新兴的跨平台移动客户端UI开发框架,正在被越来越多的开发者和组织使用,包括阿里的咸鱼、腾讯的微信等。

b3cb1c6bba408348cb39ec0639cb9971.png
  • 今天,我主要讲解Flutter中文本组件方面的Widget,包括Text、RichText、TextField,希望你们会喜欢。

106ae142b6a562610d234fd41f6c455a.png

1. Text

  • 应用场景:普通文本

b35822d3f7084e8065db5e303d818e4f.png
  • 属性设置
Text(this.data, {
    Key key,
    this.style, // 设置文字样式,具体见下面的说明
    this.textAlign, // 文字对齐方式:(center居中,left左对齐,right右对齐,justfy两端对齐)
    this.textDirection, // 文本方向(ltr从左至右,rtl从右至左)
    this.locale, 
    this.softWrap,// 是否自动换行(true自动换行,false单行显示,超出屏幕部分默认截断处理)
    this.overflow, // 文字超出屏幕之后的处理方式(clip裁剪,fade渐隐,ellipsis省略号)
    this.textScaleFactor, // 字体显示倍率
    this.maxLines, // maxLines 文字显示最大行数
    this.semanticsLabel, 
  }

 const TextStyle({
    this.inherit = true,
    this.color,//文本样式
    this.fontSize,//字体大小
    this.fontWeight,//绘制文本时的字体粗细
    this.fontStyle,//字体变体
    this.letterSpacing,//水平字母之间的空间间隔(逻辑像素为单位),可以负值
    this.wordSpacing,//单词之间添加的空间间隔(逻辑像素为单位),可以负值
    this.textBaseline,//对齐文本的水平线
    this.height,//文本行与行的高度,作为字体代销的倍数
    this.locale,//用于选择区域定字形的语言环境
    this.foreground,//文本的前景色,不能与color共同设置
    this.background,//文本背景色
    this.shadows,//Flutter Decoration背景设定(边框,圆角,阴影,渐变等)
    this.decoration,//绘制文本装饰,添加上下划线,删除线
    this.decorationColor,//文本装饰的颜色
    this.decorationStyle,//文本装饰的样式,控制画虚线,点,波浪线
    this.debugLabel,
    String fontFamily,//使用字体的名称
    String package,
  })
  • 实例演示
import 'package:flutter/material.dart'; // Material UI组件库

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

// 无状态控件显示
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
// 主界面入口返回的组件 = MaterialApp
    return MaterialApp(
      title: 'Widget_Demo', //标题
      theme: ThemeData(primarySwatch: Colors.blue), //主题色
      home: MyHomePage(), // 返回一个Widget对象,用来定义当前应用打开的时候,所显示的界面
    );
  }
}

// 返回的Widget对象
class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      //设置appbar
      appBar: new AppBar(
        title: new Text('Flutter Demo'),
      ),
      //主体
      body: new Center(
        //在屏幕中央显示一个文本
        child: Text(
          "carson ho Demo", // 显示的内容
          style: TextStyle( // 通过Style设置样式,可根据上述样式进行设置,此处仅作最简单属性设置
              color: Colors.blue, //颜色
              fontSize: 14, // 字体大小
              fontWeight: FontWeight.bold), // 字体加粗
          //文本背景颜色
        ),
      ),
    );
  }
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值