flutter TextButton.icon 无边框图文组件
前言
在之前,创建一个图文无连边框的组件的时候,往往需要写一个事件组件,包含一个row 行组件,然后在其中写入图片和文本的组件,等复杂的操作,最近正好发现了一个无边框图文按钮组件,在此记录一下 TextButton.icon()
TextButton.icon() 无边框图文按钮组件
先来看一下源码
factory TextButton.icon({
Key? key,
required VoidCallback? onPressed,
VoidCallback? onLongPress,
ValueChanged<bool>? onHover,
ValueChanged<bool>? onFocusChange,
ButtonStyle? style,
FocusNode? focusNode,
bool? autofocus,
Clip? clipBehavior,
required Widget icon,
required Widget label,
}) = _TextButtonWithIcon;
参考上面的源码,我们可以发现,icon和label 是两个必传的属性,那么就意味着我们在使用的时候,必须要传入图标和标签,其他的一些基本属性就不详解了,都是一些常用的属性,我们先来看一下使用,及使用效果
TextButton.icon(
onPressed: () {
},
icon: Icon(Icons.ac_unit),
label: Text("test"),
),
运行效果: