Flutter 如何在文本末尾添加图标按钮?

时间:2021-06-10 05:17:22

标签: flutter

如何在这样的文本末尾添加图标按钮?

Pic

我使用 Row 小部件但图标按钮不在正确的位置,它不在文本的末尾

Pic

这是我的代码:

Row(
        children: [
          Expanded(
            child: Text(
              'All about marketing, lead generation, content marketing and growth hacks',
              style: const TextStyle(
                  fontSize: 12.0, fontWeight: FontWeight.w500),
            ),
          ),
          IconButton(
            icon: Icon(Icons.info),
            iconSize: 12.0,
            color: Palette.appbar,
            onPressed: () {},
          ),
        ],
      ),

1 个答案:

答案 0 :(得分:2)

RichTextTextSpanWidgetSpan 一起使用。

WidgetSpan 允许添加您自己的小部件作为文本的一部分。

像这样:

    RichText(
      text: TextSpan(
        children: <TextSpan>[
          TextSpan(text: _text, style: _style),
          WidgetSpan(
            child:  _child
          )
        ],
      ),