2

Hello I am new to Flutter, I am fetching array from JSON like below and I would like to check if every "value" = "";

"food_table": [
{
  "name": "aaa",
  "key": "aaa",
  "value": ""
},
{
  "name": "bbb",
  "key": "bbb",
  "value": ""
},
{
  "name": "cccc",
  "key": "cccc",
  "value": ""
},
{
  "name": "dddd",
  "key": "dddd",
  "value": ""
}
]

2 Answers 2

2

The answer is in your question itself.

You can use List.every method for this, like this.

var jsonData = { "food_table": [/* all items */] }; // assuming this is your full data
bool everyValueIsEmpty = jsonData["food_table"]
      .every((item) =>item["value"] == "");

print(everyValueIsEmpty); // Will print true
Sign up to request clarification or add additional context in comments.

Comments

2

Since you are having a List you can use the method every.

final List<Map<String, String>> foodTable = [
    {"name": "aaa", "key": "aaa", "value": ""},
    {"name": "bbb", "key": "bbb", "value": ""},
    {"name": "cccc", "key": "cccc", "value": ""},
    {"name": "dddd", "key": "dddd", "value": ""}
  ];

final bool empty = foodTable.every((food) => food['value'] == "");
print(empty); // Prints true

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.