How can I manage image paths for different categories, like logos and backgrounds, in Dart? I tried using nested classes like in Java, but Dart doesn’t support that! What are the best practices or alternatives to handle this?
void main() {
print(Images.background.lake); // it dosn't work!
}
class Images {
class Portrait {
final traditional = 'assets/images/portrait/traditional.png';
final environmental = 'assets/images/portrait/environmental.png';
}
class Background {
final nature = 'assets/images/background/nature.png';
final lake = 'assets/images/background/lake.png';
}
}
2
Answers
Solution first:
Solution 2:
The Images class contains nested classes _Portrait and _Background, organizing image paths for easy access and allowing for additional nested classes as needed.
Then, you can access each image path through their chained member access (dotted notation), like: