mirror of
https://git.meshkee.com/applications/cssd.git
synced 2026-10-10 22:38:55 +03:30
93 lines
2.1 KiB
Dart
Executable File
93 lines
2.1 KiB
Dart
Executable File
import 'dart:convert';
|
|
|
|
import 'package:cssd/config/urls.dart';
|
|
import 'package:cssd/config/user.dart';
|
|
import 'package:cssd/models/users_model.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import 'package:http/http.dart' as http;
|
|
|
|
class UsersProvider extends ChangeNotifier {
|
|
String searchBoxValue = '';
|
|
|
|
List<Users>? usersBox;
|
|
List<Users>? originalUsersBox;
|
|
|
|
String? medicalCenterId;
|
|
|
|
int? selectedUserIndex;
|
|
Users? selectedUserForItems;
|
|
Users? selectedUserForPackages;
|
|
|
|
String? saveUserId;
|
|
|
|
bool isLoading = false;
|
|
void resetLoading() {
|
|
isLoading = false;
|
|
notifyListeners();
|
|
}
|
|
|
|
void setLoading() {
|
|
isLoading = true;
|
|
}
|
|
|
|
void selectUser(int index) {
|
|
selectedUserIndex = index;
|
|
notifyListeners();
|
|
}
|
|
|
|
void resetSelectedUser() {
|
|
selectedUserIndex = null;
|
|
}
|
|
|
|
void searchUsers(String value) {
|
|
usersBox = [];
|
|
searchBoxValue = value;
|
|
originalUsersBox!.forEach((result) {
|
|
if (result.id.toString().contains(searchBoxValue) ||
|
|
result.userName.toString().contains(searchBoxValue)) {
|
|
usersBox!.add(result);
|
|
}
|
|
});
|
|
notifyListeners();
|
|
}
|
|
|
|
Future<void> getUsers(String medicalCenterId) async {
|
|
String url = Url.getUsers(medicalCenterId);
|
|
var response = await http.get(
|
|
Uri.parse(url),
|
|
headers: {'Authorization': User.token, "Accept": "application/json"},
|
|
);
|
|
|
|
var usersData = json.decode(response.body);
|
|
|
|
originalUsersBox = [];
|
|
|
|
for (var user in usersData['data']['data']) {
|
|
originalUsersBox!.add(
|
|
Users(
|
|
userName: user['name'],
|
|
id: user['id'].toString(),
|
|
phoneNumber: user['cell_number'].toString(),
|
|
),
|
|
);
|
|
}
|
|
searchUsers('');
|
|
}
|
|
|
|
Future<String?> getUserMedicalCenter() async {
|
|
final response = await http.get(
|
|
Uri.parse(Url.getUserInfo),
|
|
headers: {'Authorization': User.token},
|
|
);
|
|
if (response.statusCode == 200) {
|
|
var data = json.decode(response.body)['data'];
|
|
medicalCenterId = data['user']['medical_center_id'].toString();
|
|
notifyListeners();
|
|
return medicalCenterId;
|
|
} else {
|
|
return '';
|
|
}
|
|
}
|
|
}
|