[英]flutter - how to access map string entries key
i am using getx localization.我正在使用 getx 本地化。 And my app has a list view inside Text widget.
我的应用程序在文本小部件中有一个列表视图。
I try to write in Text widget every language 'name_1' value.我尝试在文本小部件中编写每种语言的“name_1”值。 But i can not access them.
但我无法访问它们。
My translation map below:我的翻译map如下:
Map<String, Map<String, String>> get keys => {
'tr_TR': {
'name_1': 'Dünya',
'short_desc_1': 'Dünyadan',
},
'en_US': {
'name_1': 'world',
'short_desc_1': 'from world'
},
'de_DE': {
'name_1': 'world',
'short_desc_1': 'from world'
},
'fr_FR': {
'name_1': 'world',
'short_desc_1': 'from world'}
};
I get value below我得到以下价值
TranslateStrings().keys[locale]!['name_' + '2']!.tr
But i need to get this with index value.但我需要用索引值来获取它。
TranslateStrings().keys[locale]!['name_' + index.tostring()]!.tr
If i write index instead of '2' i am getting error.如果我写索引而不是'2',我会收到错误。
_CastError (Null check operator used on a null value)
_CastError(用于 null 值的空检查运算符)
SOLVED解决了
TranslateStrings().keys[locale]!['name_' + '${index + 1}']!.tr
here some magic trick for you这里有一些魔术给你
keys.forEach(
(k, v) {
print(k); //k for keys like 'tr_TR'
print(v); //v for the map after the key then access the inner value with v['name_1']
},
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.