当前位置: 首页 > news >正文

flutter 多文本,其中文本下划线往下移动

变态需求 

flutter中再满足多行文本,文本内有多个样式,并且多个样式可触发事件的情况,将其中的一部分文本的下划线往下移

方式一:

 实现

使用RichText组件,主要是看中里面的WidgetSpan可以穿child为一个widget

实现源码

     Expanded(child: RichText(text: TextSpan(children: [TextSpan(text: MmStrings.confirmService,style:MmTextStyles.textRegular.copyWith(fontSize: 12.sp),recognizer: TapGestureRecognizer()..onTap = () {context.read<MmSignUpBloc>().add(SignAgreePrivacyChangeEvent(!state.isAgreePrivacyPolicy,),);},),WidgetSpan(child: InkWell(onTap: () {MmWebUtils.launchWebUrl("${CommonConfig.instance.apiPreConfig.webUrl}${MmStrings.serviceAgreementUrl}",);},child: Stack(clipBehavior: Clip.none,children: [Text(MmStrings.serviceAgreement,style: MmTextStyles.agreementStyle.copyWith(fontSize: 12.sp,decoration: TextDecoration.none,),),Positioned(left: 0,right: 0,bottom: -2,child: Container(height: 1,color: MmColors.colorAgreement,),)],),),),TextSpan(text: MmStrings.andThe,style:MmTextStyles.textRegular.copyWith(fontSize: 12.sp),),WidgetSpan(child: InkWell(onTap: () {MmWebUtils.launchWebUrl("${CommonConfig.instance.apiPreConfig.webUrl}${MmStrings.privacyPolicyUrl}",);},child: Stack(clipBehavior: Clip.none,children: [Text(MmStrings.privacyPolicy,style: MmTextStyles.agreementStyle.copyWith(fontSize: 12.sp,decoration: TextDecoration.none,),),Positioned(left: 0,right: 0,bottom: -2,child: Container(height: 1,color: MmColors.colorAgreement,),)],),),),TextSpan(text: ".",style:MmTextStyles.textRegular.copyWith(fontSize: 12.sp),),],),),),

上面的方式有缺点和限制:如当一行文字换行就GG

但是

方式二:

新思路 使用shadow(具体实现很简单 设置shadow

extension MmTextStyleExtension on TextStyle {TextStyle toShadowStyle({double offset = -4,double thickness = 3,bool hasUnderline = true,}) {return this.copyWith(shadows: [Shadow(color: this.color ?? Colors.black,offset: Offset(0, offset),),],decoration: hasUnderline ? TextDecoration.underline : TextDecoration.none,decorationThickness: thickness,color: Colors.transparent,);}
}

使用

Text.rich(TextSpan(children: [TextSpan(text: "example example example example example example ",style: MmTextStyles.textSemiBold.toShadowStyle(hasUnderline: false),),TextSpan(text: "underline underline underline underline underline underline underline ",style: MmTextStyles.textSemiBoldUnLiner.toShadowStyle(),),],),),

方式三:

下面的方式过于复杂不建议

Flutter-Engine 的定制实践:Text 绘制流程浅析及自定义underline的间距-CSDN博客

http://www.lryc.cn/news/505006.html

相关文章:

  • 7.OPEN SQL
  • Python轻松获取抖音视频播放量
  • YOLOv8目标检测(三*)_最佳超参数训练
  • SpringBoot SPI
  • uniappp配置导航栏自定义按钮(解决首次加载图标失败问题)
  • 【Apache paimon】-- 集成 hive3.1.3 异常
  • 基于docker部署Nacos最新版本-国内稳定镜像
  • 云计算中的Hive操作详解
  • UE4_控件蓝图_制作3D生命血条
  • 11篇--图像边缘检测
  • 宝塔SSL证书申请失败,报错:申请SSL证书错误 module ‘OpenSSL.crypto‘ has no attribute ‘sign‘(已解决)
  • (已开源) 详解4D Radar数据集K-Radar
  • 基于RK3588机器人控制器+3D视觉传感器的送餐机器人解决方案
  • 基于Qwen2-VL模型针对LaTeX OCR任务进行微调训练 - 数据处理
  • Microi吾码|开源低代码.NET、VUE低代码项目,表单引擎介绍
  • [Ubuntu] Linux命令收集
  • 鸿蒙应用ArkTS开发-利用axios进行网络请求(实现前后端交互)
  • 【开源】使用环信UIKit for uniapp 做一个IM即时聊天应用
  • 计算机网络知识点全梳理(一.TCP/IP网络模型)
  • 神州数码DCME-320 online_list.php存在任意文件读取漏洞
  • 神经网络基础-神经网络搭建和参数计算
  • Linux入门攻坚——41、Linux集群系统入门-lvs(2)
  • 音视频入门基础:MPEG2-TS专题(17)——FFmpeg源码中,解析TS program map section的实现
  • 了解https原理,对称加密/非对称加密原理,浏览器与服务器加密的进化过程,https做了些什么
  • 山西省第十八届职业院校技能大赛高职组 5G 组网与运维赛项规程
  • tcpdump编译 wireshark远程抓包
  • Web开发 -前端部分-CSS
  • 用 Python Turtle 绘制流动星空:编程中的璀璨星河
  • Java从入门到工作2 - IDEA
  • fastadmin批量压缩下载远程视频文件