如何使图像像按钮一样活跃


appBar: AppBar(
backgroundColor: Colors.white,
leading: IconButton(
icon: Icon(Icons.menu, color: Colors.pink,),
onPressed: () {
print("menu button is clicked");
}
),
title: IconButton(
onPressed: () { print("run button"); },
icon: Image.asset('assets/images/Slimer_by_shinrider-dcqaiza.webp')),
),

在代码中,有一个IconButton,我为制作图像到按钮而制作。但它并没有出现图像。代码中有什么不正确的地方吗?或者我必须换一种方法吗?

检查pubspec.yaml中的资产路径设置。此外,请检查图像是否位于您正常设置的资源路径中。

pubspec.yaml

assets:
- assets/images/

显示文档
https://docs.flutter.dev/development/ui/assets-and-images

GestureDetector(
onTap: () {print('click on edit');},
child: Image(
image: AssetImage('assets/images/icons/edit-button.png'),
fit: BoxFit.cover,
height: 20,
)),

尝试与.png 一起使用

最新更新