dnfield / flutter_svg

SVG parsing, rendering, and widget library for Flutter
MIT License
1.64k stars 449 forks source link

Load a picture in case the given picture doesn't exists. #1044

Open aggeloskoutanis opened 4 months ago

aggeloskoutanis commented 4 months ago

Hello, first of all, thanks for this great package. Moving on, I would like to express a suggestion that might be handy in some situations.

I work on a project where I fetch some courier companies from the server and then I iterate them and create a list of couriers with the name and the picture of the courier company.

The courier images are stored in the assets folder and are rendered to the user using SvgPicture.asset() constructor.

The problem:

Sometimes, we introduce new couriers that the old mobile clients don't have the necessary data to display (i.ie.: the courier logo).

The solution:

Here, it would have been helpful if SvgPicture.asset() constructor had an errorBuilder that renders a default courier icon if the asset is not found.

dev-aniketj commented 3 months ago

@aggeloskoutanis Consider using the null check operator or the if condition in your code to handle null values.

Developers should refrain from creating default icons since different developers require different icons to suit their needs.

aggeloskoutanis commented 3 months ago

I don't suggest putting a default icon but exporting an error builder, where every developer can insert their Widget, which I would use to display my Error icon.

Check for example Image.asset() from Flutter SDK.