首页 > 解决方案 > Dart 动态访问 getter

问题描述

Flutter中生成AppLocalizations的getter有很多

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

我有一个用例,getter 键存储在 a 中List<String>,我需要翻译它们

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

如何通过String变量访问 getter key

标签: flutterdart

解决方案


不幸的是,您目前还不能这样做。不久前我提交了一个功能请求,但他们似乎对此并不感兴趣。

你可以在这里跟进: https ://github.com/flutter/flutter/issues/84326


推荐阅读