flutter richText富文本


flutter中富文本使用

RichText(
              text: TextSpan(
                text: '登陆即同意',
                style: TextStyle(fontSize: 14, color: Colors.black),
                children: [
                  TextSpan(
                    text: '"服务条款"',
                    style: TextStyle(fontSize: 14, color: Colors.blue),
                    recognizer: TapGestureRecognizer()
                      ..onTap = () {
                        print('点击了服务条款');
                      },
                  ),
                  TextSpan(
                    text: '和',
                    style: TextStyle(fontSize: 14, color: Colors.black),
                  ),
                  TextSpan(
                    text: '"隐私政策"',
                    style: TextStyle(fontSize: 14, color: Colors.blue),
                    recognizer: TapGestureRecognizer()
                      ..onTap = () {
                        print('点击了隐私政策');
                      },
                  ),
                  WidgetSpan(
                    alignment: PlaceholderAlignment.middle,
                    child: Image.asset(
                      'assets/noavatar.png',
                      width: 20,
                      height: 20,
                    ),
                  ),
                ],
              ),
            ),

TextSpan可以用来显示文字类型,设置文字颜色,点击事件等

   TextSpan(
                    text: '"隐私政策"',
                    style: TextStyle(fontSize: 14, color: Colors.blue),
                    recognizer: TapGestureRecognizer()
                      ..onTap = () {
                        print('点击了隐私政策');
                      },
                  ),

WidgetSpan 可以用来显示任意widget,图片按钮等等

                  WidgetSpan(
                    alignment: PlaceholderAlignment.middle,
                    child: Image.asset(
                      'assets/noavatar.png',
                      width: 20,
                      height: 20,
                    ),
                  ),


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM