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

Possible to access translation labels without context? #16

Closed
JonathanRhein opened this issue Apr 20, 2021 · 4 comments
Closed

Possible to access translation labels without context? #16

JonathanRhein opened this issue Apr 20, 2021 · 4 comments

Comments

@JonathanRhein
Copy link

Great tutorial on Medium!! Thanks a lot!

Is there a way to eliminate the necessity of passing BuildContext in

final labels = AppLocalizations.of(context);

using GetX? I sometimes have to reference the translation labels also in some of my controller/services classes where I usually try to avoid using BuildContext as much as possible (trying to separate UI and Business Logic).

@delay
Copy link
Owner

delay commented Apr 20, 2021

I actually no longer use AppLocalizations.of(context); in the current version. I replaced the old translation component with doing it the getX way and I also created a new script to build the localization file. You can take a look at the readme for how to use the new translation system.

@JonathanRhein
Copy link
Author

JonathanRhein commented Apr 21, 2021

Great - thank you! For some reason my compiler (Dart 2.12.3) complains about the required keyword in the constructors of LocalizationModel as well as PhraseModel in the update_localizations.dart script with the following message:

The parameter type 'dynamic' is incompatible with the field type 'String'.
Try changing or removing the parameter's type, or changing the field's type.dart(field_initializing_formal_not_assignable)

Once I remove the required keywords it is working fine :-)

@delay
Copy link
Owner

delay commented Apr 21, 2021

Ok are you using null safety in your project? Maybe that is why as the required keyword is only used if you update your pubspec.yaml to use:
environment: sdk: '>=2.12.0 <3.0.0'

@JonathanRhein
Copy link
Author

Ah, thank you for pointing that out! I have indeed not upgraded my project to null safety yet. Will be doing this in the future :-)

@delay delay closed this as completed Apr 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants