I have 4 languages in app.
After update on 1.4.0 and 1.4.1 the tr() methods not update the texts after setLocale() is called. Texts updates only after change screen to another. Even if i use StreamBuilder and refresh page by itself texts not changes.
But, when i change (for example) from EN to RU (nothing is updates) but if after that i change language from RU to FR (texts updates to RU but locale setted to FR) and next if change back to EN (text updates to FR). I dont know how explain it clearer.
Maybe a "key" property helps?
P.S. On version 1.3.5 all works fine and languages updates immediately after setLocale().
@aissat @danilofuchs I think this issue exists in master also. By removing context from Localization and making it singleton, while it is less verbose and can be used in any place without context, it has the issue of not updating since EasyLocalizationProvider InheritedWidget will not rebuild widgets.
Inherited widgets, when referenced in this way, will cause the consumer to rebuild when the inherited widget itself changes state.
https://api.flutter.dev/flutter/widgets/InheritedWidget-class.html
We should provide a new api for this that can handle translations without context and with context.
String tr(resource, {context}) => context != null ? Localizations.of(context).tr(resource) : Localization.instance.tr(resource);
When context is passed to tr, widgets will rebuild on locale change
and when not passed widgets will not rebuild on locale change.
Or maybe create two apis one with context and one without to avoid confusion and possible mistakes.
@aissat @danilofuchs
@spiritinlife Yes, I noticed it and agreed with you
We should provide a new api for this that can handle translations without context and with context.
String tr(resource, {context}) => context != null ? Localizations.of(context).tr(resource) : Localization.instance.tr(resource);When context is passed to tr, widgets will rebuild on locale change
and when not passed widgets will not rebuild on locale change.Or maybe create two apis one with context and one without to avoid confusion and possible mistakes.
@aissat @danilofuchs
@spiritinlife @danilofuchs take a look on this repo flutter_restart
@aissat This can be done with a ValueKey(locale) on EasyLocalization top widget. But this is not nice behaviour, changing locale shouldn't restart the whole widget tree.
We should provide a new api for this that can handle translations without context and with context.
String tr(resource, {context}) => context != null ? Localizations.of(context).tr(resource) : Localization.instance.tr(resource);When context is passed to tr, widgets will rebuild on locale change
and when not passed widgets will not rebuild on locale change.Or maybe create two apis one with context and one without to avoid confusion and possible mistakes.
@aissat @danilofuchs
just used context paramete once
Text("title").tr(context: context)
// or
tr("title",context: context)
Most helpful comment
@aissat @danilofuchs I think this issue exists in master also. By removing context from
Localizationand making it singleton, while it is less verbose and can be used in any place without context, it has the issue of not updating sinceEasyLocalizationProviderInheritedWidget will not rebuild widgets.