'How to cause a compile-time or lint-time error if code is referencing non-exist Flutter assets?

I have some flutter assets, say, file_one.png, file_two.json etc, and I use them in my code using Image.asset, Lottie and so on.

The problem is, how to cause a compile-time or lint-time error if code is referencing non-exist Flutter assets? For example, if I write Image.asset('assets/not_exist_file.png'), I hope I can get an error at compile time instead of at runtime. Since this can be statically checked and a compile-time or lint-time error is much, much better than a bug at runtime.

Thanks for any suggestions!



Solution 1:[1]

I just tried npm -g i sharp on my M1 MacBook Air and it works, so..there are a few things to know about your machine's environment.

  1. The brew formula is actually called libvips. I didn't have it installed and npm i sharp worked fine without it.

  2. Take a detailed look at https://sharp.pixelplumbing.com/install#custom-libvips and the next section "Building from Source". If you have libvips installed, you may need to set the env var SHARP_IGNORE_GLOBAL_LIBVIPS to ignore it.

  3. Make sure other npm dependencies in package.json are up to date if possible.

  4. As a workaround you could create a i386 arch copy of Terminal or iTerm2, place it in your Applications folder called "iTerm2 Rosetta", or something similar, and use the Get Info dialog on the file to enable Rosetta. You could even set a custom icon for it. enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ivan