For example, I want to get Image logo.gif
Image.asset('images/logo.gif')
Should I do it like above or create new file to store static constant like below?
In assets_path.dart
class imagePath {
static const imageFolder = 'assets/images/';
static const logo = imageFolder + 'logo.gif';
//...and others images path
}
When use
import './assets_path.dart';
Image.asset(imagePath.logo)
>Solution :
Yes!! Highly recommended as literal strings are easy to mispell. So if you have multiple occurrences of the same file, the chances to accidentally mess up increases, so just create a static const variable inside a class called something like AppAssets for all file paths of all assets used in the application.
I do this for my apps. Also nothing is preventing you from doing the same for colors and styles, like AppColors and AppStyles