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),
                      ),
                    ],
                  ),
                ),
              ),
相关推荐
kirk_wang12 小时前
Flutter file_selector 库在鸿蒙(OHOS)平台的适配实践与深度解析
flutter·移动开发·跨平台·arkts·鸿蒙
进击的前栈14 小时前
Flutter跨平台滚动视图scrollview_demo鸿蒙化使用指南
flutter·华为·harmonyos
w1395485642215 小时前
Flutter跨平台路径解析鸿蒙化使用指南
flutter·华为·harmonyos
爸爸61915 小时前
Flutter UDID 在鸿蒙平台的使用指南
flutter·华为·harmonyos
纟 冬16 小时前
# Flutter & OpenHarmony 运动App运动勋章成就组件开发
flutter
进击的前栈17 小时前
Flutter跨平台聊天组件testchat鸿蒙化使用指南
flutter·华为·harmonyos
花开彼岸天~17 小时前
Flutter跨平台图片加载鸿蒙化性能调优指南
flutter·华为·harmonyos
2501_9462338918 小时前
Flutter与OpenHarmony帖子详情页面开发
android·java·flutter
雨季66619 小时前
从零开始:Flutter 开发环境搭建全指南
flutter
爸爸61919 小时前
Flutter StatusBar Color NS 在鸿蒙平台的使用指南
flutter·华为·harmonyos