As I am very much new to the front-end world, I am not sure when I download the png from flaticon website such as https://www.flaticon.com/free-icon/telescope_3480961?related_id=3480961&origin=search I see telescope with colors, but when I use it with in Flutter using ImageIcon
Container(
height: 150,
width: 150,
color: Theme.of(context).colorScheme.background,
child: const ImageIcon(
AssetImage('assets/images/telescope.png'),
size: 150,
),
),
The image shows entirely black. I understand this png has a transparent background but why is Flutter not rendering the colours that came with the png? I am sure I am making a mistake but not sure how to resolve this.
The icon is looking like this.
2
Answers
If you want to show and image from your assets you need
Image.asset
, so instead ofImageIcon
, useImage.asset
:You can use assets image using
Image.asset
widget like this just removeImageIcon
widget from your code. also make sure you addedassets path
inpubsec.yaml
file.Assets path in
pubspec.yaml
file