Flutter and Json Retrieve a Title where value is

admin

Administrator
Staff member
I have a Json array that is from wordpress. It retrives posts.
Each post has a serie of custom_options.

here an example:

Code:
{
  "options":{
    "wpcf-fields-select-option-f1d645c9017cce89714ede343df0cc73-1":{
      "title":"-Select-",
      "value":""
    },
    "wpcf-fields-select-option-3e64c784ce30a384e5167d1d6c1feb4e-1":{
      "title":"1\/5",
      "value":"S14"
    },
    "wpcf-fields-select-option-48334e061de93e6c47cc42c0fb5cd180-1":{
      "title":"1\/8",
      "value":"S1"
    },
    "wpcf-fields-select-option-a061ee2d2d302c5f42b2c93f9e811cdc-1":{
      "title":"1\/12",
      "value":"S2"
    }
  }
}

What I am trying to do is to call a function that will return the title of a given value.

Already tried using

Code:
// infoList is the json object
// resultVal is the value I am searching for
String getarrayinfos (infoList, resultVal) {
    var result;
    Map thisList = infoList;

    for(var eachArr in thisList.keys){
      if(thisList[eachArr]["value"] == resultVal){
        result = thisList[eachArr]["title"];
      }
    }

    return result.toString();
}

and printing it as the child of a container

Code:
// options is the json Object
// S7 is the value I am searching for 
child: Text(getarrayinfos(options, "S7")),

but it prints the following error

Code:
flutter: type 'String' is not a subtype of type 'int' of 'index'

What am I doing wrong?