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),
                      ),
                    ],
                  ),
                ),
              ),
相关推荐
恋猫de小郭6 小时前
你还用 IDE 吗? AI 狂欢时代下 Cursor 慌了, JetBrains 等 IDE 的未来是什么?
前端·flutter·ai编程
TT_Close1 天前
🐟 发布中心进度同步:8 个商店的上传功能开发完毕,正抓紧测试
flutter·npm·visual studio code
RaidenLiu1 天前
Flutter Platform Channel 底层架构解析 —— 从 BinaryMessenger 到跨平台消息通信机制
前端·flutter·前端框架
鹏多多1 天前
Flutter使用screenshot进行截屏和截长图以及分享保存的全流程指南
android·前端·flutter
恋猫de小郭1 天前
什么 AI 写 Android 最好用?官方做了一个基准测试排名
android·前端·flutter
勤劳打代码3 天前
Flutter 架构日记 — 状态管理
flutter·架构·前端框架
比特鹰4 天前
手把手带你用Flutter手搓人生K线
前端·javascript·flutter
火柴就是我4 天前
Flutter限制输入框只能输入中文,iOS拼音打不出来?
flutter
TT_Close4 天前
【Flutter×鸿蒙】debug 包也要签名,这点和 Android 差远了
android·flutter·harmonyos
TT_Close5 天前
【Flutter×鸿蒙】FVM 不认鸿蒙 SDK?4步手动塞进去
flutter·swift·harmonyos