flutter 中是否有映射键的 "startsWith" 方法?

Is there a "startsWith" method for map keys in flutter?

我是 Flutter 的初学者,我一直在将 API 获取的数据转换为我的自定义模型。 我正在使用为我提供此数据的 API:

{"meals":[{"idMeal":"52852","strMeal":"Tuna Nicoise","strDrinkAlternate":null,"strCategory":"Seafood",
"strArea":"French","strInstructions":"Heat oven to 200C\/fan 180C\/gas 6. Toss the potatoes with 2 tsp oil and some seasoning. Tip onto a large baking tray, then roast for 20 mins, stirring halfway, until crisp, golden and cooked through.\r\nMeanwhile, put eggs in a small pan of water, bring to the boil, then simmer for 8-10 mins, depending on how you like them cooked. Plunge into a bowl of cold water to cool for a few mins. Peel away the shells, then cut into halves.\r\nIn a large salad bowl, whisk together the remaining oil, red wine vinegar, capers and chopped tomatoes. Season, tip in the onion, spinach, tuna and potatoes, then gently toss together. Top with the eggs, then serve straight away.",
"strMealThumb":"https:\/\/www.themealdb.com\/images\/media\/meals\/yypwwq1511304979.jpg","strTags":null,
"strYoutube":"https:\/\/www.youtube.com\/watch?v=3_UAxkx0u6U",
"strIngredient1":"Potatoes","strIngredient2":"Olive Oil","strIngredient3":"Eggs","strIngredient4":"Red Wine Vinegar","strIngredient5":"Capers","strIngredient6":"Sunflower Oil","strIngredient7":"Red Onions","strIngredient8":"Spinach","strIngredient9":"Tuna","strIngredient10":"","strIngredient11":"","strIngredient12":"","strIngredient13":"","strIngredient14":"","strIngredient15":"","strIngredient16":"","strIngredient17":"","strIngredient18":"","strIngredient19":"","strIngredient20":"",
"strMeasure1":"450g","strMeasure2":"2 tblsp ","strMeasure3":"4","strMeasure4":"1 tbls","strMeasure5":"2 tblsp ","strMeasure6":"50g","strMeasure7":"\u00bd","strMeasure8":"100g ","strMeasure9":"400g","strMeasure10":"","strMeasure11":"","strMeasure12":"","strMeasure13":"","strMeasure14":"","strMeasure15":"","strMeasure16":"","strMeasure17":"","strMeasure18":"","strMeasure19":"","strMeasure20":"",
"strSource":"https:\/\/www.bbcgoodfood.com\/recipes\/9529\/winter-tuna-nioise",
"strImageSource":null,"strCreativeCommonsConfirmed":null,"dateModified":null}]}

我想把所有以“strIngredient”开头的键的值都存储到一个列表中,“strMeasure”也是如此

但我还没有找到可以做到上述的方法。

您可以获得所有 keys,然后根据您的条件检查每一个。

Map<String,String> meals= api_data['meals'][0];

List<String> allKeys = meals.keys.toList();

for(String key in allKeys){
  if(key.startsWith("strIngredient")){
    print(meals[key]);
  }
}