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',
                       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',
                       20,
                      height: 20,
                    ),
                  ),
原文地址:https://www.cnblogs.com/qqcc1388/p/11757117.html