简体   繁体   中英

flutter - how to access map string entries key

i am using getx localization. And my app has a list view inside Text widget.

I try to write in Text widget every language 'name_1' value. But i can not access them.

My translation map below:

  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.

_CastError (Null check operator used on a null value)

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']
    },
  );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM