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