skip to Main Content
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.

2

Answers


  1. 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");
    }
    
    Login or Signup to reply.
  2. If every value in map is not empty then this will return true

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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search