Map isNotEmpty
Map isNotEmpty
property returns a boolean value of true
if this Map is not empty, or false
if this Map is empty.
Syntax
The syntax to check if the Map myMap
is not empty is
myMap.isNotEmpty
Examples
Check if Map is Not Empty
In the following Dart Program, we take a Map myMap
with three key-value pairs, and programmatically check if this Map is not empty, using Map.isNotEmpty
property.
main.dart
</>
Copy
void main() {
var myMap = {'apple': 25, 'banana': 10, 'cherry': 6};
if ( myMap.isNotEmpty ) {
print('Map is not empty.');
} else {
print('Map is empty.');
}
}
Output
Map is not empty.
Conclusion
In this Dart Tutorial, we learned how to check if given Map is not empty, using Map.isNotEmpty
property.