I use getxcontroller, in it there is a String like this:
class HomeController extends GetxController {
String testString1 = 'test1'.tr;
testMethod(){
String testString2 = 'test2'.tr;
}
}
After I trigger some localise method:
var locale = Locale('de', 'DE');
Get.updateLocale(locale);
testString2 is fine to be translated into German, but testString1 not works, since I will update value of testString1 in other method, and testString1 should have initial value.
I tried RxString/.obs, but not works, what is the right way to fix this issue?
2
Answers
When you write
testString1
gets set the moment the controller is created and will never change after, even if you update the locale. What you could do is turn it into a getter so it gets the latest translation everytime it’s accessed like