init
This commit is contained in:
41
filcnaplo/lib/api/providers/user_provider.dart
Normal file
41
filcnaplo/lib/api/providers/user_provider.dart
Normal file
@@ -0,0 +1,41 @@
|
||||
import 'package:filcnaplo/models/user.dart';
|
||||
import 'package:filcnaplo_kreta_api/models/student.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
class UserProvider with ChangeNotifier {
|
||||
Map<String, User> _users = {};
|
||||
String? _selectedUserId;
|
||||
User? get user => _users[_selectedUserId];
|
||||
|
||||
// _user properties
|
||||
String? get instituteCode => user?.instituteCode;
|
||||
String? get id => user?.id;
|
||||
String? get name => user?.name;
|
||||
String? get username => user?.username;
|
||||
String? get password => user?.password;
|
||||
Student? get student => user?.student;
|
||||
|
||||
void setUser(String userId) {
|
||||
_selectedUserId = userId;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void addUser(User user) {
|
||||
_users[user.id] = user;
|
||||
print("DEBUG: Added User: ${user.id} ${user.name}");
|
||||
}
|
||||
|
||||
void removeUser(String userId) {
|
||||
_users.removeWhere((key, value) => key == userId);
|
||||
if (_users.isNotEmpty) _selectedUserId = _users.keys.first;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
User getUser(String userId) {
|
||||
return _users[userId]!;
|
||||
}
|
||||
|
||||
List<User> getUsers() {
|
||||
return _users.values.toList();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user