How to show Icon in Text widget in flutter?

前端 未结 7 626
悲&欢浪女
悲&欢浪女 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:13

    Flutter has WidgetSpan() to add a widget inside the RichText().

    Example use:

    RichText(
      text: TextSpan(
        children: [
          TextSpan(
            text: "Click ",
          ),
          WidgetSpan(
            child: Icon(Icons.add, size: 14),
          ),
          TextSpan(
            text: " to add",
          ),
        ],
      ),
    )
    

    Above code will produce:

    image

    You can treat the child of WidgetSpan like the usual widget.

提交回复
热议问题