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

变态需求

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

实现

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

实现源码

Dart 复制代码
     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),
                      ),
                    ],
                  ),
                ),
              ),
相关推荐
空中海19 小时前
Flutter核心技术目录
flutter
apigfly20 小时前
Flutter,Compose,Web 在Android平台上从布局到屏幕的机制探究
android·flutter·webview
勇气要爆发1 天前
【第二阶段-Flutter入门】第四章:常用布局Widget
flutter
QuantumLeap丶1 天前
《Flutter全栈开发实战指南:从零到高级》- 13 -状态管理GetX
android·flutter·ios·前端框架
woshijunjunstudy1 天前
Flutter .obx 与 Rxn<T>的区别
flutter·getx
初遇你时动了情1 天前
flutter vscode 终端无法使用fvm 版本切换、项目运行
ide·vscode·flutter
一叶难遮天2 天前
Dart语言之面向对象
flutter·面向对象·dart·方法·mixins·泛型·抽象类
汤面不加鱼丸2 天前
flutter实践:DropdownButton2使用示例
flutter
心随雨下2 天前
Flutter Material 3设计语言详解
javascript·flutter·设计语言
猫林老师2 天前
Flutter for HarmonyOS开发指南(六):测试、调试与质量保障体系
flutter·华为·harmonyos