Question: To preface, I have reviewed the post [here](https://stackoverflow.com/questions/52908923/check-if-asset-exist-in-flutter), but am still having trouble.

I am building a container that is decorated with an image, only if that image exists in the assets/images/ folder. If it does not exist, the container is decorated with a default image instead.

The image path is formatted string using a variable, image\_id, that assumes a String response from an API.

Here is a code / pseudo-code hybrid of what I'm trying to do...

```
Container(
  height: 200,
  width: 300,
  decoration: BoxDecoration(
    image: DecorationImage(
      image: (AssetImage('assets/images/${image_id}.jpg') exists) //pseudo-code here
        ? AssetImage('assets/images/${image_id}.jpg')
        : AssetImage('assets/images/default.jpg'),
      fit: BoxFit.cover,
    ),
  ),
);

```

Answer: 
You should know if the asset exists as you're the responsible for adding those.

One option you have is by using: [**FlutterGen**](https://github.com/FlutterGen/flutter_gen) This library will create variables, method, etc for all your assets, if the variable is null, then, there you go.

You can also try to get the image like this:

```
final assetImage = Image.asset('path/to/asset.jpg');

```

and then check if that image is null or not. Even, if you want, you can take that and pre cache your image like this:

```
await precacheImage(assetImage.image, context);

```
You can [list](https://stackoverflow.com/a/56555070/7314211) all of the assets. Then you can check if certain asset is exist or not.