Skip to content

Commit c828324

Browse files
committed
Add .isEmpty term entry for Dart Map
Adds documentation for the Dart Map `.isEmpty` property, including a brief introduction, syntax, and a usage example aligned with Docs guidelines.
1 parent 0f9a05f commit c828324

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
Title: '.isEmpty'
3+
Description: 'Checks if a Map contains no key-value pairs.'
4+
Subjects:
5+
- 'Computer Science'
6+
- 'Code Foundations'
7+
Tags:
8+
- 'Dart'
9+
- 'Map'
10+
- 'Properties'
11+
CatalogContent:
12+
- 'learn-dart'
13+
- 'paths/computer-science'
14+
---
15+
16+
In Dart, the **`.isEmpty`** property is used to check if a `Map` contains no key-value pairs. If the map is empty, the property returns `true`. Otherwise, it returns `false`.
17+
18+
## Syntax
19+
20+
```pseudo
21+
mapName.isEmpty
22+
```
23+
24+
- `mapName`: The `Map` to be checked.
25+
26+
## Example
27+
28+
The following example demonstrates the usage of the `.isEmpty` property:
29+
30+
```dart
31+
void main() {
32+
// Creating an empty Map
33+
Map<String, int> emptyCart = {};
34+
35+
// Creating a Map with items
36+
Map<String, int> fruitCart = {'Apple': 3, 'Banana': 5};
37+
38+
// Checking if the maps are empty
39+
print(emptyCart.isEmpty);
40+
print(fruitCart.isEmpty);
41+
}
42+
```
43+
44+
The above code produces the following output:
45+
46+
```shell
47+
true
48+
false
49+
```
50+
51+
The `.isEmpty` property can also be used in conditional statements:
52+
53+
```dart
54+
void main() {
55+
Map<String, String> userInfo = {};
56+
57+
if (userInfo.isEmpty) {
58+
print('No user data available.');
59+
} else {
60+
print('User data found.');
61+
}
62+
}
63+
```
64+
65+
The above code produces the following output:
66+
67+
```shell
68+
No user data available.
69+
```

0 commit comments

Comments
 (0)