Search code examples
flutterdartstaticvar

Flutter create copy from static variable


Could you please tell me how can I make a copy from static variable? Let say I have a static member :

    static Map localData = {
        "Weapons": [
          "Rifles",
          "DMRs",
          "Sniper Rifles",
          "Shotguns",
          "Submachine Guns",
          "Lightmachine Guns",
          "Pistols",
          "Melee",
          "Throwables",
          "Misc"
        ],
    }

Then in other class, I want to access the static variable and make a copy from it, but it keeps directing to this static member.

  Map _data = LocalData.localData;

 List<String> weapon = _data['Weapons'];
    print(weapon);
    weapon.removeAt(8);

So when I remove data from the list, the static one will be removed. I just want to make a copy from it, so weapon is not directly from localData. Anyone?


Solution

  • try this

    List<String> weapon = List.from(_data['Weapons']);