title: Map List of objects from a Json response to a List in flutter
body: <p>SO I am using this API from a rest service that sends me data in the following json format.</p>
  <p><em><strong>API RESPONSE</strong></em></p>
  <pre><code>[
    {
      &quot;id&quot;: 7,
      &quot;daily_allowance_actual_percentage&quot;: {
        &quot;Bone&quot;: [
          0.01,
          &quot;Red&quot;
        ],
        &quot;Muscle Meat&quot;: [
          46.15,
          &quot;Red&quot;
        ],
        &quot;Fruit and Veg&quot;: [
          53.84,
          &quot;Red&quot;
        ]
      },
      &quot;daily_calories_from_this_meal_plan&quot;: 823.25,
      &quot;imperial_weight_of_one_meal&quot;: 5.732025,
      &quot;meal_ingredients_would_make&quot;: 8,
      &quot;meals_per_day&quot;: 2,
      &quot;nutrient_value&quot;: [
        {
          &quot;Calcium&quot;: [
            249.5,
            &quot;mg&quot;,
            &quot;Yellow&quot;,
            0.008800863,
            &quot;ounce&quot;
          ]
        },
        {
          &quot;Choline&quot;: [
            203.65,
            &quot;mg&quot;,
            &quot;Green&quot;,
            0.0071835501,
            &quot;ounce&quot;
          ]
        },
        {
          &quot;Copper&quot;: [
            1.33,
            &quot;mg&quot;,
            &quot;Green&quot;,
            0.00004691442,
            &quot;ounce&quot;
          ]
        },
        {
          &quot;Crude fat&quot;: [
            29.75,
            &quot;g&quot;,
            &quot;Green&quot;,
            1.0494015,
            &quot;ounce&quot;
          ]
        },
        {
          &quot;Folate&quot;: [
            469,
            &quot;mcg&quot;,
            &quot;Green&quot;,
            0.000016543506,
            &quot;ounce&quot;
          ]
        },
        {
          &quot;Iodine&quot;: [
            2.1,
            &quot;mcg&quot;,
            &quot;Red&quot;,
            7.40754e-8,
            &quot;ounce&quot;
          ]
        },
        {
          &quot;Iron&quot;: [
            11.77,
            &quot;mg&quot;,
            &quot;Green&quot;,
            0.00041517497999999997,
            &quot;ounce&quot;
          ]
        },
        {
          &quot;Magnesium&quot;: [
            253,
            &quot;mg&quot;,
            &quot;Red&quot;,
            0.008924322,
            &quot;ounce&quot;
          ]
        },
        {
          &quot;Manganese&quot;: [
            1.82,
            &quot;mg&quot;,
            &quot;Green&quot;,
            0.00006419868,
            &quot;ounce&quot;
          ]
        },
        {
          &quot;Niacin (B3)&quot;: [
            11.88,
            &quot;mg&quot;,
            &quot;Green&quot;,
            0.00041905512,
            &quot;ounce&quot;
          ]
        },
        {
          &quot;Omega-3 excl. ALA and SDA&quot;: [
            0.03,
            &quot;g&quot;,
            &quot;Green&quot;,
            0.00105822,
            &quot;ounce&quot;
          ]
        },
        {
          &quot;Omega-6&quot;: [
            0.93,
            &quot;g&quot;,
            &quot;Green&quot;,
            0.03280482,
            &quot;ounce&quot;
          ]
        },
        {
          &quot;Pantothenic acid (B5)&quot;: [
            1.7,
            &quot;mg&quot;,
            &quot;Green&quot;,
            0.000059965799999999994,
            &quot;ounce&quot;
          ]
        },
        {
          &quot;Phosphorus&quot;: [
            800,
            &quot;mg&quot;,
            &quot;Yellow&quot;,
            0.0282192,
            &quot;ounce&quot;
          ]
        },
        {
          &quot;Potassium&quot;: [
            2766.5,
            &quot;mg&quot;,
            &quot;Red&quot;,
            0.09758552100000001,
            &quot;ounce&quot;
          ]
        },
        {
          &quot;Protein&quot;: [
            56.02,
            &quot;g&quot;,
            &quot;Green&quot;,
            1.9760494800000001,
            &quot;ounce&quot;
          ]
        },
        {
          &quot;Riboflavin (B2)&quot;: [
            0.54,
            &quot;mg&quot;,
            &quot;Green&quot;,
            0.00001904796,
            &quot;ounce&quot;
          ]
        },
        {
          &quot;Selenium&quot;: [
            39.05,
            &quot;mcg&quot;,
            &quot;Red&quot;,
            0.0000013774497,
            &quot;ounce&quot;
          ]
        },
        {
          &quot;Sodium (Na)&quot;: [
            123,
            &quot;mg&quot;,
            &quot;Green&quot;,
            0.004338702,
            &quot;ounce&quot;
          ]
        },
        {
          &quot;Thiamin (B1)&quot;: [
            0.78,
            &quot;mg&quot;,
            &quot;Green&quot;,
            0.00002751372,
            &quot;ounce&quot;
          ]
        },
        {
          &quot;Vitamin A&quot;: [
            4.2,
            &quot;mcg&quot;,
            &quot;Red&quot;,
            1.481508e-7,
            &quot;ounce&quot;
          ]
        },
        {
          &quot;Vitamin C&quot;: [
            1.75,
            &quot;mg&quot;,
            &quot;Green&quot;,
            0.0000617295,
            &quot;ounce&quot;
          ]
        },
        {
          &quot;Vitamin D&quot;: [
            0.15,
            &quot;mcg&quot;,
            &quot;Red&quot;,
            5.2911000000000005e-9,
            &quot;ounce&quot;
          ]
        },
        {
          &quot;Vitamin E&quot;: [
            1.03,
            &quot;mg&quot;,
            &quot;Red&quot;,
            0.000036332220000000006,
            &quot;ounce&quot;
          ]
        },
        {
          &quot;Zinc (Zn)&quot;: [
            8.24,
            &quot;mg&quot;,
            &quot;Green&quot;,
            0.00029065776000000005,
            &quot;ounce&quot;
          ]
        },
        {
          &quot;Calories&quot;: [
            823.25,
            &quot;cal&quot;,
            null,
            &quot;N/A&quot;,
            &quot;ounce&quot;
          ]
        }
      ],
      &quot;pet_name&quot;: &quot;grover&quot;,
      &quot;show_weight_of_balanced_meal&quot;: false,
      &quot;suggestion&quot;: {
        &quot;add_food&quot;: {
          &quot;Yellow&quot;: [
            {
              &quot;Calcium&quot;: [
                &quot;Amaranth, grain, whole, uncooked&quot;,
                &quot;Apple, dried&quot;
              ]
            },
            {
              &quot;Phosphorus&quot;: [
                &quot;Amaranth, grain, whole, uncooked&quot;,
                &quot;Apple, dried&quot;
              ]
            }
          ],
          &quot;Red&quot;: [
            {
              &quot;Iodine&quot;: [
                &quot;Amaranth, grain, whole, uncooked&quot;,
                &quot;Apricot, dried&quot;
              ]
            },
            {
              &quot;Vitamin A&quot;: [
                &quot;Bean, edamame, from frozen, cooked&quot;,
                &quot;Beef Brain&quot;
              ]
            },
            {
              &quot;Vitamin D&quot;: [
                &quot;Beef kidney, raw&quot;,
                &quot;Beef liver, raw&quot;
              ]
            },
            {
              &quot;Vitamin E&quot;: [
                &quot;Amaranth, grain, whole, uncooked&quot;,
                &quot;Apple, dried&quot;
              ]
            },
            {
              &quot;Choline&quot;: [
                &quot;Amaranth, grain, whole, uncooked&quot;,
                &quot;Apple, dried&quot;
              ]
            },
            {
              &quot;Copper&quot;: [
                &quot;Amaranth, grain, whole, uncooked&quot;,
                &quot;Apple, dried&quot;
              ]
            },
            {
              &quot;Crude fat&quot;: [
                &quot;Amaranth, grain, whole, uncooked&quot;,
                &quot;Apple, dried&quot;
              ]
            },
            {
              &quot;Folate&quot;: [
                &quot;Amaranth, grain, whole, uncooked&quot;,
                &quot;Apple, fuji, unpeeled, raw&quot;
              ]
            },
            {
              &quot;Iron&quot;: [
                &quot;Amaranth, grain, whole, uncooked&quot;,
                &quot;Apple, dried&quot;
              ]
            },
            {
              &quot;Manganese&quot;: [
                &quot;Amaranth, grain, whole, uncooked&quot;,
                &quot;Apple, dried&quot;
              ]
            },
            {
              &quot;Niacin (B3)&quot;: [
                &quot;Apple, fuji, unpeeled, raw&quot;,
                &quot;Apple, golden delicious, unpeeled, raw&quot;
              ]
            },
            {
              &quot;Omega-3 excl. ALA and SDA&quot;: [
                &quot;Bass, fillet, raw&quot;,
                &quot;Beef Brain&quot;
              ]
            },
            {
              &quot;Omega-6&quot;: [
                &quot;Amaranth, grain, whole, uncooked&quot;,
                &quot;Avocado, raw&quot;
              ]
            },
            {
              &quot;Pantothenic acid (B5)&quot;: [
                &quot;Amaranth, grain, whole, uncooked&quot;,
                &quot;Apple, dried&quot;
              ]
            },
            {
              &quot;Protein&quot;: [
                &quot;Amaranth, grain, whole, uncooked&quot;,
                &quot;Apple, dried&quot;
              ]
            },
            {
              &quot;Riboflavin (B2)&quot;: [
                &quot;Amaranth, grain, whole, uncooked&quot;,
                &quot;Apple, fuji, unpeeled, raw&quot;
              ]
            },
            {
              &quot;Sodium (Na)&quot;: [
                &quot;Amaranth, grain, whole, uncooked&quot;,
                &quot;Apple, dried&quot;
              ]
            },
            {
              &quot;Thiamin (B1)&quot;: [
                &quot;Amaranth, grain, whole, uncooked&quot;,
                &quot;Apple, fuji, unpeeled, raw&quot;
              ]
            },
            {
              &quot;Zinc (Zn)&quot;: [
                &quot;Amaranth, grain, whole, uncooked&quot;,
                &quot;Apple, dried&quot;
              ]
            }
          ]
        },
        &quot;remove_food&quot;: {
          &quot;Yellow&quot;: [],
          &quot;Red&quot;: [
            {
              &quot;Magnesium&quot;: [
                &quot;Beef, all cuts, untrimmed, raw, no bone&quot;,
                &quot;Apricot, dried&quot;
              ]
            },
            {
              &quot;Potassium&quot;: [
                &quot;Beef, all cuts, untrimmed, raw, no bone&quot;,
                &quot;Apricot, dried&quot;
              ]
            },
            {
              &quot;Selenium&quot;: [
                &quot;Beef, all cuts, untrimmed, raw, no bone&quot;,
                &quot;Apricot, dried&quot;
              ]
            }
          ]
        }
      },
      &quot;total_calories_in_a_meal_plan&quot;: 3293,
      &quot;total_imperial_weight_of_a_meal_plan&quot;: 45.8562,
      &quot;total_weight_of_a_meal_plan&quot;: 1300,
      &quot;weight_of_one_meal&quot;: 162.5,
      &quot;feeding_plan_details&quot;: [
        {
          &quot;id&quot;: 23,
          &quot;imperial_quantity&quot;: 14.1096,
          &quot;quantity&quot;: 400,
          &quot;food&quot;: {
            &quot;id&quot;: 5,
            &quot;bone_percentage&quot;: 0,
            &quot;calcium_phosphorous_ratio&quot;: 0.14,
            &quot;name&quot;: &quot;Beef, all cuts, untrimmed, raw, no bone&quot;,
            &quot;omega_ratio&quot;: 0,
            &quot;omega_ratio_color&quot;: &quot;Red&quot;,
            &quot;calcium_phosphorous_ratio_color&quot;: &quot;Red&quot;
          }
        },
        {
          &quot;id&quot;: 24,
          &quot;imperial_quantity&quot;: 7.0548,
          &quot;quantity&quot;: 200,
          &quot;food&quot;: {
            &quot;id&quot;: 45,
            &quot;bone_percentage&quot;: 0,
            &quot;calcium_phosphorous_ratio&quot;: 0.56,
            &quot;name&quot;: &quot;Apricot, dried&quot;,
            &quot;omega_ratio&quot;: 0,
            &quot;omega_ratio_color&quot;: &quot;Red&quot;,
            &quot;calcium_phosphorous_ratio_color&quot;: &quot;Yellow&quot;
          }
        },
        {
          &quot;id&quot;: 25,
          &quot;imperial_quantity&quot;: 17.637,
          &quot;quantity&quot;: 500,
          &quot;food&quot;: {
            &quot;id&quot;: 222,
            &quot;bone_percentage&quot;: 0,
            &quot;calcium_phosphorous_ratio&quot;: 0.38,
            &quot;name&quot;: &quot;Bean, haricot, dried&quot;,
            &quot;omega_ratio&quot;: 0,
            &quot;omega_ratio_color&quot;: &quot;Red&quot;,
            &quot;calcium_phosphorous_ratio_color&quot;: &quot;Red&quot;
          }
        },
        {
          &quot;id&quot;: 26,
          &quot;imperial_quantity&quot;: 7.0548,
          &quot;quantity&quot;: 200,
          &quot;food&quot;: {
            &quot;id&quot;: 294,
            &quot;bone_percentage&quot;: 0,
            &quot;calcium_phosphorous_ratio&quot;: 0.08,
            &quot;name&quot;: &quot;Pork, all cuts, lean, raw&quot;,
            &quot;omega_ratio&quot;: 0.09,
            &quot;omega_ratio_color&quot;: &quot;Yellow&quot;,
            &quot;calcium_phosphorous_ratio_color&quot;: &quot;Red&quot;
          }
        }
      ]
    }
  ]
  </code></pre>
  <p>And I use the following method to insert the values coming from the api response into a list of that I need to use later on.</p>
  <p><em><strong>Method I use</strong></em></p>
  <pre><code>List&lt;AllMealPlanModel&gt; _allMealPlanList = new List&lt;AllMealPlanModel&gt;();
  //
    Future&lt;List&lt;AllMealPlanModel&gt;&gt; getAllMealPlanData(String item) async {
      // await _fetchCategoryData();
      //
      _mealPlanApiUrl =
      'feeding_plans/fetch_all?user_email=$_userEmail&amp;user_token=$_userToken&amp;pet_id=$item';
      String _baseUrl = 'https://api.pawfect-balance.oz.to/';
      String _fullUrl = _baseUrl + _mealPlanApiUrl;
      final response = await CallApi().getData(_mealPlanApiUrl);
      if (response.statusCode == 200) {
        // If the call to the server was successful, parse the JSON
        List&lt;dynamic&gt; values = new List&lt;dynamic&gt;();
  //// error points at here ////
        values = json.decode(response.body);
        if (values.length &gt; 0) {
          for (int i = 0; i &lt; values.length; i++) {
            if (values[i] != null) {
              Map&lt;String, dynamic&gt; map = values[i];
              _allMealPlanList.add(AllMealPlanModel.fromJson(map));
              debugPrint('Id-------${map['id']}');
              debugPrint('pet_name-------${map['petName']}');
            }
          }
        }
        print(_allMealPlanList);
        return _allMealPlanList;
      } else {
        _allMealPlanList = [];
        _showSnackbar('A Network Error Occurred.!', errorNet);
        return _allMealPlanList;
        // If that call was not successful, throw an error.
        // throw Exception('Failed to load data');
      }
    }
  </code></pre>
  <p>In my debugger when I debug the app it gives me following error.</p>
  <pre><code>Unhandled Exception: type '_InternalLinkedHashMap&lt;String, dynamic&gt;' is not a subtype of type 'List&lt;dynamic&gt;'
  </code></pre>
  <p>How can I resolve this? what am I doing wrong in my method? Can someone help me to figure this out?</p>