How do I refer to a value from snapshot. Flutter/Dart

I am trying to refer to stored data, that I have stored in a cache.

This is the code that I am using :

FutureBuilder(
              future: ReadCache.getStringList(key: 'cache4'),
              builder: (context, snapshot) {
                if (snapshot.hasData) {
                  return ListView.builder(
                      itemCount: snapshot.data.length,
                      itemBuilder: (context, index) {
                        return Padding(
                          padding: const EdgeInsets.all(5.0),
                          child: ListTile(
                            onTap: () async {
                              print(snapshot.data[index]);

                              var newMessage =
                                  await (ReadCache.getString(key: 'cache1'));

                              var response = await http.get(
                                Uri.parse(
                                    'http://192.168.1.4:8080/HongLeong/MENU_REQUEST.do?_dc=1658076505340&reset_context=1&table_id=25510&id_MenuAction=3&path=%3Cp%20class%3D%22x-window-header-path%22%3ELoss%20Event%3C%2Fp%3E&ViewType=MENU_REQUEST&gui_open_popup=1&id_Window=17&activeWindowId=mw_17&noOrigUserDate=true&LocalDate=20220718&LocalTime=00482500&TimeZone=Asia%2FShanghai&UserDate=0&UserTime=0&server_name=OPRISK_DATACOLLECTOR&key_id_list=&cell_context_id=0&id_Desktop=100252&operation_key=1000184&operation_sub_num=-1&is_json=1&is_popup=0&is_search_window=0&ccsfw_conf_by_user=0&is_batch=0&previousToken=1658069547560&historyToken=1658076505339&historyUrl=1'),
                                headers: {HttpHeaders.cookieHeader: newMessage},
                              );

                              LossEventResponseModel lossEventResponseModel =
                                  LossEventResponseModel.fromJson(
                                      jsonDecode(response.body));

                              final listNode = lossEventResponseModel
                                  .response.genericListAnswer.listNode;

                              List<String> hyperlink = [
                                for (final json in listNode
                                    .map((x) => x.toJson())
                                    .where((json) =>
                                        json['field'][0]['field_value'] ==
                                        snapshot.data[index]['Code']))
                                  json["run_hyperlink"],
                              ];

                              print(hyperlink);
                            },
                            title: Text(snapshot.data[index],
                                style: GoogleFonts.poppins(
                                  textStyle: const TextStyle(
                                    fontWeight: FontWeight.normal,
                                    fontSize: 20,
                                  ),
                                )),
                            tileColor: Colors.blueGrey[200],
                            shape: RoundedRectangleBorder(
                                borderRadius: BorderRadius.circular(10)),
                          ),
                        );
                      });
                } else {
                  return const Text("No Data");
                }
              },
            ),

Specifically this part:

the snapshot is referring data from the cache which is obtained from the previous page

this is the code :

 List<Map<String, dynamic>> incidentList = [
                    for (final json in listNode.map((x) => x.toJson()))
                      {
                        'Code': json['field'][0]['field_value'],
                        'Description': json['field'][1]['field_value'],
                        'Organisation Unit': json['field'][2]['field_value'],
                        'Date Reported': json['field'][3]['field_value'],
                        'Status': json['field'][4]['field_value'],
                      }
                  ];

                  final List<String> values =  [];
                  for(final item in incidentList){
                    values.add(item.values.map((e) => e.toString()).join("n"));
                  }
                  await WriteCache.setListString(key: 'cache4', value: values);

The error that I am getting is “Unhandled Exception: type ‘String’ is not a subtype of type ‘int’ of ‘index'”

How do I fix the where condition to where It prints the “json[“run_hyperlink”]” according to the value that is stored in “‘Code’: json[‘field’][0][‘field_value’]”

this is the raw json :

{
  "RESPONSE":{
    "GenericListAnswer":{
      "empty_top_toolbar":"0",
      "no_move_columns":"0",
      "no_add_rem_columns":"0",
      "no_sort_columns":"0",
      "no_resize_columns":"0",
      "no_oper_columns":"0",
      "refresh_data":{
        "ApplEra":"",
        "delay":"0"
      },
      "no_gui_link":"0",
      "index_last":"10742",
      "max_num_rows":"0",
      "index_true_last":"10742",
      "is_history":"0",
      "index_first_visible":"1",
      "display_table_name":"Loss Event",
      "table_id":"25510",
      "table_name":"LossEvent",
      "global_operation":[],
      "num_visible":"200",
      "list_type":"0",
      "list_key":"1",
      "parent_Class_id":"0",
      "parent_common_id":"0",
      "parent_applcol_id":"0",
      "search_num":"0",
      "id_box_search_num":"0",
      "mad_key_list":"",
      "choose_xsl":"0",
      "is_search_popup":"0",
      "section_list_params":"",
      "saved_query":{
        "query":[
          {
            "id":"184",
            "name":"Loss Event",
            "note":"",
            "is_batch":"0",
            "is_validated":"1",
            "show_out_combo":"0",
            "sort_key":"0",
            "custom_gif":"",
            "description":"Loss Event",
            "may_have_checkbox":"0",
            "is_active":"0",
            "qtype":"2",
            "may_be_edited":"1",
            "pinnability":"2"
          },
          {
            "id":"187",
            "name":"Loss Event Days Open Tracking Report",
            "note":"",
            "is_batch":"0",
            "is_validated":"1",
            "show_out_combo":"0",
            "sort_key":"0",
            "custom_gif":"",
            "description":"Loss Event Days Open Tracking Report",
            "may_have_checkbox":"0",
            "is_active":"0",
            "qtype":"2",
            "may_be_edited":"1",
            "pinnability":"2"
          },
          {
            "id":"185",
            "name":"Loss Event 1",
            "note":"",
            "is_batch":"0",
            "is_validated":"1",
            "show_out_combo":"0",
            "sort_key":"0",
            "custom_gif":"",
            "description":"Loss Event 1",
            "may_have_checkbox":"0",
            "is_active":"0",
            "qtype":"2",
            "may_be_edited":"1",
            "pinnability":"2"
          },
          {
            "id":"279",
            "name":"T Loss Event Status summary",
            "note":"",
            "is_batch":"0",
            "is_validated":"1",
            "show_out_combo":"0",
            "sort_key":"0",
            "custom_gif":"",
            "description":"T Loss Event Status summary",
            "may_have_checkbox":"0",
            "is_active":"0",
            "qtype":"2",
            "may_be_edited":"1",
            "pinnability":"2"
          }
        ]
      },
      "QuickSearch":{
        "quick_search_column":[
          "Title",
          "Tajuk",
          "Code"
        ]
      },
      "report_jasper_list":{
        "report_jasper":[
          {
            "display_name":"LE002 - Loss Event Status Summary",
            "id":"15",
            "mad_key":"15",
            "is_param":"1",
            "report_options":"",
            "reportForbiddenFormat":[
              "2",
              "4",
              "5",
              "6"
            ]
          },
          {
            "display_name":"LE003 - Loss Event Days Open Tracking Report",
            "id":"5",
            "mad_key":"5",
            "is_param":"1",
            "report_options":"",
            "reportForbiddenFormat":[
              "2",
              "4",
              "5",
              "6"
            ]
          },
          {
            "display_name":"LE01 - Loss Event Data",
            "id":"2",
            "mad_key":"2",
            "is_param":"1",
            "report_options":"",
            "reportForbiddenFormat":[
              "2",
              "4",
              "5",
              "6"
            ]
          }
        ]
      },
      "wf_configured":"1",
      "op_parameter":"",
      "ListNode":[
        {
          "id":"2",
          "mad_key":"32835",
          "is_custom":"0",
          "is_locked":"0",
          "is_inactive":"1",
          "run_hyperlink":{
            "classid":"25510",
            "id":"2",
            "mad_key":"32835"
          },
          "field":[
            {
              "field_name":"code",
              "col_index":"1",
              "field_value":"LE-0000000002",
              "mad_key":"0",
              "id":"0"
            },
            {
              "field_name":"common_desc_0",
              "col_index":"2",
              "field_value":"test_01",
              "mad_key":"0",
              "id":"0"
            },
            {
              "field_name":"id_Org",
              "col_index":"3",
              "field_value":"01_01_04_01_SA - Shah Alam",
              "mad_key":"100377",
              "id":"100055"
            },
            {
              "field_name":"dateReported",
              "col_index":"4",
              "field_value":"18/09/2020",
              "mad_key":"0",
              "id":"0"
            }
          ]
        },
        {
          "id":"3",
          "mad_key":"32836",
          "is_custom":"0",
          "is_locked":"0",
          "is_inactive":"0",
          "run_hyperlink":{
            "classid":"25510",
            "id":"3",
            "mad_key":"32836"
          },
          "field":[
            {
              "field_name":"code",
              "col_index":"1",
              "field_value":"LE-0000000003",
              "mad_key":"0",
              "id":"0"
            },
            {
              "field_name":"common_desc_0",
              "col_index":"2",
              "field_value":"Transactions not reported (intentional)",
              "mad_key":"0",
              "id":"0"
            },
            {
              "field_name":"id_Org",
              "col_index":"3",
              "field_value":"01_01_04_01_HQ - Menara Hong Leong, Damansara City",
              "mad_key":"100451",
              "id":"100069"
            },
            {
              "field_name":"dateReported",
              "col_index":"4",
              "field_value":"03/02/2018",
              "mad_key":"0",
              "id":"0"
            }
          ]
        },
        {
          "id":"22",
          "mad_key":"20234",
          "is_custom":"0",
          "is_locked":"0",
          "is_inactive":"0",
          "run_hyperlink":{
            "classid":"25510",
            "id":"22",
            "mad_key":"20234"
          },
          "field":[
            {
              "field_name":"code",
              "col_index":"1",
              "field_value":"LE-0000000022",
              "mad_key":"0",
              "id":"0"
            },
            {
              "field_name":"common_desc_0",
              "col_index":"2",
              "field_value":"Transaction type unauthorised",
              "mad_key":"0",
              "id":"0"
            },
            {
              "field_name":"id_Org",
              "col_index":"3",
              "field_value":"01_01_04_01_HQ - Menara Hong Leong, Damansara City",
              "mad_key":"100451",
              "id":"100069"
            },
            {
              "field_name":"dateReported",
              "col_index":"4",
              "field_value":"04/02/2018",
              "mad_key":"0",
              "id":"0"
            }
          ]
        }
    ]
    "BASEL_RESPONSE":{
      "UserDate":"0",
      "UserTime":"0",
      "CurrentTimeStamp":"26/07/2022 21:24:57 +0800",
      "UserName":"Administrator",
      "module_config_1":"0",
      "module_config_2":"0",
      "ErrEntity":{
        "MessageID":"0",
        "last_req_id":"50033",
        "table_id":"25510",
        "key_id_list":"536901,536902,536905,536909,536910,536913",
        "operation_id":"0"
      },
      "is_csv":"0",
      "VersionName":"DYMA @ 6.1.24.0, ORG @ 2017.3.22.15.0.41, GRC @ 2017.3.22.15.0.55, LDC @ 2017.3.22.15.1.8, DYMA_XML @ 2017.3.22.15.0.30, NAS @ 2017.3.22.15.1.22 - Config: 0 - Node: OPRISK_DATACOLLECTOR",
      "ExpiryDate":"31/01/2030",
      "count_key":"2",
      "id_Us":"1",
      "is_popup":"0",
      "tot_messages":"0",
      "my_messages":"0",
      "product":"0"
    },
    "RESPONSE_HEADER":{
      "SessionID":"qNQzbCTdM1821510940CzbeWQ0001",
      "NomeRichiesta":"MENU_REQUEST",
      "ltimeStart":"21245695",
      "ltimeStop":"21250041",
      "ldate_null":"19900101",
      "product":"1",
      "server_name":"OPRISK_DATACOLLECTOR",
      "cell_context_id":"538044",
      "operation_key":"100",
      "operation_sub_num":"-1"
    }
  }
}

Leave a Comment