improvements
parent
c4160ff98b
commit
0ffc0f650f
@ -0,0 +1,35 @@
|
|||||||
|
import 'package:test_sa/models/base.dart';
|
||||||
|
|
||||||
|
class MedicalDepartmentModel extends Base {
|
||||||
|
MedicalDepartmentModel({
|
||||||
|
this.departmentName, this.departmentCode, this.ntCode, this.costCenterNumber, this.costCenterName, this.name, this.id, this.createdBy, this.createdDate, this.modifiedBy, this.modifiedDate
|
||||||
|
}) : super(identifier: id?.toString() ?? '', name: departmentName); // Handle potential null id
|
||||||
|
|
||||||
|
MedicalDepartmentModel.fromJson(Map<String, dynamic> json) {
|
||||||
|
departmentName = json['departmentName'] ?? json['name'];
|
||||||
|
departmentCode = json['departmentCode'];
|
||||||
|
ntCode = json['ntCode'];
|
||||||
|
costCenterNumber = json['costCenterNumber'];
|
||||||
|
costCenterName = json['costCenterName'];
|
||||||
|
name = json['name'];
|
||||||
|
id = json['id'];
|
||||||
|
createdBy = json['createdBy'];
|
||||||
|
createdDate = json['createdDate'];
|
||||||
|
modifiedBy = json['modifiedBy'];
|
||||||
|
modifiedDate = json['modifiedDate'];
|
||||||
|
}
|
||||||
|
|
||||||
|
num? id; // Now nullable
|
||||||
|
String? departmentName; // Now nullable
|
||||||
|
String? departmentCode; // Now nullable
|
||||||
|
String? ntCode;
|
||||||
|
String? costCenterNumber;
|
||||||
|
String? costCenterName;
|
||||||
|
String? name;
|
||||||
|
String? createdBy;
|
||||||
|
String? createdDate;
|
||||||
|
String? modifiedBy;
|
||||||
|
String? modifiedDate;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:http/http.dart';
|
||||||
|
import 'package:test_sa/controllers/api_routes/api_manager.dart';
|
||||||
|
import 'package:test_sa/controllers/api_routes/urls.dart';
|
||||||
|
import 'package:test_sa/modules/loan_module/models/medical_department_model.dart';
|
||||||
|
import 'package:test_sa/providers/loading_list_notifier.dart';
|
||||||
|
|
||||||
|
class MedicalDepartmentProvider extends LoadingListNotifier<MedicalDepartmentModel> {
|
||||||
|
@override
|
||||||
|
Future getData({int? id}) async {
|
||||||
|
if (loading == true) return -2;
|
||||||
|
loading = true;
|
||||||
|
notifyListeners();
|
||||||
|
try {
|
||||||
|
Response response = await ApiManager.instance.get(URLs.getMedDepartmentBasedOnSite + "?customerId=$id");
|
||||||
|
stateCode = response.statusCode;
|
||||||
|
if (response.statusCode >= 200 && response.statusCode < 300) {
|
||||||
|
List categoriesListJson = json.decode(response.body)["data"];
|
||||||
|
items = categoriesListJson.map((item) => MedicalDepartmentModel.fromJson(item)).toList();
|
||||||
|
}
|
||||||
|
loading = false;
|
||||||
|
notifyListeners();
|
||||||
|
return response.statusCode;
|
||||||
|
} catch (error) {
|
||||||
|
loading = false;
|
||||||
|
stateCode = -1;
|
||||||
|
notifyListeners();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue