Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support path method to an asset folder #73

Closed
vladimirgoncharov opened this issue Jan 19, 2021 · 2 comments · Fixed by #472
Closed

Support path method to an asset folder #73

vladimirgoncharov opened this issue Jan 19, 2021 · 2 comments · Fixed by #472
Labels
contributions welcome Welcome contribute enhancement New feature or request

Comments

@vladimirgoncharov
Copy link

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
@vladimirgoncharov vladimirgoncharov changed the title Support paths to a folder Support path method to a folder Jan 19, 2021
@vladimirgoncharov vladimirgoncharov changed the title Support path method to a folder Support path method to an asset folder Jan 19, 2021
@vintage
Copy link

vintage commented Feb 15, 2021

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.

@DJTB
Copy link

DJTB commented Dec 20, 2022

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()
)

@AlexV525 AlexV525 added enhancement New feature or request contributions welcome Welcome contribute labels Mar 6, 2024
AlexV525 added a commit that referenced this issue Apr 20, 2024
… classes (#472)

## What does this change?

Resolves #73 🎯

## Type of change

- [x] New feature (non-breaking change which adds functionality)
- [x] This change requires a documentation update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributions welcome Welcome contribute enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants