Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dart dynamically access getters

Tags:

flutter

dart

The generated AppLocalizations in flutter has many getters

final appLocalizations = AppLocalizations.of(context)!;
print(appLocalizations.helloWorld);

I have a use case that the getter keys is stored in a List<String> and I need to translate them

const key = 'helloWorld';
print(appLocalizations[key]);

How I can access to the getter by a String variable like key ?

like image 221
WebMaster Avatar asked Nov 17 '25 04:11

WebMaster


1 Answers

Unfortunately you can't do that as of yet. I've filed a feature request a while back, but they don't seem enthused about it.

You can follow up on it here: https://github.com/flutter/flutter/issues/84326

like image 117
moneer alhashim Avatar answered Nov 18 '25 20:11

moneer alhashim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!