onlyOwned<T> method
Returns a new list containing only the elements that are owned by the specified uid.
The uid parameter represents the unique identifier of the owner.
The function filters the elements based on their ownerUID property, returning only the elements
whose ownerUID matches the specified uid.
Returns a new list containing only the elements owned by the specified uid.
Example:
class MyObject {
final String ownerUID;
final String name;
MyObject(this.ownerUID, this.name);
}
List<MyObject> objects = [
MyObject('user1', 'Object 1'),
MyObject('user2', 'Object 2'),
MyObject('user1', 'Object 3'),
];
List<MyObject> ownedObjects = objects.onlyOwned('user1');
print(ownedObjects.map((obj) => obj.name).toList()); // Output: [Object 1, Object 3]
Implementation
List<T> onlyOwned<T>(String uid) {
Iterable<dynamic> objects = this;
return List<T>.from(objects.where((element) => element.ownerUID == uid));
}