如何在 Flutter 中将 flatbutton.icon 更改为文本按钮?

How do I change a flatbutton.icon to a textbutton in Flutter?

我做了一个平面按钮图标,但在当前的 flutter 版本中似乎已经贬值了。我试过将它升级为文本按钮,但它没有在图标旁边显示文本。

这是原来的代码,要改成文字按钮才行。我是否必须定义一个 class 或函数才能实现?

Row(
            children: [
              FlatButton.icon(
                onPressed: () => print('Live'),
                icon: const Icon(
                  icons.videocam,
                  color: Colors.red,
                ),
                label: Text('Live'),
              ),
            ],
          )

谢谢! :)

您可以使用 IconButton widget:

Row(
  children: [
    IconButton(
      onPressed: () => print('Live'),
      icon: const Icon(icons.videocam, color: Colors.red),
    ),
    Text('Live'),
  ]
)

您可以使用 TextButton.icon() 小部件。这里有一个例子:

TextButton.icon(
  onPressed: () => print('Live'),
  icon: Icon(Icons.videocam_rounded),
  label: Text('Live'),
),

结果如下: