首页 > 解决方案 > 如何将资产/图标中的图标添加到我的按钮组件中

问题描述

在此处输入图像描述

这是我的按钮组件代码:

Widget build(BuildContext context) {
    return MaterialButton(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.all(Radius.circular(40)),
        side: BorderSide(color: kPrimaryColor)
      ),
      padding: padding,
      color: color,
      minWidth: 280,
      onPressed: press,
      child: Text(
        text,
        style: TextStyle(
          color: Colors.grey[900],
          fontSize: 15,
        ),
      ),
    );

  }

标签: flutterdart

解决方案


child用 a包裹你Row并将图标添加为 Row's 的第二个元素children。结果将如下所示:

      child: Row(
        children: [
          Text(
            text,
            style: TextStyle(
              color: Colors.grey[900],
              fontSize: 15,
            ),
          ),
          Image.asset('assets/icons/my_icon.png'),
        ],
      ),

推荐阅读