'flutter init state compare and use the data

I want to compare data in assets and servers. I have a map for my image in the asset and I got a list of images from the server. so I want to compare them in my init state and if they are equal, use asset and if it's not equal, use link of server. here is my map :

 Map icons ={
    "sport" : {
       "light": MyIcons.varzeshi,
       "dark" : MyIcons.varzeshi_dark,
    },
    "Cinema & Photography" : {
       "light": MyIcons.namayeshi,
       "dark" : MyIcons.namayeshi_dark,
    },
    "History" : {
       "light": MyIcons.tarikh,
       "dark" : MyIcons.tarikh_dark,
    },
    "Story" : {
       "light": MyIcons.revayatgari,
       "dark" : MyIcons.revayatgari_dark,
    },
    "Psychology" : {
       "light": MyIcons.ravanshenasi,
       "dark" : MyIcons.ravanshenasi_dark,
    },
    "Entertainment" : {
       "light": MyIcons.sargarmi,
       "dark" : MyIcons.sargarmi_dark,
    },
    "Literature" : {
       "light": MyIcons.adabiat,
       "dark" : MyIcons.adabiat_dark,
    },
    "Technology" : {
       "light": MyIcons.fanavari,
       "dark" : MyIcons.fanavari_dark,
    },
    "News & Review" : {
       "light": MyIcons.khabari,
       "dark" : MyIcons.khabari_dark,
    },
    "book reading" : {
       "light": MyIcons.ketab,
       "dark" : MyIcons.ketab_dark,
    },
    "Cultural & Social" : {
       "light": MyIcons.ejtemaei,
       "dark" : MyIcons.ejtemaei_dark,
    },
    "Health" : {
       "light": MyIcons.pezeshki,
       "dark" : MyIcons.pezeshki_dark,
    },
    "language" : {
       "light": MyIcons.zabaan,
       "dark" : MyIcons.zabaan_dark,
    },
    "Music" : {
       "light": MyIcons.mosighi,
       "dark" : MyIcons.mosighi_dark,
    },
    "Business" : {
       "light": MyIcons.kasbkar,
       "dark" : MyIcons.kasbkar_dark,
    },
    "Philosophy & Art" : {
       "light": MyIcons.falsafedin,
       "dark" : MyIcons.falsafedin_dark,
    },
    "Self improvement & Lifestyle" : {
       "light": MyIcons.toseEfardi,
       "dark" : MyIcons.toseEfardi_dark,
    },
  };

and here is my data from the server :

data[index]

server data :

 {
        "Cat_Image_Dark": "https://varzeshi-dark.svg",
        "Cat_Image": "https://varzeshi.svg",
        "Cat_EN_Name": "Sport"
      },

so how can I find the link to the server in the map?



Solution 1:[1]

I am assuming that the data from the server is coming from some sort of API and is passed in as a string. If so:

import 'dart:convert';

var dataFromServer = json.decode(data[index]);
print(dataFromServer["Cat_Image"]); //prints "https://varzeshi.svg"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tray Denney