How to show Icon in Text widget in flutter?

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

    Another option is String.fromCharCode(int charCode)

    This is icons.dart created by flutter team and charCodes are can found here.

    RichText(
      text: TextSpan(
      style: TextStyle(
        color: Colors.black,
        fontSize: 24.0,
      ),
      text: 'This is alarm icon : ',
        children: [
          TextSpan(
            text: String.fromCharCode(0xe190), //<-- charCode
            style: TextStyle(
            fontFamily: 'MaterialIcons', //<-- fontFamily
            fontSize: 24.0,
            color: Colors.red,
           ),
         )
       ],
      ),
    )
    

    And result :

提交回复
热议问题