1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-10-23 06:53:23 +00:00
comunicmobile/lib/lists/users_list.dart

40 lines
860 B
Dart
Raw Normal View History

import 'dart:collection';
import 'package:comunic/models/user.dart';
/// Users list
///
/// @author Pierre HUBERT
class UsersList extends ListBase<User> {
2021-03-13 14:14:54 +00:00
List<User> _list = [];
int get length => _list.length;
2019-04-25 06:56:16 +00:00
set length(l) => _list.length = l;
@override
User operator [](int index) {
return _list[index];
}
@override
void operator []=(int index, User value) {
_list[index] = value;
}
/// Find a user with a specific ID
2019-04-25 06:56:16 +00:00
User getUser(int userID) {
for (int i = 0; i < this.length; i++)
if (this[i].id == userID) return this[i];
2019-04-25 06:56:16 +00:00
throw "User not found in the list!";
}
2019-04-25 06:56:16 +00:00
/// Check if the user is included in this list or not
bool hasUser(int userID) => any((f) => f.id == userID);
2019-04-25 06:56:16 +00:00
/// Get the list of users ID present in this list
List<int> get usersID => List.generate(length, (i) => this[i].id);
}