flutter_gen
flutter_gen copied to clipboard
Support path method to an asset folder
For example I have the next settings:
# pubspec.yaml
flutter:
assets:
- assets/images/profile.jpg
And the library generates path to the profile image.
Widget build(BuildContext context) {
// Assets.images.profile.path = 'assets/images/profile.jpg'
return Image.asset(Assets.images.profile.path);
}
But sometime I need to write a specific code and have access to the folder assets/images
. Could you support the logic?
var imagesPath = Assets.images.path;
// do some magic in the folder
Same here. Working on a project (online game) which is split into mobile app and backend API. The mobile app keeps all the image assets, so for the player avatars I have:
...
AssetGenImage get femaleAristocrat =>
const AssetGenImage('assets/images/players/female_aristocrat.png');
AssetGenImage get femaleCommander =>
const AssetGenImage('assets/images/players/female_commander.png');
...
but the API just returns the player avatar as female_aristocrat
. Would be great to have some way to get the part assets/images/players/
somehow, without hardcoding it in the app.
So instead of calling:
String get imagePath => 'assets/images/players/$avatar.png';
I could make it like:
String get imagePath => '{${Assets.images.players.path}/$avatar.png';
Not a big deal, but already made a dozen of typos in these kind of paths.
Similarly easy_localization only accepts a path, so I'm hardcoding the path.
Note you have to declare the translations within assets in pubspec already, so flutter_gen is picking it up regardless - it's just not accessible since only the values for the files: en-us
etc are available - but not helpful in this instance.
EasyLocalization(
supportedLocales: [Locale('en', 'US'), Locale('de', 'DE')],
path: 'assets/translations', // <-- change the path of the translation files
fallbackLocale: Locale('en', 'US'),
child: MyApp()
)