How to show Icon in Text widget in flutter?

前端 未结 7 454
悲&欢浪女
悲&欢浪女 2020-12-28 13:24

I want to show an icon in text widget. How do I do this ?

The following code only shows the IconData

Text(\"Click ${Icons.add} to add\"         


        
相关标签:
7条回答
  • 2020-12-28 14:20

    You can use this Package to achieve this.

    I am not able to find the pub of this package.

    Here is the Implementation.

        RealRichText(
          [
            TextSpan(
              text: "A Text Link",
              style: TextStyle(color: Colors.red, fontSize: 14),
              recognizer: TapGestureRecognizer()
                ..onTap = () {
                  debugPrint("Link Clicked.");
                },
            ),
            ImageSpan(
              AssetImage("packages/real_rich_text/images/emoji_9.png"),
              imageWidth: 24,
              imageHeight: 24,
            ),
            ImageSpan(AssetImage("packages/real_rich_text/images/emoji_10.png"),
                imageWidth: 24,
                imageHeight: 24,
                margin: EdgeInsets.symmetric(horizontal: 10)),
            TextSpan(
              text: "哈哈哈",
              style: TextStyle(color: Colors.yellow, fontSize: 14),
            ),
            TextSpan(
              text: "@Somebody",
              style: TextStyle(
                  color: Colors.black, fontSize: 14, fontWeight: FontWeight.bold),
              recognizer: TapGestureRecognizer()
                ..onTap = () {
                  debugPrint("Link Clicked");
                },
            ),
            TextSpan(
              text: " #RealRichText# ",
              style: TextStyle(color: Colors.blue, fontSize: 14),
              recognizer: TapGestureRecognizer()
                ..onTap = () {
                  debugPrint("Link Clicked");
                },
            ),
            TextSpan(
              text: "showing a bigger image",
              style: TextStyle(color: Colors.black, fontSize: 14),
            ),
            ImageSpan(AssetImage("packages/real_rich_text/images/emoji_10.png"),
                imageWidth: 24,
                imageHeight: 24,
                margin: EdgeInsets.symmetric(horizontal: 5)),
            TextSpan(
              text: "and seems working perfect……",
              style: TextStyle(color: Colors.black, fontSize: 14),
            ),
          ],
        );
    

    You can also check out below issue for more:

    Flutter Issue #2022

    0 讨论(0)
提交回复
热议问题