【问题标题】:how to add icon into text flutter?如何将图标添加到文本颤动中?
【发布时间】:2021-08-11 08:51:10
【问题描述】:

我有一个简单的代码

              RaisedButton(
                  onPressed: () {
                    model.resetmodem();
                  },
                  child: Text(
                    'Size (also 24 pixels, not coincidentally, since both FlutterLogo and Icon honor the ambient IconTheme). This leaves some room left over, and now the row tells the text exactly how wide to be: the exact width of the remaining space. The text, now happy to comply to a reasonable request, wraps the text ',
                    maxLines: 2,
                    overflow: TextOverflow.ellipsis,
                  ),
                  color: Colors.blue,
                  textColor: Colors.white,
                  shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(25)),
                ),

我想在文字前面加个图标但不想让文字溢出

【问题讨论】:

  • 哪个图标?代码中没有图标。

标签: flutter dart button text icons


【解决方案1】:

如果溢出,请使用 Row 并将此文本和图标放入其中,您必须降低字体大小或图标大小或使按钮变大

【讨论】:

    【解决方案2】:

    您可以将 RichText 与 InkWell 一起使用:

                InkWell(
                 onTap: () {
                      //Your code here
                    },
                    child: RichText(
                      text: TextSpan(
                          text: 'Size (also 24 pixels, not coincidentally, since both FlutterLogo and Icon honor the ambient IconTheme). This leaves some room left over, and now the row tells the text exactly how wide to be: the exact width of the remaining space. The text, now happy to comply to a reasonable request, wraps the text ',
                          children: [
                            WidgetSpan(child: Icon(Icons.done)),
                          ]),
                    ),
                  )
    

    【讨论】:

      猜你喜欢
      • 2019-11-05
      • 2021-01-25
      • 2021-05-19
      • 2019-05-31
      • 1970-01-01
      • 2021-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多