flutter richText rich text

flutter in the use of rich text

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 type can be used to display text, set the text color, click events

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

WidgetSpan can be used to display any widget, picture buttons, etc.

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

Guess you like

Origin www.cnblogs.com/qqcc1388/p/11757117.html