dart_eval
dart_eval copied to clipboard
value is null, but 'value == null' is false
Map e = ...;
for (var item in e) {
print(item['displayLogId']); // null
bool ifNull = item['displayLogId'] == null;
print(ifNull); / false
}
i print item['displayLogId'] which is null, but for item['displayLogId'] == null, it is false. Is it right, or there is a better method to use?
Hello @cuifengcn,
I'm Michael and I'm interested in contributing to this project!
To answer this question, I have had a similar issue with Map and a trick was to use containsKey. See here for reference.
A correction to your code will be like:
bool containsKey = item.containsKey('displayLogId'); // check if the key 'displayLogId' exists
bool isNull = containsKey && item['displayLogId'] == null; // you can now check if the value for `displayLogId` is `null`
print(isNull);
Let me know if you have any questions about this solution.