【Flutter】【package】auto_size_text 文字自动适配大小
创始人
2024-01-25 23:14:31
0

文章目录

  • 前言
  • 一、auto_size_text 是什么?
  • 二、使用
    • 1.简单的使用
    • 2.参数说明
    • 3.group
    • 4.rich text
  • 总结


在这里插入图片描述

前言

auto_size_text :https://pub.flutter-io.cn/packages/auto_size_text


一、auto_size_text 是什么?

第三方的插件,能够自动适配你的文本的大小。来适应边界。

二、使用

1.简单的使用

style 部分同text的一样的,基础的功能设备都是同text 文本的使用一样。
下面做一个简单的对比。我们限制一个宽度高度。在里面放入文本。

  • 使用text:文字显示不全的
return Scaffold(appBar: AppBar(// Here we take the value from the MyHomePage object that was created by// the App.build method, and use it to set our appbar title.title: Text(widget.title),),body: const Center(child: SizedBox(width: 200,height: 140,child: Text(style: TextStyle(fontSize: 100),maxLines: 2,'Here we take the value from the MyHomePage object that was created by'),))// This trailing comma makes auto-formatting nicer for build methods.);

在这里插入图片描述

  • 使用了auto_size_text :自动缩小了文本的size,达到能显示的情况
    return Scaffold(appBar: AppBar(// Here we take the value from the MyHomePage object that was created by// the App.build method, and use it to set our appbar title.title: Text(widget.title),),body: const Center(child: SizedBox(width: 200,height: 140,child: AutoSizeText(style: TextStyle(fontSize: 30),maxLines: 2,'Here we take the value from the MyHomePage object that was created by'),))// This trailing comma makes auto-formatting nicer for build methods.);

在这里插入图片描述

2.参数说明

参数描述
key*控制一个构件如何替换树中的另一个构件。
textKey设置结果小组件的键Text
style*如果非 null,则用于此文本的样式
minFontSize自动调整文本大小时使用的最小文本大小约束。如果设置了预设字体大小,则被忽略。
maxFontSize自动调整文本大小时使用的最大文本大小约束。如果设置了预设字体大小,则被忽略。
stepGranularity字体大小适应约束的步长。
presetFontSizes预定义所有可能的字体大小。重要:必须按降序排列。presetFontSizes
group同步倍数的大小AutoSizeText
textAlign*文本应如何水平对齐。
textDirection*文本的方向性。这决定了如何解释类似值。textAlignTextAlign.startTextAlign.end
locale*用于在相同的 Unicode 字符可以以不同的方式呈现时选择字体,具体取决于区域设置。
softWrap*文本是否应在软换行符处中断。
wrapWords不适合一行的单词是否应换行。默认为true以表现得像文本。
overflow*应如何处理视觉溢出。
overflowReplacement如果文本溢出且不适合其边界,则改为显示此微件。
textScaleFactor*每个逻辑像素的字体像素数。也影响,和。minFontSizemaxFontSizepresetFontSizes
maxLines文本跨越的可选最大行数。
semanticsLabel*此文本的替代语义标签。

3.group

可以统一各个autosizetext的大小。fontsize大小。来达到统一各个text的字体大小是一致的

    return Scaffold(appBar: AppBar(// Here we take the value from the MyHomePage object that was created by// the App.build method, and use it to set our appbar title.title: Text(widget.title),),body: Column(children: [AutoSizeText("text1",group: myautosize,maxLines: 1,),AutoSizeText("Here we take the value from the MyHomePage object that was created byHere we take the value from the MyHomePage object that was created by",minFontSize: 100,group: myautosize,)],)// This trailing comma makes auto-formatting nicer for build methods.);
  • minFontSize: 100, 最终并不会使用这个最小的的这个fontsize,结果如图
    ---

4.rich text

    return Scaffold(appBar: AppBar(// Here we take the value from the MyHomePage object that was created by// the App.build method, and use it to set our appbar title.title: Text(widget.title),),body: Column(children:const [AutoSizeText.rich(TextSpan(text: 'A really long String'),style: TextStyle(fontSize: 20),minFontSize: 5,),AutoSizeText.rich(TextSpan(children: [TextSpan(text: '我是 1'),TextSpan(text: '我是 2'),TextSpan(text: '我是 3'),TextSpan(text: '我是 4'),TextSpan(text: '我是 5', style: TextStyle(color: Colors.green)),]),style: TextStyle(fontSize: 20),minFontSize: 5,),],)// This trailing comma makes auto-formatting nicer for build methods.);

在这里插入图片描述

总结

欢迎关注,留言,咨询,交流!
在这里插入图片描述

相关内容

热门资讯

40个冷门创业项目推荐创业冷门... 40个冷门创业项目推荐现在冷门行业都有什么?能赚钱的小项目有很多,可是选择起来比较烦琐,选项目首先从...
十大冷门创业项目 十大冷门创业... 当下很多看似赚钱的不一定赚到钱,很多看似不乐观的不一定处于寒冬!今天我们就来看看有哪些冷门却很是赚钱...
适合新手创业的项目有哪些? 适... 创业的利润和可观的回报,吸引了很多人走向了创业的道路。对于没有任何创业经验的人来说,就想要知道适合新...
最适合新手创业的20个小项目 ... 最适合新手创业的20个小项目以下是由中国人才网为大家推荐的20个创业新手最适合的创业项目:眼镜店根据...
新手小白也可操作的创业赚钱项目... 第一时间获取热门网赚项目资讯,长按扫码加团队微信领福利项目概述:一直有小韭菜问我,现在什么能做?什么...
年入二十万 大部分人达不到 他... 大家有没有钓过鱼,哪怕是大太阳也抵挡不住钓鱼的心?钓鱼其实是会让人上瘾的,这个隐还不好戒。今天就给大...
创新创业扶持项目 创新创业扶持... 国务院关于大力推进大众创业万众创新若干政策措施的意见国发〔2015〕32号各省、自治区、直辖市人民政...
芜湖市创新创业扶持政策 芜湖市... 八大政策1、众创空间初始奖补。评定为市级众创空间的,给予50万元奖励,评定为市级及以上示范性众创空间...
选择创业项目的理由怎么写 选择... 在市场大环境的影响下,现在有越来越多的大学毕业生踏上了创业的道路。为什么越来越多的大学生走上创业之路...
国家植物园水杉林喷雾暑期增加开... 7月7日,北京青年报记者从国家植物园获悉,为让市民游客感受到更多的夏日清凉,国家植物园樱桃沟水杉林喷...