This commit is contained in:
2025-03-25 13:49:02 +01:00
parent 44e26460d8
commit d2bb65a91e
12 changed files with 546 additions and 6 deletions
+26 -4
View File
@@ -354,18 +354,40 @@ The following extensions have been added to the `List` object:
new `List` or filter the existing list by specifying the `inplace` option.
```dart
final list = [1, 2, 2, 3, 4, 4];
final uniqueList = list.unique();
const List<int> list = [1, 2, 2, 3, 4, 4];
final List<int> uniqueList = list.unique();
print(uniqueList); // Output: [1, 2, 3, 4]
final people = [
const List<Person> people = [
Person(id: 1, name: 'Alice'),
Person(id: 2, name: 'Bob'),
Person(id: 1, name: 'Alice Duplicate'),
];
final uniquePeople = people.unique((person) => person.id);
final List<Person> uniquePeople = people.unique((person) => person.id);
print(uniquePeople.map((p) => p.name)); // Output: ['Alice', 'Bob']
```
- `isNullOrEmpty`: Checks if a list is either null or empty.
```dart
const List<int> list = [1, 2, 3];
print(list.isNullOrEmpty); // Output: false
final List<int> emptyList = <int>[];
print(emptyList.isNullOrEmpty); // Output: true
final List<int>? nullList = null;
print(nullList.isNullOrEmpty); // Output: true
```
- `isNullOrEmpty`: Checks if a list is either null or empty.
```dart
final List<int> list = [1, 2, 3];
print(list.isNullOrEmpty); // Output: false
final List<int> emptyList = <int>[];
print(emptyList.isNullOrEmpty); // Output: true
final List<int>? nullList = null;
print(nullList.isNullOrEmpty); // Output: true
```
## Contributing
Contributions are welcome! Feel free to fork the repository and submit pull