Home > other >  How to I check Map all datas are not empty or not in Flutter?
How to I check Map all datas are not empty or not in Flutter?

Time:12-11

Map? toSendMap = {
1: "",
2: "",
3: "",
4: "",
5: "",
6: "",
7: "",
8: "",
9: "",
10: "",
11: "",
12: "",
13: "",
14: "",
15: "",
16: "",
17: "",
18: "",
19: "",
20: "",
21: "",
22: "",
23: "",
24: "",
25: "",
26: "",
27: "",
28: "",
29: "",
30: "",
31: "",
 };

Here is my Map data and I want to control it if it has any key is empty . What should I write to check it?

I tried every way but I couldn't get any result.

CodePudding user response:

You can get values like youMap.values, then you can make it list and joint into single string to perform empty string check.

Map? toSendMap = {
  1: "",
  2: "",
  
};

final mapValues = toSendMap.values.join("");
if (mapValues.isEmpty) {
  print("got empty result");
} else {
  print("all are not empty");
}

CodePudding user response:

try this:

toSendMap?.entries.forEach((element) {
  if ((element.value as String).isEmpty) {
    print("empty");
  }
});

CodePudding user response:

If every value in map is not empty then this will return true

var isValid = toSendMap?.values.every((element) => (element as String).isNotEmpty)

  • Related