flutter - 如何将资产/图标中的图标添加到我的按钮组件中
问题描述
这是我的按钮组件代码:
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,
),
),
);
}
解决方案
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'),
],
),
推荐阅读
- java - Intellij 和堆大小最小的问题
- azure - 使用流分析将数据从 IoT 中心传输到 Cosmos DB 时出现分区错误
- java - 如何使用 IntWritable 的值作为条件对数据进行分区?
- jquery - 在 Laravel 中使用 AJAX 向我的数据库发送数据时出现问题
- wordpress - 如何制作两列垂直的字段?
- python - 使用 Python 请求库获取谷歌的访问令牌
- php - 如何使用循环显示多个错误消息
- php - Laravel 控制器到控制器
- python - 在 Python 中计算给定数据集的雨月数
- ruby-on-rails - 是否可以使用导轨中的回形针上传超速图像