簡體   English   中英

如何在文本 flutter 中添加圖標?

[英]how to add icon into text flutter?

我有一個簡單的代碼

              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)),
                ),

我想在文本前面添加一個圖標,但我不想溢出文本

如果溢出,請使用 Row 並將此文本和圖標放入其中,您必須減小字體大小或圖標大小或使按鈕更大

您可以將 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)),
                      ]),
                ),
              )

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM