Compare commits
79 Commits
ui_ux_roll
...
master
@ -0,0 +1,404 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:http/http.dart';
|
||||||
|
import 'package:http/io_client.dart';
|
||||||
|
|
||||||
|
import '../exceptions/api_exception.dart';
|
||||||
|
|
||||||
|
typedef FactoryConstructor<U> = U Function(dynamic);
|
||||||
|
|
||||||
|
class APIError {
|
||||||
|
int? errorCode;
|
||||||
|
String? errorMessage;
|
||||||
|
|
||||||
|
APIError(this.errorCode, this.errorMessage);
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => {'errorCode': errorCode, 'errorMessage': errorMessage};
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return jsonEncode(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
APIException _throwAPIException(Response response) {
|
||||||
|
print(response.statusCode);
|
||||||
|
switch (response.statusCode) {
|
||||||
|
case 200:
|
||||||
|
APIError? apiError;
|
||||||
|
if (response.body.isNotEmpty) {
|
||||||
|
var jsonError = jsonDecode(response.body);
|
||||||
|
debugPrint(jsonError);
|
||||||
|
apiError = APIError(response.statusCode, jsonError[0]);
|
||||||
|
}
|
||||||
|
return APIException(APIException.BAD_REQUEST, error: apiError);
|
||||||
|
case 400:
|
||||||
|
APIError? apiError;
|
||||||
|
if (response.body.isNotEmpty) {
|
||||||
|
var jsonError = jsonDecode(response.body);
|
||||||
|
debugPrint("json error : $jsonError");
|
||||||
|
apiError = APIError(response.statusCode, jsonError[0]);
|
||||||
|
}
|
||||||
|
return APIException(APIException.BAD_REQUEST, error: apiError);
|
||||||
|
case 401:
|
||||||
|
return const APIException(APIException.UNAUTHORIZED);
|
||||||
|
case 403:
|
||||||
|
return const APIException(APIException.FORBIDDEN);
|
||||||
|
case 404:
|
||||||
|
return const APIException(APIException.NOT_FOUND);
|
||||||
|
case 500:
|
||||||
|
return const APIException(APIException.INTERNAL_SERVER_ERROR);
|
||||||
|
case 444:
|
||||||
|
var downloadUrl = response.headers["location"];
|
||||||
|
return APIException(APIException.UPGRADE_REQUIRED, arguments: downloadUrl);
|
||||||
|
default:
|
||||||
|
return const APIException(APIException.OTHER);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ApiClient {
|
||||||
|
static final ApiClient _instance = ApiClient._internal();
|
||||||
|
|
||||||
|
ApiClient._internal();
|
||||||
|
|
||||||
|
factory ApiClient() => _instance;
|
||||||
|
|
||||||
|
Future<U> postJsonForObject<T, U>(FactoryConstructor<U> factoryConstructor, String url, T jsonObject,
|
||||||
|
{String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0, bool isFormData = false}) async {
|
||||||
|
var defaultHeaders = {'Accept': 'application/json'};
|
||||||
|
if (headers != null && headers.isNotEmpty) {
|
||||||
|
defaultHeaders.addAll(headers);
|
||||||
|
}
|
||||||
|
if (!kReleaseMode) {
|
||||||
|
debugPrint("Url:$url");
|
||||||
|
var bodyJson = json.encode(jsonObject);
|
||||||
|
debugPrint("body:$bodyJson");
|
||||||
|
}
|
||||||
|
var response = await postJsonForResponse(url, jsonObject, token: token, queryParameters: queryParameters, headers: headers, retryTimes: retryTimes, isFormData: isFormData);
|
||||||
|
try {
|
||||||
|
var jsonData = jsonDecode(response.body);
|
||||||
|
if (jsonData != null) {
|
||||||
|
debugPrint(jsonData.runtimeType.toString());
|
||||||
|
return factoryConstructor(jsonData);
|
||||||
|
} else {
|
||||||
|
APIError? apiError;
|
||||||
|
apiError = APIError(response.statusCode, jsonData[0]);
|
||||||
|
throw APIException(APIException.BAD_REQUEST, error: apiError);
|
||||||
|
}
|
||||||
|
} catch (ex) {
|
||||||
|
if (ex is APIException) {
|
||||||
|
rethrow;
|
||||||
|
} else {
|
||||||
|
throw APIException(APIException.BAD_RESPONSE_FORMAT, arguments: ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<U> putJsonForObject<T, U>(FactoryConstructor<U> factoryConstructor, String url, T jsonObject,
|
||||||
|
{String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0, bool isFormData = false}) async {
|
||||||
|
var defaultHeaders = {'Accept': 'application/json'};
|
||||||
|
if (headers != null && headers.isNotEmpty) {
|
||||||
|
defaultHeaders.addAll(headers);
|
||||||
|
}
|
||||||
|
if (!kReleaseMode) {
|
||||||
|
debugPrint("Url:$url");
|
||||||
|
var bodyJson = json.encode(jsonObject);
|
||||||
|
debugPrint("body:$bodyJson");
|
||||||
|
}
|
||||||
|
var response = await putJsonForResponse(url, jsonObject, token: token, queryParameters: queryParameters, headers: headers, retryTimes: retryTimes, isFormData: isFormData);
|
||||||
|
try {
|
||||||
|
var jsonData = jsonDecode(response.body);
|
||||||
|
if (jsonData != null) {
|
||||||
|
debugPrint(jsonData.runtimeType.toString());
|
||||||
|
return factoryConstructor(jsonData);
|
||||||
|
} else {
|
||||||
|
APIError? apiError;
|
||||||
|
apiError = APIError(response.statusCode, jsonData[0]);
|
||||||
|
throw APIException(APIException.BAD_REQUEST, error: apiError);
|
||||||
|
}
|
||||||
|
} catch (ex) {
|
||||||
|
if (ex is APIException) {
|
||||||
|
rethrow;
|
||||||
|
} else {
|
||||||
|
throw APIException(APIException.BAD_RESPONSE_FORMAT, arguments: ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Response> postJsonForResponse<T>(String url, T jsonObject,
|
||||||
|
{String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0, bool isFormData = false}) async {
|
||||||
|
int currentRetryTime = retryTimes;
|
||||||
|
String? requestBody;
|
||||||
|
late Map<String, String> stringObj;
|
||||||
|
if (jsonObject != null) {
|
||||||
|
requestBody = jsonEncode(jsonObject);
|
||||||
|
if (headers == null) {
|
||||||
|
headers = {'Content-Type': 'application/json'};
|
||||||
|
} else {
|
||||||
|
headers['Content-Type'] = 'application/json';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!kReleaseMode) {
|
||||||
|
print("url:$url");
|
||||||
|
print("requestBody:$requestBody");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isFormData) {
|
||||||
|
headers = {'Content-Type': 'application/x-www-form-urlencoded'};
|
||||||
|
stringObj = ((jsonObject ?? {}) as Map<String, dynamic>).map((key, value) => MapEntry(key, value?.toString() ?? ""));
|
||||||
|
}
|
||||||
|
if (!kReleaseMode) {
|
||||||
|
print("url:$url");
|
||||||
|
print("requestBody:$requestBody");
|
||||||
|
}
|
||||||
|
Future<Response> retry(APIException exception) async {
|
||||||
|
if (currentRetryTime > 0) {
|
||||||
|
currentRetryTime -= 1;
|
||||||
|
debugPrint('will retry after 3 seconds...');
|
||||||
|
await Future.delayed(const Duration(seconds: 3));
|
||||||
|
return await _postForResponse(url, requestBody, token: token, queryParameters: queryParameters, headers: headers);
|
||||||
|
} else {
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return await _postForResponse(url, isFormData ? stringObj : requestBody, token: token, queryParameters: queryParameters, headers: headers);
|
||||||
|
} on SocketException catch (e) {
|
||||||
|
return await retry(APIException(APIException.OTHER, arguments: e));
|
||||||
|
} on HttpException catch (e) {
|
||||||
|
return await retry(APIException(APIException.OTHER, arguments: e));
|
||||||
|
} on TimeoutException catch (e) {
|
||||||
|
throw APIException(APIException.TIMEOUT, arguments: e);
|
||||||
|
} on ClientException catch (e) {
|
||||||
|
return await retry(APIException(APIException.OTHER, arguments: e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Response> putJsonForResponse<T>(String url, T jsonObject,
|
||||||
|
{String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0, bool isFormData = true}) async {
|
||||||
|
int currentRetryTime = retryTimes;
|
||||||
|
String? requestBody;
|
||||||
|
late Map<String, String> stringObj;
|
||||||
|
if (jsonObject != null) {
|
||||||
|
requestBody = jsonEncode(jsonObject);
|
||||||
|
if (headers == null) {
|
||||||
|
headers = {'Content-Type': 'application/json'};
|
||||||
|
} else {
|
||||||
|
headers['Content-Type'] = 'application/json';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!kReleaseMode) {
|
||||||
|
print(jsonObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isFormData) {
|
||||||
|
headers = {'Content-Type': 'application/x-www-form-urlencoded'};
|
||||||
|
stringObj = ((jsonObject ?? {}) as Map<String, dynamic>).map((key, value) => MapEntry(key, value?.toString() ?? ""));
|
||||||
|
}
|
||||||
|
if (!kReleaseMode) {
|
||||||
|
print("url:$url");
|
||||||
|
print("requestBody:$requestBody");
|
||||||
|
}
|
||||||
|
Future<Response> retry(APIException exception) async {
|
||||||
|
if (currentRetryTime > 0) {
|
||||||
|
currentRetryTime -= 1;
|
||||||
|
debugPrint('will retry after 3 seconds...');
|
||||||
|
await Future.delayed(const Duration(seconds: 3));
|
||||||
|
return await _putForResponse(url, requestBody, token: token, queryParameters: queryParameters, headers: headers);
|
||||||
|
} else {
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return await _postForResponse(url, isFormData ? stringObj : requestBody, token: token, queryParameters: queryParameters, headers: headers);
|
||||||
|
} on SocketException catch (e) {
|
||||||
|
return await retry(APIException(APIException.OTHER, arguments: e));
|
||||||
|
} on HttpException catch (e) {
|
||||||
|
return await retry(APIException(APIException.OTHER, arguments: e));
|
||||||
|
} on TimeoutException catch (e) {
|
||||||
|
throw APIException(APIException.TIMEOUT, arguments: e);
|
||||||
|
} on ClientException catch (e) {
|
||||||
|
return await retry(APIException(APIException.OTHER, arguments: e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Response> _postForResponse(String url, requestBody, {String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers}) async {
|
||||||
|
var defaultHeaders = <String, String>{};
|
||||||
|
if (token != null) {
|
||||||
|
defaultHeaders['Authorization'] = 'Bearer $token';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (headers != null && headers.isNotEmpty) {
|
||||||
|
defaultHeaders.addAll(headers);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (queryParameters != null) {
|
||||||
|
var queryString = Uri(queryParameters: queryParameters).query;
|
||||||
|
url = '$url?$queryString';
|
||||||
|
}
|
||||||
|
var response = await _post(Uri.parse(url), body: requestBody, headers: defaultHeaders).timeout(const Duration(seconds: 120));
|
||||||
|
|
||||||
|
if (response.statusCode >= 200 && response.statusCode < 300) {
|
||||||
|
return response;
|
||||||
|
} else {
|
||||||
|
throw _throwAPIException(response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Response> _putForResponse(String url, requestBody, {String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers}) async {
|
||||||
|
var defaultHeaders = <String, String>{};
|
||||||
|
if (token != null) {
|
||||||
|
defaultHeaders['Authorization'] = 'Bearer $token';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (headers != null && headers.isNotEmpty) {
|
||||||
|
defaultHeaders.addAll(headers);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (queryParameters != null) {
|
||||||
|
var queryString = Uri(queryParameters: queryParameters).query;
|
||||||
|
url = '$url?$queryString';
|
||||||
|
}
|
||||||
|
var response = await _put(Uri.parse(url), body: requestBody, headers: defaultHeaders).timeout(const Duration(seconds: 120));
|
||||||
|
|
||||||
|
if (response.statusCode >= 200 && response.statusCode < 300) {
|
||||||
|
return response;
|
||||||
|
} else {
|
||||||
|
throw _throwAPIException(response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Response> _deleteForResponse(String url, {String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers}) async {
|
||||||
|
var defaultHeaders = <String, String>{};
|
||||||
|
if (token != null) {
|
||||||
|
defaultHeaders['Authorization'] = 'Bearer $token';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (headers != null && headers.isNotEmpty) {
|
||||||
|
defaultHeaders.addAll(headers);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (queryParameters != null) {
|
||||||
|
var queryString = Uri(queryParameters: queryParameters).query;
|
||||||
|
url = '$url?$queryString';
|
||||||
|
}
|
||||||
|
var response = await _delete(Uri.parse(url), headers: defaultHeaders).timeout(const Duration(seconds: 60));
|
||||||
|
|
||||||
|
if (response.statusCode >= 200 && response.statusCode < 300) {
|
||||||
|
return response;
|
||||||
|
} else {
|
||||||
|
throw _throwAPIException(response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Response> getJsonForResponse<T>(String url, {String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0}) async {
|
||||||
|
int currentRetryTime = retryTimes;
|
||||||
|
if (headers == null) {
|
||||||
|
headers = {'Content-Type': 'application/json'};
|
||||||
|
} else {
|
||||||
|
headers['Content-Type'] = 'application/json';
|
||||||
|
}
|
||||||
|
Future<Response> retry(APIException exception) async {
|
||||||
|
if (currentRetryTime > 0) {
|
||||||
|
currentRetryTime -= 1;
|
||||||
|
debugPrint('will retry after 3 seconds...');
|
||||||
|
await Future.delayed(const Duration(seconds: 3));
|
||||||
|
return await _getForResponse(url, token: token, queryParameters: queryParameters, headers: headers);
|
||||||
|
} else {
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return await _getForResponse(url, token: token, queryParameters: queryParameters, headers: headers);
|
||||||
|
} on SocketException catch (e) {
|
||||||
|
return await retry(APIException(APIException.OTHER, arguments: e));
|
||||||
|
} on HttpException catch (e) {
|
||||||
|
return await retry(APIException(APIException.OTHER, arguments: e));
|
||||||
|
} on TimeoutException catch (e) {
|
||||||
|
throw APIException(APIException.TIMEOUT, arguments: e);
|
||||||
|
} on ClientException catch (e) {
|
||||||
|
return await retry(APIException(APIException.OTHER, arguments: e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Response> deleteJsonForResponse<T>(String url, {String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0}) async {
|
||||||
|
int currentRetryTime = retryTimes;
|
||||||
|
if (headers == null) {
|
||||||
|
headers = {'Content-Type': 'application/json'};
|
||||||
|
} else {
|
||||||
|
headers['Content-Type'] = 'application/json';
|
||||||
|
}
|
||||||
|
Future<Response> retry(APIException exception) async {
|
||||||
|
if (currentRetryTime > 0) {
|
||||||
|
currentRetryTime -= 1;
|
||||||
|
debugPrint('will retry after 3 seconds...');
|
||||||
|
await Future.delayed(const Duration(seconds: 3));
|
||||||
|
return await _deleteForResponse(url, token: token, queryParameters: queryParameters, headers: headers);
|
||||||
|
} else {
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return await _deleteForResponse(url, token: token, queryParameters: queryParameters, headers: headers);
|
||||||
|
} on SocketException catch (e) {
|
||||||
|
return await retry(APIException(APIException.OTHER, arguments: e));
|
||||||
|
} on HttpException catch (e) {
|
||||||
|
return await retry(APIException(APIException.OTHER, arguments: e));
|
||||||
|
} on TimeoutException catch (e) {
|
||||||
|
throw APIException(APIException.TIMEOUT, arguments: e);
|
||||||
|
} on ClientException catch (e) {
|
||||||
|
return await retry(APIException(APIException.OTHER, arguments: e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Response> _getForResponse(String url, {String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers}) async {
|
||||||
|
var defaultHeaders = <String, String>{};
|
||||||
|
if (token != null) {
|
||||||
|
defaultHeaders['Authorization'] = 'Bearer $token';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (headers != null && headers.isNotEmpty) {
|
||||||
|
defaultHeaders.addAll(headers);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (queryParameters != null) {
|
||||||
|
var queryString = Uri(queryParameters: queryParameters).query;
|
||||||
|
url = '$url?$queryString';
|
||||||
|
}
|
||||||
|
var response = await _get(Uri.parse(url), headers: defaultHeaders).timeout(const Duration(seconds: 60));
|
||||||
|
|
||||||
|
if (response.statusCode >= 200 && response.statusCode < 300) {
|
||||||
|
return response;
|
||||||
|
} else {
|
||||||
|
throw _throwAPIException(response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Response> _get(url, {Map<String, String>? headers}) => _withClient((client) => client.get(url, headers: headers));
|
||||||
|
|
||||||
|
bool _certificateCheck(X509Certificate cert, String host, int port) => true;
|
||||||
|
|
||||||
|
Future<T> _withClient<T>(Future<T> Function(Client) fn) async {
|
||||||
|
var httpClient = HttpClient()..badCertificateCallback = _certificateCheck;
|
||||||
|
var client = IOClient(httpClient);
|
||||||
|
try {
|
||||||
|
return await fn(client);
|
||||||
|
} finally {
|
||||||
|
client.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Response> _post(url, {Map<String, String>? headers, body, Encoding? encoding}) => _withClient((client) => client.post(url, headers: headers, body: body, encoding: encoding));
|
||||||
|
|
||||||
|
Future<Response> _put(url, {Map<String, String>? headers, body, Encoding? encoding}) => _withClient((client) => client.put(url, headers: headers, body: body, encoding: encoding));
|
||||||
|
|
||||||
|
Future<Response> _delete(url, {Map<String, String>? headers}) => _withClient((client) => client.delete(url, headers: headers));
|
||||||
|
}
|
||||||
@ -0,0 +1,27 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:http/http.dart';
|
||||||
|
import 'package:test_sa/api/api_client.dart';
|
||||||
|
import 'package:test_sa/controllers/api_routes/urls.dart';
|
||||||
|
|
||||||
|
import '../models/department.dart';
|
||||||
|
|
||||||
|
class DepartmentsApiClient{
|
||||||
|
|
||||||
|
static final DepartmentsApiClient _instance = DepartmentsApiClient._internal();
|
||||||
|
|
||||||
|
DepartmentsApiClient._internal();
|
||||||
|
|
||||||
|
factory DepartmentsApiClient() => _instance;
|
||||||
|
|
||||||
|
Future getDepartment() async {
|
||||||
|
Response response;
|
||||||
|
response = await ApiClient().postJsonForResponse(
|
||||||
|
URLs.host1 + URLs.getDepartments,
|
||||||
|
{},
|
||||||
|
isFormData: false
|
||||||
|
);
|
||||||
|
Map listJson = json.decode(utf8.decode(response.bodyBytes).replaceAll("\\", ""));
|
||||||
|
return listJson['data'].map<Department>((department) => Department.fromJson(department)).toList();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,71 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:test_sa/api/api_client.dart';
|
||||||
|
import 'package:test_sa/api/user_api_client.dart';
|
||||||
|
|
||||||
|
import '../controllers/api_routes/urls.dart';
|
||||||
|
import '../models/device/device_transfer.dart';
|
||||||
|
import '../models/device/device_transfer_info.dart';
|
||||||
|
|
||||||
|
class DeviceTransferApiClient {
|
||||||
|
static final DeviceTransferApiClient _instance = DeviceTransferApiClient._internal();
|
||||||
|
|
||||||
|
DeviceTransferApiClient._internal();
|
||||||
|
|
||||||
|
factory DeviceTransferApiClient() => _instance;
|
||||||
|
|
||||||
|
Future<List<DeviceTransfer>> getRequests({required List items, required int pageItemNumber}) async {
|
||||||
|
Map<String, dynamic> body= {
|
||||||
|
"pageSize": "${(items.length) ~/ pageItemNumber}",
|
||||||
|
};
|
||||||
|
|
||||||
|
final response = await ApiClient().postJsonForResponse(
|
||||||
|
"${URLs.host1}${URLs.getDeviceTransfer}",
|
||||||
|
body,
|
||||||
|
isFormData: false
|
||||||
|
);
|
||||||
|
|
||||||
|
Map listJson = json.decode(utf8.decode(response.bodyBytes).replaceAll("\\", ""));
|
||||||
|
print(listJson);
|
||||||
|
return listJson['data'].map<DeviceTransfer>((request) => DeviceTransfer.fromJson(request)).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<DeviceTransfer> createRequest({
|
||||||
|
required DeviceTransfer model,
|
||||||
|
}) async {
|
||||||
|
Map<String, dynamic> body = {
|
||||||
|
"id": model.id??0,
|
||||||
|
"assetId": model.device?.id,
|
||||||
|
"destSiteId":model.receiver?.client?.id,
|
||||||
|
"senderSiteId":model.sender?.userId,
|
||||||
|
"receiverAssignedEmployeeId": model.receiver?.userId
|
||||||
|
};
|
||||||
|
|
||||||
|
print(body);
|
||||||
|
|
||||||
|
final response = await ApiClient().postJsonForResponse("${URLs.host1}${URLs.requestDeviceTransfer}", body, isFormData: false);
|
||||||
|
|
||||||
|
return DeviceTransfer.fromJson(json.decode(utf8.decode(response.bodyBytes))[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<DeviceTransfer> updateRequest({
|
||||||
|
required bool isSender,
|
||||||
|
required String requestId,
|
||||||
|
required DeviceTransfer oldModel,
|
||||||
|
required DeviceTransferInfo newModel,
|
||||||
|
}) async {
|
||||||
|
Map<String, dynamic> body = {
|
||||||
|
"id": oldModel.id??0,
|
||||||
|
"assetId": oldModel.device?.id,
|
||||||
|
"destSiteId":oldModel.receiver?.client?.id,
|
||||||
|
"senderSiteId":oldModel.sender?.userId,
|
||||||
|
"receiverAssignedEmployeeId": oldModel.receiver?.userId
|
||||||
|
};
|
||||||
|
|
||||||
|
body.addAll(newModel.toJson(isSender));
|
||||||
|
|
||||||
|
final response = await ApiClient().putJsonForResponse("${URLs.host1}${URLs.updateDeviceTransfer}", body);
|
||||||
|
|
||||||
|
return DeviceTransfer.fromJson(json.decode(utf8.decode(response.bodyBytes))[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,62 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:test_sa/models/device/device.dart';
|
||||||
|
|
||||||
|
import '../controllers/api_routes/urls.dart';
|
||||||
|
import 'api_client.dart';
|
||||||
|
|
||||||
|
class DevicesApiClient {
|
||||||
|
static final DevicesApiClient _instance = DevicesApiClient._internal();
|
||||||
|
final List<Device> devices = [];
|
||||||
|
|
||||||
|
DevicesApiClient._internal();
|
||||||
|
|
||||||
|
factory DevicesApiClient() => _instance;
|
||||||
|
|
||||||
|
/// Fetch devices by [hospitalId] and insert the result into [devices] list
|
||||||
|
Future getEquipment(String hospitalId) async {
|
||||||
|
|
||||||
|
|
||||||
|
final response = await ApiClient().postJsonForResponse(
|
||||||
|
URLs.host1 + URLs.getEquipment,
|
||||||
|
{'client': hospitalId},
|
||||||
|
isFormData: false
|
||||||
|
);
|
||||||
|
|
||||||
|
Map equipmentListJson = json.decode(utf8.decode(response.bodyBytes));
|
||||||
|
print(equipmentListJson);
|
||||||
|
devices.clear();
|
||||||
|
devices.addAll(equipmentListJson['data'] != null ? equipmentListJson['data'].map<Device>((device) => Device.fromJson(device)).toList(): []);
|
||||||
|
debugPrint("devices : ${devices.length}");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns a list of devices by [hospitalId] and [serialNumber] (or | and) [number]
|
||||||
|
Future<List<Device>> getDevicesList({required String hospitalId, String? serialNumber, String? number}) async {
|
||||||
|
final response = await ApiClient().postJsonForResponse(
|
||||||
|
URLs.host1 + URLs.getEquipment,
|
||||||
|
{
|
||||||
|
'client': hospitalId,
|
||||||
|
if (serialNumber?.isEmpty == false) 'name': serialNumber,
|
||||||
|
if (number?.isEmpty == false) 'number': number,
|
||||||
|
},
|
||||||
|
isFormData: false
|
||||||
|
);
|
||||||
|
List categoriesListJson = json.decode(utf8.decode(response.bodyBytes));
|
||||||
|
return categoriesListJson.map((device) => Device.fromJson(device)).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns a list of devices by [hospitalId] (and optionally) [serialNumber]
|
||||||
|
Future<List<Device>> getDevicesListBySN({required String hospitalId, required String serialNumber}) async {
|
||||||
|
final response = await ApiClient().postJsonForResponse(
|
||||||
|
URLs.host1 + URLs.getEquipment,
|
||||||
|
{
|
||||||
|
'client': hospitalId,
|
||||||
|
if (serialNumber.isNotEmpty) 'serial_qr': serialNumber,
|
||||||
|
},
|
||||||
|
isFormData: false
|
||||||
|
);
|
||||||
|
List categoriesListJson = json.decode(utf8.decode(response.bodyBytes));
|
||||||
|
return categoriesListJson.map((device) => Device.fromJson(device)).toList();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,149 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:http/http.dart';
|
||||||
|
import 'package:test_sa/api/user_api_client.dart';
|
||||||
|
|
||||||
|
import '../controllers/api_routes/urls.dart';
|
||||||
|
import '../models/gas_refill/gas_refill_model.dart';
|
||||||
|
import 'api_client.dart';
|
||||||
|
|
||||||
|
class GasRefillApiClient {
|
||||||
|
static final GasRefillApiClient _instance = GasRefillApiClient._internal();
|
||||||
|
|
||||||
|
GasRefillApiClient._internal();
|
||||||
|
|
||||||
|
factory GasRefillApiClient() => _instance;
|
||||||
|
|
||||||
|
// todo @majd there is a method postJsonForObject, use this, rather then postJsonForResponse
|
||||||
|
|
||||||
|
Future<List<GasRefillModel>> getRequestPages({required List items, required int pageItemNumber}) async {
|
||||||
|
|
||||||
|
Map<String, dynamic> body = {
|
||||||
|
"uid": "${UserApiClient().user?.id}",
|
||||||
|
"token": "${UserApiClient().user?.token}",
|
||||||
|
"pageSize": "${(items.length) ~/ pageItemNumber}",
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
final response = await ApiClient().postJsonForResponse(
|
||||||
|
"${URLs.host1}${URLs.getGasRefill}",
|
||||||
|
body,
|
||||||
|
isFormData: false,
|
||||||
|
);
|
||||||
|
|
||||||
|
// client's request was successfully received
|
||||||
|
var requestsListJson = json.decode(utf8.decode(response.bodyBytes));
|
||||||
|
print(requestsListJson);
|
||||||
|
return requestsListJson['data'].map<GasRefillModel>((request) => GasRefillModel.fromJson(request)).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<GasRefillModel> createModel({
|
||||||
|
required GasRefillModel model,
|
||||||
|
}) async {
|
||||||
|
|
||||||
|
|
||||||
|
Map<String, dynamic> body = {
|
||||||
|
"gazRefillNo": await generateGazRefillNo(),
|
||||||
|
"assignedEmployee": {
|
||||||
|
"id": UserApiClient().user?.id.toString(),
|
||||||
|
"name": UserApiClient().user?.username.toString()
|
||||||
|
},
|
||||||
|
"status": {
|
||||||
|
"id": 0,
|
||||||
|
"name": "",
|
||||||
|
"value": 0
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
body["gazRefillDetails"] = model.details
|
||||||
|
?.map((model) => {
|
||||||
|
"gasType": {
|
||||||
|
"id": model.type?.id,
|
||||||
|
"name": model.type?.label.toString(),
|
||||||
|
"value": model.type?.id
|
||||||
|
},
|
||||||
|
"cylinderType": {
|
||||||
|
"id": 0,
|
||||||
|
"name": "",
|
||||||
|
"value": 0
|
||||||
|
},
|
||||||
|
"cylinderSize": {
|
||||||
|
"id": model.cylinderSize?.id,
|
||||||
|
"name": model.cylinderSize?.label.toString(),
|
||||||
|
"value": model.cylinderSize?.id,
|
||||||
|
},
|
||||||
|
"requestedQty": model.requestedQuantity,
|
||||||
|
"deliverdQty": 0
|
||||||
|
|
||||||
|
})
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
print(body);
|
||||||
|
|
||||||
|
final response = await ApiClient().postJsonForResponse(
|
||||||
|
"${URLs.host1}${URLs.requestGasRefill}",
|
||||||
|
body,
|
||||||
|
isFormData: false
|
||||||
|
);
|
||||||
|
|
||||||
|
return GasRefillModel.fromJson(json.decode(utf8.decode(response.bodyBytes))[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future updateModel({
|
||||||
|
required GasRefillModel? oldModel,
|
||||||
|
required GasRefillModel newModel,
|
||||||
|
}) async {
|
||||||
|
|
||||||
|
Map<String, dynamic> body = {
|
||||||
|
"id": oldModel?.id,
|
||||||
|
"gazRefillNo": await generateGazRefillNo(),
|
||||||
|
"assignedEmployee": {
|
||||||
|
"id": UserApiClient().user?.id.toString(),
|
||||||
|
"name": UserApiClient().user?.username.toString()
|
||||||
|
},
|
||||||
|
"status": {
|
||||||
|
"id": 0,
|
||||||
|
"name": "",
|
||||||
|
"value": 0
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
body["gazRefillDetails"] = newModel.details
|
||||||
|
?.map((model) => {
|
||||||
|
"gasType": {
|
||||||
|
"id": model.type?.id,
|
||||||
|
"name": model.type?.label.toString(),
|
||||||
|
"value": model.type?.id
|
||||||
|
},
|
||||||
|
"cylinderType": {
|
||||||
|
"id": 0,
|
||||||
|
"name": "",
|
||||||
|
"value": 0
|
||||||
|
},
|
||||||
|
"cylinderSize": {
|
||||||
|
"id": model.cylinderSize?.id,
|
||||||
|
"name": model.cylinderSize?.label.toString(),
|
||||||
|
"value": model.cylinderSize?.id,
|
||||||
|
},
|
||||||
|
"requestedQty": model.requestedQuantity,
|
||||||
|
"deliverdQty": 0
|
||||||
|
|
||||||
|
})
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
final reponse = await ApiClient().putJsonForResponse("${URLs.host1}${URLs.updateGasRefill}/${newModel.id}", body);
|
||||||
|
|
||||||
|
oldModel?.fromGasRefillModel(newModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Future<String> generateGazRefillNo() async {
|
||||||
|
|
||||||
|
final reponse = await ApiClient().getJsonForResponse("${URLs.host1}${URLs.generateGazRefillNo}");
|
||||||
|
var data = json.decode(reponse.body);
|
||||||
|
return data['data'];
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:http/http.dart';
|
||||||
|
import 'package:test_sa/api/api_client.dart';
|
||||||
|
import 'package:test_sa/controllers/api_routes/urls.dart';
|
||||||
|
|
||||||
|
import '../models/lookup.dart';
|
||||||
|
|
||||||
|
class GasTypesApiClient{
|
||||||
|
|
||||||
|
static final GasTypesApiClient _instance = GasTypesApiClient._internal();
|
||||||
|
|
||||||
|
GasTypesApiClient._internal();
|
||||||
|
|
||||||
|
factory GasTypesApiClient() => _instance;
|
||||||
|
|
||||||
|
Future <List<Lookup>> getData() async {
|
||||||
|
Response response;
|
||||||
|
response = await ApiClient().getJsonForResponse("${URLs.host1}${URLs.getGasTypes}");
|
||||||
|
Map categoriesListJson = json.decode(utf8.decode(response.bodyBytes));
|
||||||
|
return categoriesListJson["data"].map<Lookup>((item) => Lookup.fromJson(item)).toList();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:http/http.dart';
|
||||||
|
|
||||||
|
import '../controllers/api_routes/urls.dart';
|
||||||
|
import '../models/lookup.dart';
|
||||||
|
import 'api_client.dart';
|
||||||
|
|
||||||
|
class GazCylinderSizeApiClient{
|
||||||
|
|
||||||
|
static final GazCylinderSizeApiClient _instance = GazCylinderSizeApiClient._internal();
|
||||||
|
|
||||||
|
GazCylinderSizeApiClient._internal();
|
||||||
|
|
||||||
|
factory GazCylinderSizeApiClient() => _instance;
|
||||||
|
|
||||||
|
Future getData() async {
|
||||||
|
Response response= await ApiClient().getJsonForResponse("${URLs.host1}${URLs.getGasCylinderSize}");
|
||||||
|
var categoriesListJson = json.decode(response.body);
|
||||||
|
return categoriesListJson['data'].map<Lookup>((item) => Lookup.fromJson(item)).toList();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,53 @@
|
|||||||
|
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:http/http.dart';
|
||||||
|
import 'package:test_sa/controllers/api_routes/urls.dart';
|
||||||
|
|
||||||
|
import '../models/hospital.dart';
|
||||||
|
import 'api_client.dart';
|
||||||
|
|
||||||
|
class HospitalsApiClient{
|
||||||
|
|
||||||
|
static final HospitalsApiClient _instance = HospitalsApiClient._internal();
|
||||||
|
|
||||||
|
HospitalsApiClient._internal();
|
||||||
|
|
||||||
|
factory HospitalsApiClient() => _instance;
|
||||||
|
|
||||||
|
Future getHospitals({
|
||||||
|
required String title,
|
||||||
|
required int pageSize
|
||||||
|
}) async {
|
||||||
|
|
||||||
|
Response response = await ApiClient().postJsonForResponse(
|
||||||
|
URLs.host1 + URLs.getHospitals,
|
||||||
|
{
|
||||||
|
"pageSize": pageSize.toString(),
|
||||||
|
"name": title,
|
||||||
|
},
|
||||||
|
isFormData: false
|
||||||
|
);
|
||||||
|
|
||||||
|
Map categoriesListJson = json.decode(utf8.decode(response.bodyBytes));
|
||||||
|
print(categoriesListJson);
|
||||||
|
return categoriesListJson['data'].map<Hospital>((category) => Hospital.fromJson(category)).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Future<List<Hospital>> getHospitalsList({
|
||||||
|
required String title,
|
||||||
|
}) async {
|
||||||
|
Response response;
|
||||||
|
response = await ApiClient().postJsonForResponse(
|
||||||
|
URLs.host1 + URLs.getHospitals,
|
||||||
|
{"name" : title},
|
||||||
|
isFormData: false
|
||||||
|
);
|
||||||
|
|
||||||
|
List<Hospital> page = [];
|
||||||
|
Map categoriesListJson = json.decode(utf8.decode(response.bodyBytes));
|
||||||
|
page = categoriesListJson['data'].map<Hospital>((category) => Hospital.fromJson(category)).toList();
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,56 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:test_sa/api/api_client.dart';
|
||||||
|
import 'package:test_sa/api/user_api_client.dart';
|
||||||
|
import 'package:test_sa/controllers/api_routes/urls.dart';
|
||||||
|
import 'package:test_sa/models/visits/visits_group.dart';
|
||||||
|
import 'package:test_sa/models/visits/visits_search.dart';
|
||||||
|
|
||||||
|
import '../models/visits/visit.dart';
|
||||||
|
|
||||||
|
class PreventiveMaintenanceApiClient {
|
||||||
|
static final PreventiveMaintenanceApiClient _instance = PreventiveMaintenanceApiClient._internal();
|
||||||
|
|
||||||
|
/// ## list of user requests
|
||||||
|
final List<Visit> visits = [];
|
||||||
|
|
||||||
|
PreventiveMaintenanceApiClient._internal();
|
||||||
|
|
||||||
|
factory PreventiveMaintenanceApiClient() => _instance;
|
||||||
|
|
||||||
|
Future getVisits({required int pageItemNumber, VisitsSearch? visitsSearch}) async {
|
||||||
|
print('get visits');
|
||||||
|
final response = await ApiClient().getJsonForResponse(
|
||||||
|
'${URLs.host1}${URLs.getPreventiveMaintenanceVisits}',
|
||||||
|
headers: {"Content-Type": "application/json; charset=utf-8"},
|
||||||
|
queryParameters: {
|
||||||
|
'uid': UserApiClient().user?.id,
|
||||||
|
'token': UserApiClient().user?.token,
|
||||||
|
'page': '${(visits.length) ~/ pageItemNumber}',
|
||||||
|
if (visitsSearch != null) ...visitsSearch.queryParameters(),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
List requestsListJson = json.decode(utf8.decode(response.bodyBytes).replaceAll("\\", ""));
|
||||||
|
List<Visit> visitsList = requestsListJson.map((request) => Visit.fromJson(request)).toList();
|
||||||
|
visits.addAll(visitsList);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future updateGroupOfVisits({required VisitsGroup group}) async {
|
||||||
|
print('update group of visits');
|
||||||
|
final user = UserApiClient().user;
|
||||||
|
Map<String, String> body = group.toJson();
|
||||||
|
body["token"] = user?.token ?? "";
|
||||||
|
body["uid"] = user?.id ?? "";
|
||||||
|
//userId = 397.toString(); // testing id to view data
|
||||||
|
await ApiClient().postJsonForResponse(
|
||||||
|
'${URLs.host1}${URLs.updatePreventiveMaintenanceVisits}',
|
||||||
|
body,
|
||||||
|
);
|
||||||
|
// client's request was successfully received
|
||||||
|
for (var visit in (group.visits ?? [])) {
|
||||||
|
visit.status = group.status;
|
||||||
|
visit.actualDate = group.date.toString().split(" ").first;
|
||||||
|
}
|
||||||
|
group.visits?.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,250 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:test_sa/api/api_client.dart';
|
||||||
|
import 'package:test_sa/api/user_api_client.dart';
|
||||||
|
import 'package:test_sa/models/issue.dart';
|
||||||
|
import 'package:test_sa/models/lookup.dart';
|
||||||
|
import 'package:test_sa/models/service_report.dart';
|
||||||
|
import 'package:test_sa/models/service_request/service_request.dart';
|
||||||
|
import 'package:test_sa/models/service_request/service_request_search.dart';
|
||||||
|
import 'package:test_sa/models/timer_model.dart';
|
||||||
|
|
||||||
|
import '../controllers/api_routes/urls.dart';
|
||||||
|
|
||||||
|
class ServiceRequestApiClient {
|
||||||
|
static final ServiceRequestApiClient _instance = ServiceRequestApiClient._internal();
|
||||||
|
final List<ServiceRequest> serviceRequests = [];
|
||||||
|
|
||||||
|
ServiceRequestApiClient._internal();
|
||||||
|
|
||||||
|
factory ServiceRequestApiClient() => _instance;
|
||||||
|
|
||||||
|
// 111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
|
||||||
|
|
||||||
|
/// ### The result will be added to [serviceRequests]
|
||||||
|
Future createRequest(ServiceRequest serviceRequest) async {
|
||||||
|
print("create request");
|
||||||
|
final user = UserApiClient().user;
|
||||||
|
await ApiClient().postJsonForObject(
|
||||||
|
(json) {
|
||||||
|
// ServiceRequest.fromJson(json.decode(utf8.decode(response.bodyBytes))[0])
|
||||||
|
serviceRequests.insert(0, ServiceRequest.fromJson(json[0]));
|
||||||
|
},
|
||||||
|
'${URLs.host1}${URLs.createRequest}',
|
||||||
|
{
|
||||||
|
"callNo": serviceRequest.id,
|
||||||
|
"callCreatedBy": {"name": serviceRequest.engineerName},
|
||||||
|
"requestedDate": DateTime.now().millisecondsSinceEpoch.toString(),
|
||||||
|
"requestedTime": DateTime.now().millisecondsSinceEpoch.toString(),
|
||||||
|
"defectType": {"id": serviceRequest.defectType?.id, "name": serviceRequest.defectType?.label, "value": serviceRequest.defectType?.id},
|
||||||
|
// "assets": [0],
|
||||||
|
"assignedEmployee": {"id": user?.id.toString(), "name": user?.username},
|
||||||
|
"voiceNote": serviceRequest.audio,
|
||||||
|
// "callSiteContactPerson": [
|
||||||
|
// {"id": 0, "employeeCode": "string", "name": "string", "telephone": "string", "job": "string", "email": "string", "land": "string", "contactUserId": "string"}
|
||||||
|
// ],
|
||||||
|
"priority": {"id": serviceRequest.priority?.id, "name": serviceRequest.priority?.label, "value": serviceRequest.priority?.id},
|
||||||
|
// "requestedThrough": {"id": 0, "name": "string", "value": 0},
|
||||||
|
// "typeofRequest": {"id": 0, "name": "string", "value": 0},
|
||||||
|
// "callComments": "string",
|
||||||
|
// "noofFollowup": 0,
|
||||||
|
// "attachmentsCallRequest": [
|
||||||
|
// {"id": "", "name": ""}
|
||||||
|
// ],
|
||||||
|
"status": {"name": serviceRequest.statusLabel, "value": serviceRequest.statusValue},
|
||||||
|
// "callLastSituation": {"id": 0, "name": "string", "value": 0},
|
||||||
|
// "firstAction": {"id": 0, "name": "string", "value": 0},
|
||||||
|
// "loanAvailablity": {"id": 0, "name": "string", "value": 0},
|
||||||
|
// "comments": "string",
|
||||||
|
// "firstActionDate": "2023-04-17T10:39:59.599Z",
|
||||||
|
"visitDate": serviceRequest.visitDate,
|
||||||
|
// "callReview": {"id": 0, "name": "string", "value": serviceRequest.}
|
||||||
|
},
|
||||||
|
// {
|
||||||
|
// "uid": user?.id,
|
||||||
|
// "token": user?.token ?? "",
|
||||||
|
// "sn_id": serviceRequest.deviceId ?? "",
|
||||||
|
// "date": (DateTime.now().millisecondsSinceEpoch).toString(),
|
||||||
|
// "client": user?.hospital?.id ?? '',
|
||||||
|
// "complaint": serviceRequest.maintenanceIssue,
|
||||||
|
// "image": json.encode(serviceRequest.devicePhotos),
|
||||||
|
// "priority": (serviceRequest.priority?.id).toString(),
|
||||||
|
// "defect_types": (serviceRequest.defectType?.id).toString(),
|
||||||
|
// "audio": serviceRequest.audio,
|
||||||
|
// },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
|
||||||
|
|
||||||
|
/// Get Service Requests and Fill [serviceRequests]
|
||||||
|
Future<List<ServiceRequest>> getRequests({pageItemNumber, ServiceRequestSearch? search}) async {
|
||||||
|
print("get requests xx");
|
||||||
|
final user = UserApiClient().user;
|
||||||
|
print("user name : ${user?.username}");
|
||||||
|
print("user id : ${user?.id}");
|
||||||
|
final response = await ApiClient().postJsonForResponse(
|
||||||
|
'${URLs.host1}${URLs.getCallRequests}',
|
||||||
|
{
|
||||||
|
// "pageSize": (serviceRequests.length) ~/ pageItemNumber,
|
||||||
|
"pageNumber": pageItemNumber,
|
||||||
|
// "callId": "string",
|
||||||
|
// "requestedDateSymbol": {
|
||||||
|
// "id": 0,
|
||||||
|
// "name": "string",
|
||||||
|
// "value": 0
|
||||||
|
// },
|
||||||
|
// "requestedDateFrom": "2023-04-18T08:29:50.708Z",
|
||||||
|
// "requestedDateTo": "2023-04-18T08:29:50.708Z",
|
||||||
|
// "firstActionSymbol": {
|
||||||
|
// "id": 0,
|
||||||
|
// "name": "string",
|
||||||
|
// "value": 0
|
||||||
|
// },
|
||||||
|
// "firstActionFrom": "2023-04-18T08:29:50.708Z",
|
||||||
|
// "firstActionTo": "2023-04-18T08:29:50.708Z",
|
||||||
|
if (search?.hospital != null && (search?.hospital?.isNotEmpty ?? false)) "site": search?.hospital,
|
||||||
|
// "assetNo": "string",
|
||||||
|
if (search?.deviceSerialNumber != null && (search?.deviceSerialNumber?.isNotEmpty ?? false)) "assetSerialNumber": search?.deviceSerialNumber,
|
||||||
|
// "maintenanceSituation": {
|
||||||
|
// "id": 0,
|
||||||
|
// "name": "string",
|
||||||
|
// "value": 0
|
||||||
|
// },
|
||||||
|
// "status": {
|
||||||
|
// "id": 0,
|
||||||
|
// "name": "string",
|
||||||
|
// "value": 0
|
||||||
|
// },
|
||||||
|
"assignedEmployee": {
|
||||||
|
"id": user?.id,
|
||||||
|
"name": user?.username,
|
||||||
|
},
|
||||||
|
// "firstActionStatus": {
|
||||||
|
// "id": 0,
|
||||||
|
// "name": "string",
|
||||||
|
// "value": 0
|
||||||
|
// },
|
||||||
|
if (search?.deviceName != null && (search?.deviceName?.isNotEmpty ?? false)) "assetName": search?.deviceName,
|
||||||
|
// "manufacturer": "string",
|
||||||
|
if (search?.model != null && (search?.model?.isNotEmpty ?? false)) "modelDefinition": search?.model,
|
||||||
|
// "typeOfrequest": {
|
||||||
|
// "id": 0,
|
||||||
|
// "name": "string",
|
||||||
|
// "value": 0
|
||||||
|
// },
|
||||||
|
// "priority": {
|
||||||
|
// "id": 0,
|
||||||
|
// "name": "string",
|
||||||
|
// "value": 0
|
||||||
|
// }
|
||||||
|
},
|
||||||
|
// queryParameters: {
|
||||||
|
// // 'uid': user?.id,
|
||||||
|
// if (user?.hospital?.id != null) 'client_nid': user?.hospital?.id,
|
||||||
|
// 'token': user?.token,
|
||||||
|
// 'page': '${(serviceRequests.length) ~/ pageItemNumber}',
|
||||||
|
// // if (deviceSerialNumber != null && (deviceSerialNumber?.isNotEmpty ?? false)) 'sn_id': deviceSerialNumber,
|
||||||
|
// if (statusValue != null) 'status': statusValue?.toString(),
|
||||||
|
// // if (deviceName != null && (deviceName?.isNotEmpty ?? false)) 'equipment_en_name': deviceName,
|
||||||
|
// // if (hospital != null && (hospital?.isNotEmpty ?? false)) 'client': hospital,
|
||||||
|
// // if (model != null && (model?.isNotEmpty ?? false)) 'model': model,
|
||||||
|
// // if (search != null) ...search.queryParameters(),
|
||||||
|
// },
|
||||||
|
);
|
||||||
|
print(response.body);
|
||||||
|
List requestsListJson = json.decode(response.body)['data'];
|
||||||
|
List<ServiceRequest> serviceRequestsPage = requestsListJson.map((request) => ServiceRequest.fromJson(request)).toList();
|
||||||
|
serviceRequests.addAll(serviceRequestsPage);
|
||||||
|
return serviceRequestsPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<ServiceRequest> getServiceById(String? requestId) async {
|
||||||
|
print("get service by id");
|
||||||
|
final user = UserApiClient().user;
|
||||||
|
final response = await ApiClient().getJsonForResponse(
|
||||||
|
'${URLs.host1}${URLs.getSingleServiceRequest}',
|
||||||
|
queryParameters: {'call_nid': requestId, 'uid': user?.id, 'token': user?.token},
|
||||||
|
);
|
||||||
|
// If the call to the server was successful, parse the JSON.
|
||||||
|
List jsonList = json.decode(utf8.decode(response.bodyBytes));
|
||||||
|
List<ServiceRequest> requests = jsonList.map((i) => ServiceRequest.fromJson(i)).toList();
|
||||||
|
return requests[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
Future createIssueReport(Issue issue) async {
|
||||||
|
print("Create Issue Report");
|
||||||
|
final user = UserApiClient().user;
|
||||||
|
Map<String, String> body = issue.toMap();
|
||||||
|
body["uid"] = user?.id ?? "";
|
||||||
|
body["token"] = user?.token ?? "";
|
||||||
|
await ApiClient().postJsonForResponse('${URLs.host1}${URLs.createReport}', body);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future updateDate({String? newDate, Lookup? employee, ServiceRequest? request}) async {
|
||||||
|
print("Update Date");
|
||||||
|
final user = UserApiClient().user;
|
||||||
|
Map<String, String> body = {};
|
||||||
|
body["uid"] = user?.id ?? '';
|
||||||
|
body["token"] = user?.token ?? '';
|
||||||
|
body["nid"] = request?.id ?? '';
|
||||||
|
body["date"] = newDate ?? '';
|
||||||
|
body["ass_emp"] = employee?.id?.toString() ?? '';
|
||||||
|
await ApiClient().postJsonForResponse('${URLs.host1}${URLs.updateRequestDate}', body);
|
||||||
|
request?.engineerName = employee?.label.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future createServiceReport({required ServiceReport? report, required ServiceRequest? request}) async {
|
||||||
|
print("Create Service Report");
|
||||||
|
final user = UserApiClient().user;
|
||||||
|
Map<String, String>? body = report?.toMap();
|
||||||
|
body?["uid"] = user?.id ?? "";
|
||||||
|
body?["token"] = user?.token ?? "";
|
||||||
|
body?["job_id"] = request?.id ?? '';
|
||||||
|
await ApiClient().postJsonForResponse('${URLs.host1}${URLs.createServiceReport}', body);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future createDuplicatedReport({required ServiceRequest request}) async {
|
||||||
|
print("Create Duplicated Report");
|
||||||
|
final user = UserApiClient().user;
|
||||||
|
await ApiClient().getJsonForResponse(
|
||||||
|
'${URLs.host1}${URLs.createDuplicatedReport}',
|
||||||
|
queryParameters: {'nid': request.id, 'uid': user?.id, 'token': user?.token},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future updateServiceReport({required ServiceReport report, required ServiceRequest request}) async {
|
||||||
|
print("Update Service Report");
|
||||||
|
final user = UserApiClient().user;
|
||||||
|
Map<String, String> body = report.toMap();
|
||||||
|
body["uid"] = user?.id ?? "";
|
||||||
|
body["token"] = user?.token ?? "";
|
||||||
|
body["job_id"] = request.id ?? '';
|
||||||
|
body["report_id"] = request.reportID ?? '';
|
||||||
|
await ApiClient().postJsonForResponse('${URLs.host1}${URLs.updateServiceReport}', body);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future updateServiceReportTimer({required TimerModel timer, required ServiceRequest request}) async {
|
||||||
|
print("Update Service Report Timer");
|
||||||
|
final user = UserApiClient().user;
|
||||||
|
Map<String, String> body = {};
|
||||||
|
body["uid"] = user?.id ?? "";
|
||||||
|
body["token"] = user?.token ?? "";
|
||||||
|
body["job_id"] = request.id ?? '';
|
||||||
|
body["start_time"] = ((timer.startAt?.millisecondsSinceEpoch ?? 0) / 1000).toStringAsFixed(0);
|
||||||
|
body["end_time"] = ((timer.endAt?.millisecondsSinceEpoch ?? 0) / 1000).toStringAsFixed(0);
|
||||||
|
body["working_hours"] = ((timer.durationInSecond ?? 0) / 60 / 60).toStringAsFixed(5);
|
||||||
|
body["report_id"] = request.reportID ?? '';
|
||||||
|
await ApiClient().postJsonForResponse('${URLs.host1}${URLs.updateServiceReport}', body);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<ServiceReport> getSingleServiceReport({required String reportId}) async {
|
||||||
|
print("Get Single Service Report");
|
||||||
|
final user = UserApiClient().user;
|
||||||
|
final response = await ApiClient().getJsonForResponse(
|
||||||
|
'${URLs.host1}${URLs.getServiceReport}',
|
||||||
|
queryParameters: {'report_id': reportId, 'uid': user?.id, 'token': user?.token},
|
||||||
|
);
|
||||||
|
return ServiceReport.fromJson(json.decode(utf8.decode(response.bodyBytes)), reportId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,81 @@
|
|||||||
|
import 'package:test_sa/controllers/api_routes/urls.dart';
|
||||||
|
import 'package:test_sa/models/user.dart';
|
||||||
|
|
||||||
|
import 'api_client.dart';
|
||||||
|
|
||||||
|
class UserApiClient {
|
||||||
|
static final UserApiClient _instance = UserApiClient._internal();
|
||||||
|
|
||||||
|
/// ### This instance will be [NULL] until the login or registration process completed successfully by calling [login] or [register] functions
|
||||||
|
User? user;
|
||||||
|
|
||||||
|
UserApiClient._internal();
|
||||||
|
|
||||||
|
factory UserApiClient() => _instance;
|
||||||
|
|
||||||
|
/// - [user] object have to contains username & password
|
||||||
|
/// - If the request completed successfully the [UserApiClient.user] object inside [UserApiClient] class won't be null and will contains the data comes from the response.
|
||||||
|
/// - Returns exception of type [APIException] if any error happened.
|
||||||
|
///
|
||||||
|
///#### lib\client\user_api_client.dart
|
||||||
|
Future login({required User user}) async {
|
||||||
|
return await ApiClient().postJsonForObject(
|
||||||
|
(json) {
|
||||||
|
this.user = User.fromJson(json);
|
||||||
|
},
|
||||||
|
"${URLs.host1}${URLs.login}",
|
||||||
|
await user.toLoginJson(), //body
|
||||||
|
isFormData: false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// - [newUser] object have to contains the new user data [email, phone, ...]
|
||||||
|
/// - If the request completed successfully the [user] object inside [UserApiClient] class won't be null and will contains the data comes from the response.
|
||||||
|
/// - Returns exception of type [APIException] if any error happened.
|
||||||
|
///
|
||||||
|
///#### lib\client\user_api_client.dart
|
||||||
|
Future register({required User newUser}) async {
|
||||||
|
return await ApiClient().postJsonForObject(
|
||||||
|
(json) {
|
||||||
|
user = User.fromJson(json);
|
||||||
|
},
|
||||||
|
"${URLs.host1}${URLs.register}",
|
||||||
|
await newUser.toRegisterJson(), //body
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// [updatedUser] have to contains the new data for the current user
|
||||||
|
/// - If the request completed successfully the [user] object inside [UserApiClient] class won't be null and will contains the data comes from the response.
|
||||||
|
/// - Returns exception of type [APIException] if any error happened.
|
||||||
|
///
|
||||||
|
///#### lib\client\user_api_client.dart
|
||||||
|
Future updateProfile({required User updatedUser}) async {
|
||||||
|
return await ApiClient().postJsonForObject(
|
||||||
|
(json) {
|
||||||
|
user = User.fromJson(json);
|
||||||
|
},
|
||||||
|
"${URLs.host1}${URLs.updateProfile}",
|
||||||
|
updatedUser.toUpdateProfileJson(), //body
|
||||||
|
);
|
||||||
|
// Map<String, dynamic> jsonObject = {};
|
||||||
|
// jsonObject["uid"] = user.id;
|
||||||
|
// jsonObject["token"] = user.token;
|
||||||
|
// if (user.department?.id != user.department?.id) {
|
||||||
|
// jsonObject["department"] = user.department?.id;
|
||||||
|
// }
|
||||||
|
// if (user.whatsApp != user.whatsApp) {
|
||||||
|
// jsonObject["whatsapp"] = user.whatsApp;
|
||||||
|
// }
|
||||||
|
// if (user.phoneNumber != user.phoneNumber) {
|
||||||
|
// jsonObject["phone"] = user.phoneNumber;
|
||||||
|
// }
|
||||||
|
// final response = await ApiClient().postJsonForResponse(URLs.updateProfile, jsonObject);
|
||||||
|
//
|
||||||
|
// if (response.statusCode >= 200 && response.statusCode < 300) {
|
||||||
|
// // client's request was successfully received
|
||||||
|
// this.user = User.fromJson(jsonDecode(utf8.decode(response.bodyBytes))[0]);
|
||||||
|
// this.user?.hospital = user.hospital;
|
||||||
|
// this.user?.department = user.department;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,91 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:test_sa/api/api_client.dart';
|
||||||
|
import 'package:test_sa/api/user_api_client.dart';
|
||||||
|
import 'package:test_sa/controllers/api_routes/urls.dart';
|
||||||
|
import 'package:test_sa/models/pantry/pentry.dart';
|
||||||
|
import 'package:test_sa/models/visits/visits_group.dart';
|
||||||
|
import 'package:test_sa/models/visits/visits_search.dart';
|
||||||
|
|
||||||
|
import '../models/visits/visit.dart';
|
||||||
|
|
||||||
|
class VisitsApiClient {
|
||||||
|
static final VisitsApiClient _instance = VisitsApiClient._internal();
|
||||||
|
|
||||||
|
/// ## list of user requests
|
||||||
|
final List<Visit> visits = [];
|
||||||
|
|
||||||
|
VisitsApiClient._internal();
|
||||||
|
|
||||||
|
factory VisitsApiClient() => _instance;
|
||||||
|
// 333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333
|
||||||
|
Future getVisits({required int pageItemNumber, VisitsSearch? visitsSearch}) async {
|
||||||
|
print("get visits");
|
||||||
|
final response = await ApiClient().postJsonForResponse(
|
||||||
|
'${URLs.host1}${URLs.getRegularVisits}',
|
||||||
|
// headers: {"Content-Type": "application/json; charset=utf-8"},
|
||||||
|
{
|
||||||
|
// "pageSize": 0,
|
||||||
|
"pageNumber": pageItemNumber,
|
||||||
|
// "id": 0,
|
||||||
|
// "assetId": 0,
|
||||||
|
"modelId": visitsSearch?.model,
|
||||||
|
// "ppmId": 0,
|
||||||
|
// "ppmScheduleId": 0,
|
||||||
|
// "classification": 0,
|
||||||
|
// "visitStatusId": 0,
|
||||||
|
// "deviceStatusId": 0,
|
||||||
|
// "groupLeaderReviewId": 0,
|
||||||
|
// "assignedEmployeeId": "string",
|
||||||
|
"assignedToId": visitsSearch?.contactStatus,
|
||||||
|
"expectedDateFrom": visitsSearch?.expectedDateFrom,
|
||||||
|
"expectedDateTo": visitsSearch?.expectedDateTo,
|
||||||
|
"actualDateFrom": visitsSearch?.actualDateFrom,
|
||||||
|
"actualDateTo": visitsSearch?.actualDateTo,
|
||||||
|
// "siteId": 0,
|
||||||
|
// "jobSheetNo": "string",
|
||||||
|
// "typeOfServiceId": 0,
|
||||||
|
// "planNumber": 0
|
||||||
|
}
|
||||||
|
// queryParameters: {
|
||||||
|
// 'uid': UserApiClient().user?.id,
|
||||||
|
// 'token': UserApiClient().user?.token,
|
||||||
|
// 'page': '${(visits.length) ~/ pageItemNumber}',
|
||||||
|
// if (visitsSearch != null) ...visitsSearch.queryParameters(),
|
||||||
|
// },
|
||||||
|
);
|
||||||
|
// print(json.decode(utf8.decode(response.bodyBytes).replaceAll("\\", "")));
|
||||||
|
List requestsListJson = json.decode(response.body)['data'];
|
||||||
|
List<Visit> visitsList = requestsListJson.map((request) => Visit.fromJson(request)).toList();
|
||||||
|
visits.addAll(visitsList);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444
|
||||||
|
Future updateGroupOfVisits({required VisitsGroup group}) async {
|
||||||
|
final user = UserApiClient().user;
|
||||||
|
Map<String, dynamic> body = {};
|
||||||
|
// body["token"] = user?.token ?? "";
|
||||||
|
body['ids'] = [...(group.visits?.map((e) => e.id).toList() ?? [])];
|
||||||
|
body["assignedEmployeeId"] = user?.id ?? "";
|
||||||
|
//userId = 397.toString(); // testing id to view data
|
||||||
|
await ApiClient().putJsonForResponse('${URLs.host1}${URLs.updateRegularVisits}', body);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Pentry> getPentry(String id) async {
|
||||||
|
final response = await ApiClient().getJsonForResponse(
|
||||||
|
'${URLs.host1}${URLs.getPentry}/$id',
|
||||||
|
headers: {"Content-Type": "application/json; charset=utf-8"},
|
||||||
|
);
|
||||||
|
|
||||||
|
return Pentry.fromMap(json.decode(utf8.decode(response.bodyBytes)));
|
||||||
|
}
|
||||||
|
|
||||||
|
Future updatePentry({Pentry? pentry, Visit? visit}) async {
|
||||||
|
final user = UserApiClient().user;
|
||||||
|
Map<String, String>? body = pentry?.toMap();
|
||||||
|
body?["uid"] = user?.id ?? "";
|
||||||
|
body?["token"] = user?.token ?? "";
|
||||||
|
await ApiClient().postJsonForResponse('${URLs.host1}${URLs.updatePentry}/${visit?.id}', body);
|
||||||
|
// visit?.status = pentry?.ppmVisitStatus;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,40 +1,38 @@
|
|||||||
import 'package:test_sa/models/subtitle.dart';
|
import '../../models/subtitle.dart';
|
||||||
import 'package:meta/meta.dart';
|
|
||||||
|
|
||||||
class HttpStatusManger{
|
class HttpStatusManger {
|
||||||
static String getStatusMessage({
|
static String getStatusMessage({
|
||||||
@required int status,
|
required int? status,
|
||||||
@required Subtitle subtitle,
|
required Subtitle? subtitle,
|
||||||
String messageFor400,
|
String? messageFor400,
|
||||||
String messageFor200,
|
String? messageFor200,
|
||||||
}){
|
}) {
|
||||||
if(status == null)
|
if (status == null) {
|
||||||
// no status code - code error no need for subtitle
|
|
||||||
return "careful null status";
|
return "careful null status";
|
||||||
if(status == -1)
|
}
|
||||||
// client's request in process
|
if (status == -1) {
|
||||||
return subtitle.currentlyServiceNotAvailable;
|
return subtitle?.currentlyServiceNotAvailable ?? "";
|
||||||
if(status == -2){
|
}
|
||||||
|
if (status == -2) {
|
||||||
// client's request in process
|
// client's request in process
|
||||||
return subtitle.waitUntilYourRequestComplete;
|
return subtitle?.waitUntilYourRequestComplete ?? "";
|
||||||
}else if(status >= 200 && status < 300){
|
} else if (status >= 200 && status < 300) {
|
||||||
// client's request was successfully received
|
// client's request was successfully received
|
||||||
return messageFor200 ?? subtitle.requestCompleteSuccessfully;
|
return messageFor200 ?? subtitle?.requestCompleteSuccessfully ?? "";
|
||||||
} else if(status >= 400 && status < 500){
|
} else if (status >= 400 && status < 500) {
|
||||||
// client's request have error
|
// client's request have error
|
||||||
switch(status){
|
switch (status) {
|
||||||
case 400:
|
case 400:
|
||||||
return messageFor400 ?? subtitle.failedToCompleteRequest;
|
return messageFor400 ?? subtitle?.failedToCompleteRequest ?? "";
|
||||||
default:
|
default:
|
||||||
return subtitle.failedToCompleteRequest;
|
return subtitle?.failedToCompleteRequest ?? "";
|
||||||
}
|
}
|
||||||
} else if(status >= 500){
|
} else if (status >= 500) {
|
||||||
// server error
|
// server error
|
||||||
return subtitle.currentlyServiceNotAvailable;
|
return subtitle?.currentlyServiceNotAvailable ?? "";
|
||||||
} else {
|
} else {
|
||||||
// no error match so return default error
|
// no error match so return default error
|
||||||
return subtitle.failedToCompleteRequest;
|
return subtitle?.failedToCompleteRequest ?? "";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,142 +1,65 @@
|
|||||||
import 'dart:convert';
|
import 'package:test_sa/api/devices_api_client.dart';
|
||||||
|
import 'package:test_sa/controllers/providers/loading_notifier.dart';
|
||||||
|
|
||||||
import 'package:flutter/cupertino.dart';
|
import '../../../models/device/device.dart';
|
||||||
import 'package:http/http.dart';
|
|
||||||
import 'package:test_sa/controllers/api_routes/urls.dart';
|
|
||||||
import 'package:test_sa/models/device/device.dart';
|
|
||||||
import 'package:test_sa/models/user.dart';
|
|
||||||
|
|
||||||
class DevicesProvider extends ChangeNotifier{
|
class DevicesProvider extends LoadingNotifier {
|
||||||
|
final List<Device> _searchableList = [];
|
||||||
|
|
||||||
|
List<Device> get searchableList => _searchableList;
|
||||||
|
|
||||||
//reset provider data
|
//reset provider data
|
||||||
void reset(){
|
void reset() {
|
||||||
_devices = null;
|
DevicesApiClient().devices.clear();
|
||||||
_stateCode = null;
|
_stateCode = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// state code of current request to defied error message
|
// state code of current request to defied error message
|
||||||
// like 400 customer request failed
|
// like 400 customer request failed
|
||||||
// 500 service not available
|
// 500 service not available
|
||||||
int _stateCode;
|
int? _stateCode;
|
||||||
int get stateCode => _stateCode;
|
|
||||||
|
|
||||||
List<Device> _devices;
|
|
||||||
List<Device> get devices => _devices;
|
|
||||||
|
|
||||||
// when categories in-process _loading = true
|
int? get stateCode => _stateCode;
|
||||||
// done _loading = true
|
|
||||||
// failed _loading = false
|
|
||||||
bool _loading;
|
|
||||||
bool get isLoading => _loading;
|
|
||||||
set isLoading(bool isLoading){
|
|
||||||
_loading = isLoading;
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// return -2 if request in progress
|
/// - Fetching Devices From The Server and Inserting them into [DevicesApiClient.devices] List.
|
||||||
/// return -1 if error happen when sending request
|
/// - [_searchableList] will be filled after the request succeed.
|
||||||
/// return state code if request complete may be 200, 404 or 403
|
///
|
||||||
/// for more details check http state manager
|
/// ### NOTE : if [hospitalId] is [NULL] nothing will happen
|
||||||
/// lib\controllers\http_status_manger\http_status_manger.dart
|
Future getEquipment() async {
|
||||||
Future<int> getEquipment ({
|
final hospitalId = /*UserApiClient().user?.hospital?.id ??*/ '';
|
||||||
@required String host,
|
if (hospitalId != null) {
|
||||||
@required User user,
|
_searchableList.clear();
|
||||||
@required String hospitalId
|
await waitApiRequest(
|
||||||
}) async {
|
() async {
|
||||||
if(_loading == true)
|
await DevicesApiClient().getEquipment(hospitalId);
|
||||||
return -2;
|
_searchableList.addAll(DevicesApiClient().devices);
|
||||||
_loading = true;
|
},
|
||||||
notifyListeners();
|
onSuccess: () {
|
||||||
Response response;
|
/// TODO : this is temporary
|
||||||
try{
|
_stateCode = 200;
|
||||||
response = await get(
|
},
|
||||||
Uri.parse(host + URLs.getEquipment+"?client=$hospitalId"),
|
onError: (error) {
|
||||||
headers: {
|
/// TODO : this is temporary
|
||||||
"Content-Type":"application/json; charset=utf-8"
|
_stateCode = error.error?.errorCode;
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
} catch(error) {
|
|
||||||
_loading = false;
|
|
||||||
_stateCode = -1;
|
|
||||||
notifyListeners();
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
_stateCode = response.statusCode;
|
|
||||||
if(response.statusCode >= 200 && response.statusCode < 300) {
|
|
||||||
// client's request was successfully received
|
|
||||||
List equipmentListJson = json.decode(utf8.decode(response.bodyBytes));
|
|
||||||
_devices = equipmentListJson.map((device) => Device.fromJson(device)).toList();
|
|
||||||
}
|
|
||||||
_loading = false;
|
|
||||||
notifyListeners();
|
|
||||||
return response.statusCode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// return -2 if request in progress
|
/// Returns a list of devices by [hospitalId] and [serialNumber] (or | and) [number]
|
||||||
/// return -1 if error happen when sending request
|
///
|
||||||
/// return state code if request complete may be 200, 404 or 403
|
/// ### NOTE : if [hospitalId] is [NULL] empty list will be returned
|
||||||
/// for more details check http state manager
|
Future<List<Device>> getDevicesList({required String? hospitalId, String? serialNumber, String? number}) {
|
||||||
/// lib\controllers\http_status_manger\http_status_manger.dart
|
if (hospitalId == null) return Future.value(const []);
|
||||||
Future<List<Device>> getDevicesList ({
|
return DevicesApiClient().getDevicesList(hospitalId: hospitalId, serialNumber: serialNumber, number: number);
|
||||||
@required String host,
|
|
||||||
@required User user,
|
|
||||||
@required String hospitalId,
|
|
||||||
String serialNumber,
|
|
||||||
String number,
|
|
||||||
}) async {
|
|
||||||
Response response;
|
|
||||||
try{
|
|
||||||
response = await get(
|
|
||||||
Uri.parse("$host${URLs.getEquipment}?client=$hospitalId"
|
|
||||||
"${serialNumber?.isEmpty == false ? "&name=$serialNumber" :""}"
|
|
||||||
"${number?.isEmpty == false ? "&number=$number" : ""}"
|
|
||||||
),
|
|
||||||
);
|
|
||||||
List<Device> page = [];
|
|
||||||
if(response.statusCode >= 200 && response.statusCode < 300) {
|
|
||||||
// client's request was successfully received
|
|
||||||
List categoriesListJson = json.decode(utf8.decode(response.bodyBytes));
|
|
||||||
page = categoriesListJson.map((device) => Device.fromJson(device)).toList();
|
|
||||||
}
|
|
||||||
return page;
|
|
||||||
} catch(error) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// return -2 if request in progress
|
/// Returns a list of devices by [hospitalId] (and optionally) [serialNumber]
|
||||||
/// return -1 if error happen when sending request
|
///
|
||||||
/// return state code if request complete may be 200, 404 or 403
|
/// ### NOTE : if [hospitalId] is [NULL] empty list will be returned
|
||||||
/// for more details check http state manager
|
Future<List<Device>> getDevicesListBySN({required String serialNumber}) {
|
||||||
/// lib\controllers\http_status_manger\http_status_manger.dart
|
final hospitalId = /*UserApiClient().user?.hospital?.id ??*/ "";
|
||||||
Future<List<Device>> getDevicesListBySN ({
|
if (hospitalId == null) return Future.value(const []);
|
||||||
@required String host,
|
return DevicesApiClient().getDevicesListBySN(hospitalId: hospitalId, serialNumber: serialNumber);
|
||||||
@required User user,
|
|
||||||
@required String hospitalId,
|
|
||||||
@required String sn
|
|
||||||
}) async {
|
|
||||||
Response response;
|
|
||||||
try{
|
|
||||||
response = await get(
|
|
||||||
Uri.parse(host + URLs.getEquipment+"?client=$hospitalId"
|
|
||||||
+ ( sn == null || sn.isEmpty ? "" : "&serial_qr=$sn" )),
|
|
||||||
);
|
|
||||||
|
|
||||||
_stateCode = response.statusCode;
|
|
||||||
List<Device> _page = [];
|
|
||||||
if(response.statusCode >= 200 && response.statusCode < 300) {
|
|
||||||
// client's request was successfully received
|
|
||||||
List categoriesListJson = json.decode(utf8.decode(response.bodyBytes));
|
|
||||||
_page = categoriesListJson.map((device) => Device.fromJson(device)).toList();
|
|
||||||
}
|
|
||||||
return _page;
|
|
||||||
} catch(error) {
|
|
||||||
_loading = false;
|
|
||||||
_stateCode = -1;
|
|
||||||
notifyListeners();
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,72 +1,44 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:test_sa/controllers/api_routes/urls.dart';
|
|
||||||
import 'package:test_sa/models/lookup.dart';
|
|
||||||
import 'package:test_sa/models/user.dart';
|
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:http/http.dart';
|
import 'package:http/http.dart';
|
||||||
|
|
||||||
class GasTypesProvider extends ChangeNotifier{
|
import '../../../../../api/gas_types_api_client.dart';
|
||||||
|
import '../../../../../models/lookup.dart';
|
||||||
|
import '../../../../../models/user.dart';
|
||||||
|
import '../../../../api_routes/urls.dart';
|
||||||
|
import '../../../loading_notifier.dart';
|
||||||
|
|
||||||
|
class GasTypesProvider extends LoadingNotifier {
|
||||||
//reset provider data
|
//reset provider data
|
||||||
void reset(){
|
void reset() {
|
||||||
_items = null;
|
_items?.clear();
|
||||||
_loading = null;
|
|
||||||
_stateCode = null;
|
_stateCode = null;
|
||||||
|
stopLoading();
|
||||||
}
|
}
|
||||||
|
|
||||||
// state code of current request to defied error message
|
// state code of current request to defied error message
|
||||||
// like 400 customer request failed
|
// like 400 customer request failed
|
||||||
// 500 service not available
|
// 500 service not available
|
||||||
int _stateCode;
|
int? _stateCode;
|
||||||
int get stateCode => _stateCode;
|
|
||||||
|
int? get stateCode => _stateCode;
|
||||||
|
|
||||||
// contain user data
|
// contain user data
|
||||||
// when user not login or register _user = null
|
// when user not login or register _user = null
|
||||||
List<Lookup> _items;
|
List<Lookup>? _items;
|
||||||
List<Lookup> get items => _items;
|
|
||||||
|
|
||||||
// when categories in-process _loading = true
|
List<Lookup>? get items => _items;
|
||||||
// done _loading = true
|
|
||||||
// failed _loading = false
|
|
||||||
bool _loading;
|
|
||||||
bool get isLoading => _loading;
|
|
||||||
set isLoading(bool isLoading){
|
|
||||||
_loading = isLoading;
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// return -2 if request in progress
|
Future getData() async {
|
||||||
/// return -1 if error happen when sending request
|
waitApiRequest(() async {
|
||||||
/// return state code if request complete may be 200, 404 or 403
|
_items = await GasTypesApiClient().getData();
|
||||||
/// for more details check http state manager
|
|
||||||
/// lib\controllers\http_status_manger\http_status_manger.dart
|
|
||||||
Future<int> getData ({String host,User user,}) async {
|
|
||||||
if(_loading == true) return -2;
|
|
||||||
_loading = true;
|
|
||||||
notifyListeners();
|
|
||||||
Response response;
|
|
||||||
try{
|
|
||||||
response = await get(
|
|
||||||
Uri.parse(host + URLs.getGasTypes),
|
|
||||||
);
|
|
||||||
_stateCode = response.statusCode;
|
|
||||||
if(response.statusCode >= 200 && response.statusCode < 300) {
|
|
||||||
// client's request was successfully received
|
|
||||||
List categoriesListJson = json.decode(utf8.decode(response.bodyBytes));
|
|
||||||
_items = categoriesListJson.map((item) => Lookup.fromJson(item)).toList();
|
|
||||||
}
|
|
||||||
_loading = false;
|
|
||||||
notifyListeners();
|
|
||||||
return response.statusCode;
|
|
||||||
} catch(error) {
|
|
||||||
_loading = false;
|
|
||||||
_stateCode = -1;
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
return -1;
|
},
|
||||||
}
|
onSuccess: () {
|
||||||
|
_stateCode = 200;
|
||||||
|
notifyListeners();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|||||||
@ -1,162 +0,0 @@
|
|||||||
import 'dart:convert';
|
|
||||||
|
|
||||||
import 'package:test_sa/controllers/api_routes/urls.dart';
|
|
||||||
import 'package:test_sa/models/user.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:http/http.dart';
|
|
||||||
|
|
||||||
class UserProvider extends ChangeNotifier{
|
|
||||||
|
|
||||||
//reset provider data
|
|
||||||
void reset(){
|
|
||||||
_user = null;
|
|
||||||
_loading = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// contain user data
|
|
||||||
// when user not login or register _user = null
|
|
||||||
User _user;
|
|
||||||
User get user => _user;
|
|
||||||
set user(User user) {
|
|
||||||
_user = user;
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// when login or register in-process _login = true
|
|
||||||
// when login or register is done or not start = false
|
|
||||||
bool _loading = false;
|
|
||||||
bool get isLoading => _loading;
|
|
||||||
set isLoading(bool isLoading) {
|
|
||||||
_loading = isLoading;
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// sign in with user - need (email or phone) and password;
|
|
||||||
/// return -2 if request in progress
|
|
||||||
/// return -1 if error happen when sending request
|
|
||||||
/// return state code if request complete may be 200, 404 or 403
|
|
||||||
/// for more details check http state manager
|
|
||||||
/// lib\controllers\http_status_manger\http_status_manger.dart
|
|
||||||
Future<int> login ({
|
|
||||||
@required String host,
|
|
||||||
@required User user,
|
|
||||||
}) async {
|
|
||||||
if(_loading == true)
|
|
||||||
return -2;
|
|
||||||
_loading = true;
|
|
||||||
notifyListeners();
|
|
||||||
Response response;
|
|
||||||
try{
|
|
||||||
response = await post(
|
|
||||||
Uri.parse(
|
|
||||||
host+URLs.login),
|
|
||||||
body: await user.toLoginJson(),
|
|
||||||
);
|
|
||||||
_loading = false;
|
|
||||||
if(response.statusCode >= 200 && response.statusCode < 300) {
|
|
||||||
// client's request was successfully received
|
|
||||||
_user = User.fromJson(jsonDecode(utf8.decode(response.bodyBytes))[0]);
|
|
||||||
|
|
||||||
|
|
||||||
return response.statusCode;
|
|
||||||
}
|
|
||||||
notifyListeners();
|
|
||||||
return response.statusCode;
|
|
||||||
} catch(error) {
|
|
||||||
_loading = false;
|
|
||||||
notifyListeners();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// sign up with User object;
|
|
||||||
/// return -2 if request in progress
|
|
||||||
/// return -1 if error happen when sending request
|
|
||||||
/// return state code if request complete may be 200, 404 or 403
|
|
||||||
/// for more details about state codes check http state manager
|
|
||||||
/// lib\controllers\http_status_manger\http_status_manger.dart
|
|
||||||
Future<int> register ({
|
|
||||||
@required String host,
|
|
||||||
@required User user,
|
|
||||||
}) async {
|
|
||||||
if(_loading == true)
|
|
||||||
return -2;
|
|
||||||
_loading = true;
|
|
||||||
notifyListeners();
|
|
||||||
Response response;
|
|
||||||
try{
|
|
||||||
response = await post(
|
|
||||||
Uri.parse(
|
|
||||||
host+URLs.register),
|
|
||||||
body: await user.toRegisterJson()
|
|
||||||
);
|
|
||||||
} catch(error) {
|
|
||||||
_loading = false;
|
|
||||||
notifyListeners();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
_loading = false;
|
|
||||||
notifyListeners();
|
|
||||||
if(response.statusCode >= 200 && response.statusCode < 300) {
|
|
||||||
// client's request was successfully received
|
|
||||||
_user = User.fromJson(jsonDecode(utf8.decode(response.bodyBytes))[0]);
|
|
||||||
_user.hospital = user.hospital;
|
|
||||||
notifyListeners();
|
|
||||||
return response.statusCode;
|
|
||||||
}
|
|
||||||
return response.statusCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// sign up with User object;
|
|
||||||
/// return -2 if request in progress
|
|
||||||
/// return -1 if error happen when sending request
|
|
||||||
/// return state code if request complete may be 200, 404 or 403
|
|
||||||
/// for more details about state codes check http state manager
|
|
||||||
/// lib\controllers\http_status_manger\http_status_manger.dart
|
|
||||||
Future<int> updateProfile ({
|
|
||||||
@required String host,
|
|
||||||
@required User user,
|
|
||||||
}) async {
|
|
||||||
if(_loading == true)
|
|
||||||
return -2;
|
|
||||||
_loading = true;
|
|
||||||
notifyListeners();
|
|
||||||
Response response;
|
|
||||||
|
|
||||||
Map<String,dynamic> jsonObject ={};
|
|
||||||
jsonObject["uid"] = user.id;
|
|
||||||
jsonObject["token"] = user.token;
|
|
||||||
if(user.department.id != _user.department.id)
|
|
||||||
jsonObject["department"] = user.department.id;
|
|
||||||
if(user.whatsApp != _user.whatsApp)
|
|
||||||
jsonObject["whatsapp"] = user.whatsApp;
|
|
||||||
if(user.phoneNumber != _user.phoneNumber)
|
|
||||||
jsonObject["phone"] = user.phoneNumber;
|
|
||||||
try{
|
|
||||||
response = await post(
|
|
||||||
Uri.parse(
|
|
||||||
host+URLs.updateProfile),
|
|
||||||
body: jsonObject
|
|
||||||
);
|
|
||||||
} catch(error) {
|
|
||||||
_loading = false;
|
|
||||||
notifyListeners();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
_loading = false;
|
|
||||||
notifyListeners();
|
|
||||||
|
|
||||||
if(response.statusCode >= 200 && response.statusCode < 300) {
|
|
||||||
// client's request was successfully received
|
|
||||||
_user = User.fromJson(jsonDecode(utf8.decode(response.bodyBytes))[0]);
|
|
||||||
_user.hospital = user.hospital;
|
|
||||||
_user.department = user.department;
|
|
||||||
notifyListeners();
|
|
||||||
return response.statusCode;
|
|
||||||
}
|
|
||||||
return response.statusCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -0,0 +1,45 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import '../../exceptions/api_exception.dart';
|
||||||
|
|
||||||
|
/// ## Change Notifier Class To Handle The State While Waiting The Futures Value
|
||||||
|
class LoadingNotifier with ChangeNotifier {
|
||||||
|
bool _loading = false;
|
||||||
|
|
||||||
|
/// - Returns [TRUE] if [waitApiRequest] function called
|
||||||
|
/// - Returns [FALSE] if [waitApiRequest] function completed in both states (failed, succeed)
|
||||||
|
bool get loading => _loading;
|
||||||
|
|
||||||
|
/// - [fun] : Callback function that contains the API request.
|
||||||
|
/// - [onError] : Optional callback function to handle the request on failure with [APIException] parameter.
|
||||||
|
/// - [onSuccess] : Optional callback function to handle the request on succeed.
|
||||||
|
Future waitApiRequest(Function fun, {Function(APIException)? onError, Function? onSuccess}) async {
|
||||||
|
if (_loading == true) {
|
||||||
|
debugPrint('loading_notifier.dart : another action already started');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_loading = true;
|
||||||
|
debugPrint('loading_notifier.dart : start loading');
|
||||||
|
notifyListeners();
|
||||||
|
try {
|
||||||
|
await fun();
|
||||||
|
if (onSuccess != null) {
|
||||||
|
await onSuccess();
|
||||||
|
}
|
||||||
|
} on APIException catch (error) {
|
||||||
|
debugPrint("loading_notifier.dart : [_waitResult] returns this message ${error.message} : ${error.arguments} ${error.error?.errorCode} ");
|
||||||
|
if (onError != null) {
|
||||||
|
await onError(error);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
stopLoading();
|
||||||
|
debugPrint('loading_notifier.dart : stop loading');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// ## Stop loading and Notify listeners
|
||||||
|
void stopLoading() {
|
||||||
|
_loading = false;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,103 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:fluttertoast/fluttertoast.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:test_sa/api/user_api_client.dart';
|
||||||
|
|
||||||
|
import '../../models/user.dart';
|
||||||
|
import '../../views/pages/user/land_page.dart';
|
||||||
|
import '../http_status_manger/http_status_manger.dart';
|
||||||
|
import '../localization/localization.dart';
|
||||||
|
import 'loading_notifier.dart';
|
||||||
|
import 'settings/setting_provider.dart';
|
||||||
|
|
||||||
|
class UserProvider extends LoadingNotifier {
|
||||||
|
/// - [UserApiClient.user] will be null
|
||||||
|
/// - loading process will stop
|
||||||
|
void reset() {
|
||||||
|
UserApiClient().user = null;
|
||||||
|
stopLoading();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// ## Login & Fill [UserApiClient.user] data
|
||||||
|
/// - onSuccess and user is Active : push to [LandPage]
|
||||||
|
/// - onSuccess and user isn't Active : toast message will appears
|
||||||
|
/// - onError : SnackBar will appears
|
||||||
|
Future login(BuildContext context, {required User user}) async {
|
||||||
|
final subtitle = AppLocalization.of(context)?.subtitle;
|
||||||
|
waitApiRequest(
|
||||||
|
() async {
|
||||||
|
await UserApiClient().login(user: user);
|
||||||
|
},
|
||||||
|
onSuccess: () {
|
||||||
|
if (context.mounted) {
|
||||||
|
Provider.of<SettingProvider>(context, listen: false).setUser(UserApiClient().user ?? User());
|
||||||
|
if (UserApiClient().user?.isAuthenticated ?? false) {
|
||||||
|
Navigator.of(context).pushNamed(LandPage.id);
|
||||||
|
} else {
|
||||||
|
Fluttertoast.showToast(msg: subtitle?.activationAlert ?? "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onError: (error) {
|
||||||
|
String errorMessage = error.error?.errorCode == 400 ? subtitle?.wrongEmailOrPassword ?? "" : HttpStatusManger.getStatusMessage(status: error.error?.errorCode, subtitle: subtitle);
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(errorMessage)));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// ## Register & Fill [UserApiClient.user] data
|
||||||
|
/// - onSuccess : toast message will appears
|
||||||
|
/// - onError : SnackBar will appears
|
||||||
|
Future register(BuildContext context, {required User newUser}) async {
|
||||||
|
final subtitle = AppLocalization.of(context)?.subtitle;
|
||||||
|
// if (newUser.hospital == null) {
|
||||||
|
// ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(subtitle?.hospitalRequired ?? "")));
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// if (newUser.department == null) {
|
||||||
|
// ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(subtitle?.unitRequired ?? "")));
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
waitApiRequest(
|
||||||
|
() async {
|
||||||
|
await UserApiClient().register(newUser: newUser);
|
||||||
|
},
|
||||||
|
onSuccess: () {
|
||||||
|
Fluttertoast.showToast(msg: subtitle?.activationAlert ?? "");
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
onError: (error) {
|
||||||
|
String? errorMessage = error.error?.errorCode == 402
|
||||||
|
? subtitle?.nameExist
|
||||||
|
: error.error?.errorCode == 401
|
||||||
|
? subtitle?.emailExist
|
||||||
|
: HttpStatusManger.getStatusMessage(status: error.error?.errorCode, subtitle: subtitle);
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(errorMessage ?? "")));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// ## Update current user profile
|
||||||
|
/// - onSuccess : SnackBar will appears
|
||||||
|
/// - onError : SnackBar will appears
|
||||||
|
Future updateProfile(BuildContext context, {required User updatedUser}) async {
|
||||||
|
final subtitle = AppLocalization.of(context)?.subtitle;
|
||||||
|
// if (updatedUser.department?.id == null) {
|
||||||
|
// ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(subtitle?.unitRequired ?? "")));
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
waitApiRequest(
|
||||||
|
() async {
|
||||||
|
await UserApiClient().updateProfile(updatedUser: updatedUser);
|
||||||
|
},
|
||||||
|
onSuccess: () {
|
||||||
|
Provider.of<SettingProvider>(context, listen: false).setUser(UserApiClient().user!);
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(subtitle?.requestCompleteSuccessfully ?? '')));
|
||||||
|
},
|
||||||
|
onError: (error) {
|
||||||
|
String errorMessage = HttpStatusManger.getStatusMessage(status: error.error?.errorCode, subtitle: subtitle);
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(errorMessage)));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import '../api/api_client.dart';
|
||||||
|
|
||||||
|
class APIException implements Exception {
|
||||||
|
static const String BAD_REQUEST = 'api_common_bad_request';
|
||||||
|
static const String UNAUTHORIZED = 'api_common_unauthorized';
|
||||||
|
static const String FORBIDDEN = 'api_common_forbidden';
|
||||||
|
static const String NOT_FOUND = 'api_common_not_found';
|
||||||
|
static const String INTERNAL_SERVER_ERROR = 'api_common_internal_server_error';
|
||||||
|
static const String UPGRADE_REQUIRED = 'api_common_upgrade_required';
|
||||||
|
static const String BAD_RESPONSE_FORMAT = 'api_common_bad_response_format';
|
||||||
|
static const String OTHER = 'api_common_http_error';
|
||||||
|
static const String TIMEOUT = 'api_common_http_timeout';
|
||||||
|
static const String UNKNOWN = 'unexpected_error';
|
||||||
|
|
||||||
|
final String message;
|
||||||
|
final APIError? error;
|
||||||
|
final arguments;
|
||||||
|
|
||||||
|
const APIException(this.message, {this.arguments, this.error});
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => {'message': message, 'error': error, 'arguments': '$arguments'};
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return jsonEncode(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,22 +1,22 @@
|
|||||||
class Department{
|
class Department {
|
||||||
String id;
|
int? id;
|
||||||
String name;
|
String? name;
|
||||||
|
|
||||||
Department({
|
Department({
|
||||||
this.id,
|
this.id,
|
||||||
this.name,
|
this.name,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory Department.fromJson(Map<String,dynamic> parsedJson){
|
factory Department.fromJson(Map<String, dynamic> parsedJson) {
|
||||||
return Department(
|
return Department(
|
||||||
id: parsedJson["nid"] ?? parsedJson["id"],
|
id: parsedJson["nid"] ?? parsedJson["id"],
|
||||||
name: parsedJson["dept_name"] ?? parsedJson["value"],
|
name: parsedJson["dept_name"] ?? parsedJson["value"],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
factory Department.fromDepartment(Department department){
|
factory Department.fromDepartment(Department? department) {
|
||||||
return Department(
|
return Department(
|
||||||
id: department?.id,
|
id: department?.id,
|
||||||
name: department?.name,
|
name: department?.name,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
enum UsersTypes{
|
enum UsersTypes {
|
||||||
engineer, // 0
|
engineer, // 0
|
||||||
normal_user, // 1
|
normal_user, // 1
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,23 +1,23 @@
|
|||||||
class Hospital{
|
class Hospital {
|
||||||
String id;
|
int? id;
|
||||||
String name;
|
String? name;
|
||||||
|
|
||||||
Hospital({
|
Hospital({
|
||||||
this.id,
|
this.id,
|
||||||
this.name,
|
this.name,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory Hospital.fromJson(Map<String,dynamic> parsedJson){
|
factory Hospital.fromJson(Map<String, dynamic> parsedJson) {
|
||||||
return Hospital(
|
return Hospital(
|
||||||
id: parsedJson["nid"] ?? parsedJson["id"],
|
id: parsedJson["id"],
|
||||||
name: parsedJson["client_name"] ?? parsedJson["value"],
|
name:parsedJson["custName"],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
factory Hospital.fromHospital(Hospital hospital){
|
factory Hospital.fromHospital(Hospital? hospital) {
|
||||||
return Hospital(
|
return Hospital(
|
||||||
id: hospital?.id,
|
id: hospital?.id,
|
||||||
name: hospital?.name,
|
name: hospital?.name,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,15 +1,12 @@
|
|||||||
import 'package:test_sa/models/lookup.dart';
|
import '../../lookup.dart';
|
||||||
|
|
||||||
class ContactTitle extends Lookup {
|
class ContactTitle extends Lookup {
|
||||||
ContactTitle({
|
ContactTitle({required int id, required String label}) : super(id: id, label: label);
|
||||||
int id,
|
|
||||||
String label
|
|
||||||
}):super(id: id,label: label);
|
|
||||||
|
|
||||||
factory ContactTitle.fromMap(Map<String,dynamic> parsedJson){
|
factory ContactTitle.fromMap(Map<String, dynamic> parsedJson) {
|
||||||
return ContactTitle(
|
return ContactTitle(
|
||||||
label: parsedJson["value"],
|
label: parsedJson["value"],
|
||||||
id: parsedJson["id"],
|
id: parsedJson["id"],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,15 +1,12 @@
|
|||||||
import 'package:test_sa/models/lookup.dart';
|
import '../../lookup.dart';
|
||||||
|
|
||||||
class ContactTitle extends Lookup {
|
class ContactTitle extends Lookup {
|
||||||
ContactTitle({
|
ContactTitle({required int id, required String label}) : super(id: id, label: label);
|
||||||
int id,
|
|
||||||
String label
|
|
||||||
}):super(id: id,label: label);
|
|
||||||
|
|
||||||
factory ContactTitle.fromMap(Map<String,dynamic> parsedJson){
|
factory ContactTitle.fromMap(Map<String, dynamic> parsedJson) {
|
||||||
return ContactTitle(
|
return ContactTitle(
|
||||||
label: parsedJson["value"],
|
label: parsedJson["value"],
|
||||||
id: parsedJson["id"],
|
id: parsedJson["id"],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,45 +1,37 @@
|
|||||||
import 'package:test_sa/models/lookup.dart';
|
import '../lookup.dart';
|
||||||
|
|
||||||
class PMKit{
|
class PMKit {
|
||||||
Lookup itemCode;
|
Lookup? itemCode;
|
||||||
String itemName;
|
String? itemName;
|
||||||
String preparationTimeFrame;
|
String? preparationTimeFrame;
|
||||||
String kitFrequencyDemand;
|
String? kitFrequencyDemand;
|
||||||
String availability;
|
String? availability;
|
||||||
String quantityNeeded;
|
String? quantityNeeded;
|
||||||
String quantityReserved;
|
String? quantityReserved;
|
||||||
|
|
||||||
PMKit({
|
PMKit({this.itemCode, this.itemName, this.preparationTimeFrame, this.kitFrequencyDemand, this.availability, this.quantityNeeded, this.quantityReserved});
|
||||||
this.itemCode,
|
|
||||||
this.itemName,
|
|
||||||
this.preparationTimeFrame,
|
|
||||||
this.kitFrequencyDemand,
|
|
||||||
this.availability,
|
|
||||||
this.quantityNeeded,
|
|
||||||
this.quantityReserved
|
|
||||||
});
|
|
||||||
|
|
||||||
Map<String, String> toMap() {
|
Map<String, String> toMap() {
|
||||||
return {
|
return {
|
||||||
if(itemCode != null) 'itemCode': (itemCode?.id).toString(),
|
if (itemCode != null) 'itemCode': (itemCode?.id).toString(),
|
||||||
if(itemName != null) 'itemName': itemName,
|
if (itemName != null) 'itemName': itemName!,
|
||||||
if(preparationTimeFrame != null) 'preparationTimeFrame': preparationTimeFrame,
|
if (preparationTimeFrame != null) 'preparationTimeFrame': preparationTimeFrame!,
|
||||||
if(kitFrequencyDemand != null) 'kitFrequencyDemand': kitFrequencyDemand,
|
if (kitFrequencyDemand != null) 'kitFrequencyDemand': kitFrequencyDemand!,
|
||||||
if(availability != null) 'availability': availability,
|
if (availability != null) 'availability': availability!,
|
||||||
if(quantityNeeded != null) 'quantityNeeded': quantityNeeded,
|
if (quantityNeeded != null) 'quantityNeeded': quantityNeeded!,
|
||||||
if(quantityReserved != null) 'quantityReserved': quantityReserved,
|
if (quantityReserved != null) 'quantityReserved': quantityReserved!,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
factory PMKit.fromMap(Map<String, dynamic> map) {
|
factory PMKit.fromMap(Map<String, dynamic> map) {
|
||||||
return PMKit(
|
return PMKit(
|
||||||
itemCode: Lookup.fromJson(map['itemCode']),
|
itemCode: Lookup.fromJson(map['itemCode']),
|
||||||
itemName: map['itemName'] as String,
|
itemName: map['itemName'] as String?,
|
||||||
preparationTimeFrame: map['preparationTimeFrame'] as String,
|
preparationTimeFrame: map['preparationTimeFrame'] as String?,
|
||||||
kitFrequencyDemand: map['kitFrequencyDemand'] as String,
|
kitFrequencyDemand: map['kitFrequencyDemand'] as String?,
|
||||||
availability: map['availability'] as String,
|
availability: map['availability'] as String?,
|
||||||
quantityNeeded: map['quantityNeeded'] as String,
|
quantityNeeded: map['quantityNeeded'] as String?,
|
||||||
quantityReserved: map['quantityReserved'] as String,
|
quantityReserved: map['quantityReserved'] as String?,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
class TimerModel {
|
class TimerModel {
|
||||||
DateTime startAt;
|
DateTime? startAt;
|
||||||
DateTime endAt;
|
DateTime? endAt;
|
||||||
int durationInSecond;
|
int? durationInSecond;
|
||||||
|
|
||||||
TimerModel({this.startAt,this.endAt,this.durationInSecond});
|
TimerModel({this.startAt, this.endAt, this.durationInSecond});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,69 +1,433 @@
|
|||||||
import 'package:test_sa/models/lookup.dart';
|
class Visit {
|
||||||
|
int? id;
|
||||||
class Visit{
|
int? visitNo;
|
||||||
String id;
|
String? visitCode;
|
||||||
String serialNumber;
|
int? ppmId;
|
||||||
String expectDate;
|
int? planNo;
|
||||||
String actualDate;
|
String? planCode;
|
||||||
String hospitalId;
|
int? ppmScheduleId;
|
||||||
String hospitalName;
|
int? ppmScheduleNo;
|
||||||
String deviceId;
|
String? ppmScheduleCode;
|
||||||
String deviceSerialNumber;
|
int? assetId;
|
||||||
String deviceArabicName;
|
String? assetName;
|
||||||
String deviceEnglishName;
|
String? assetSerialNo;
|
||||||
String employId;
|
String? assetNumber;
|
||||||
String employName;
|
String? warrantyEndDate;
|
||||||
String modelAndBrand;
|
int? modelId;
|
||||||
String contactStatus;
|
String? modelName;
|
||||||
Lookup status;
|
int? manufacturerId;
|
||||||
String assignTo;
|
String? manufacturerName;
|
||||||
String deviceNumber;
|
int? siteId;
|
||||||
List<String> images;
|
String? siteName;
|
||||||
|
int? assignedToId;
|
||||||
Visit({
|
String? assignedToName;
|
||||||
this.id,
|
String? jobSheetNo;
|
||||||
this.serialNumber,
|
String? assignedEmployeeId;
|
||||||
this.hospitalId,
|
String? assignedEmployeeName;
|
||||||
this.hospitalName,
|
String? expectedDate;
|
||||||
this.deviceId,
|
String? actualDate;
|
||||||
this.deviceSerialNumber,
|
String? nextDate;
|
||||||
this.deviceArabicName,
|
String? forwardToId;
|
||||||
this.deviceEnglishName,
|
String? forwardToName;
|
||||||
this.employId,
|
int? maintenanceContractId;
|
||||||
this.employName,
|
String? contractNumber;
|
||||||
this.expectDate,
|
int? typeOfServiceId;
|
||||||
this.actualDate,
|
String? typeOfServiceName;
|
||||||
this.status,
|
int? executionTimeFrameId;
|
||||||
this.modelAndBrand,
|
String? executionTimeFrameName;
|
||||||
this.contactStatus,
|
String? externalEngineer;
|
||||||
this.images,
|
String? telephone;
|
||||||
this.assignTo,
|
int? groupLeaderReviewId;
|
||||||
this.deviceNumber,
|
String? groupLeaderReviewName;
|
||||||
});
|
int? timePeriodId;
|
||||||
|
String? timePeriodName;
|
||||||
factory Visit.fromJson(Map<String,dynamic> parsedJson){
|
List<VCalibrationTools>? vCalibrationTools;
|
||||||
return Visit(
|
List<VKits>? vKits;
|
||||||
id: parsedJson["nid"],
|
List<VContacts>? vContacts;
|
||||||
serialNumber: parsedJson["title"],
|
List<VChecklists>? vChecklists;
|
||||||
hospitalId: parsedJson["client"],
|
List<String>? vAttachments;
|
||||||
deviceNumber: parsedJson["device_no"],
|
int? visitStatusId;
|
||||||
hospitalName: parsedJson["client_name"],
|
String? visitStatusName;
|
||||||
deviceId: parsedJson["medical_equipment_nid"],
|
String? startDate;
|
||||||
deviceSerialNumber: parsedJson["medical_equipment"],
|
String? endDate;
|
||||||
deviceEnglishName: parsedJson["equipment_english_name"],
|
String? workingHours;
|
||||||
deviceArabicName: parsedJson["equipment_arabic_name"],
|
String? travelingHours;
|
||||||
employId: parsedJson["assigned_employee"],
|
int? deviceStatusId;
|
||||||
employName: parsedJson["assigned_employee_name"],
|
String? deviceStatusName;
|
||||||
expectDate: parsedJson["expected_date"],
|
String? comments;
|
||||||
actualDate: parsedJson["actual_date"],
|
String? workPerformed;
|
||||||
modelAndBrand: parsedJson["mode_brand"],
|
int? supplierId;
|
||||||
contactStatus: parsedJson["contactStatus"],
|
String? supplierName;
|
||||||
images: List<String>.from(parsedJson["images"] ?? []),
|
int? ppmSupplierId;
|
||||||
status: Lookup(
|
String? ppmSupplierName;
|
||||||
id: int.tryParse(parsedJson["status"] ?? "-1"), // actual value (0,1,2)
|
String? createdOn;
|
||||||
label: parsedJson["status_value"] // text value
|
String? modifiedOn;
|
||||||
),
|
int? taskStatusId;
|
||||||
assignTo: parsedJson["assigned_to"],
|
String? taskStatusName;
|
||||||
);
|
|
||||||
|
Visit(
|
||||||
|
{this.id,
|
||||||
|
this.visitNo,
|
||||||
|
this.visitCode,
|
||||||
|
this.ppmId,
|
||||||
|
this.planNo,
|
||||||
|
this.planCode,
|
||||||
|
this.ppmScheduleId,
|
||||||
|
this.ppmScheduleNo,
|
||||||
|
this.ppmScheduleCode,
|
||||||
|
this.assetId,
|
||||||
|
this.assetName,
|
||||||
|
this.assetSerialNo,
|
||||||
|
this.assetNumber,
|
||||||
|
this.warrantyEndDate,
|
||||||
|
this.modelId,
|
||||||
|
this.modelName,
|
||||||
|
this.manufacturerId,
|
||||||
|
this.manufacturerName,
|
||||||
|
this.siteId,
|
||||||
|
this.siteName,
|
||||||
|
this.assignedToId,
|
||||||
|
this.assignedToName,
|
||||||
|
this.jobSheetNo,
|
||||||
|
this.assignedEmployeeId,
|
||||||
|
this.assignedEmployeeName,
|
||||||
|
this.expectedDate,
|
||||||
|
this.actualDate,
|
||||||
|
this.nextDate,
|
||||||
|
this.forwardToId,
|
||||||
|
this.forwardToName,
|
||||||
|
this.maintenanceContractId,
|
||||||
|
this.contractNumber,
|
||||||
|
this.typeOfServiceId,
|
||||||
|
this.typeOfServiceName,
|
||||||
|
this.executionTimeFrameId,
|
||||||
|
this.executionTimeFrameName,
|
||||||
|
this.externalEngineer,
|
||||||
|
this.telephone,
|
||||||
|
this.groupLeaderReviewId,
|
||||||
|
this.groupLeaderReviewName,
|
||||||
|
this.timePeriodId,
|
||||||
|
this.timePeriodName,
|
||||||
|
this.vCalibrationTools,
|
||||||
|
this.vKits,
|
||||||
|
this.vContacts,
|
||||||
|
this.vChecklists,
|
||||||
|
this.vAttachments,
|
||||||
|
this.visitStatusId,
|
||||||
|
this.visitStatusName,
|
||||||
|
this.startDate,
|
||||||
|
this.endDate,
|
||||||
|
this.workingHours,
|
||||||
|
this.travelingHours,
|
||||||
|
this.deviceStatusId,
|
||||||
|
this.deviceStatusName,
|
||||||
|
this.comments,
|
||||||
|
this.workPerformed,
|
||||||
|
this.supplierId,
|
||||||
|
this.supplierName,
|
||||||
|
this.ppmSupplierId,
|
||||||
|
this.ppmSupplierName,
|
||||||
|
this.createdOn,
|
||||||
|
this.modifiedOn,
|
||||||
|
this.taskStatusId,
|
||||||
|
this.taskStatusName});
|
||||||
|
|
||||||
|
Visit.fromJson(Map<String, dynamic> json) {
|
||||||
|
id = json['id'];
|
||||||
|
visitNo = json['visitNo'];
|
||||||
|
visitCode = json['visitCode'];
|
||||||
|
ppmId = json['ppmId'];
|
||||||
|
planNo = json['planNo'];
|
||||||
|
planCode = json['planCode'];
|
||||||
|
ppmScheduleId = json['ppmScheduleId'];
|
||||||
|
ppmScheduleNo = json['ppmScheduleNo'];
|
||||||
|
ppmScheduleCode = json['ppmScheduleCode'];
|
||||||
|
assetId = json['assetId'];
|
||||||
|
assetName = json['assetName'];
|
||||||
|
assetSerialNo = json['assetSerialNo'];
|
||||||
|
assetNumber = json['assetNumber'];
|
||||||
|
warrantyEndDate = json['warrantyEndDate'];
|
||||||
|
modelId = json['modelId'];
|
||||||
|
modelName = json['modelName'];
|
||||||
|
manufacturerId = json['manufacturerId'];
|
||||||
|
manufacturerName = json['manufacturerName'];
|
||||||
|
siteId = json['siteId'];
|
||||||
|
siteName = json['siteName'];
|
||||||
|
assignedToId = json['assignedToId'];
|
||||||
|
assignedToName = json['assignedToName'];
|
||||||
|
jobSheetNo = json['jobSheetNo'];
|
||||||
|
assignedEmployeeId = json['assignedEmployeeId'];
|
||||||
|
assignedEmployeeName = json['assignedEmployeeName'];
|
||||||
|
expectedDate = json['expectedDate'];
|
||||||
|
actualDate = json['actualDate'];
|
||||||
|
nextDate = json['nextDate'];
|
||||||
|
forwardToId = json['forwardToId'];
|
||||||
|
forwardToName = json['forwardToName'];
|
||||||
|
maintenanceContractId = json['maintenanceContractId'];
|
||||||
|
contractNumber = json['contractNumber'];
|
||||||
|
typeOfServiceId = json['typeOfServiceId'];
|
||||||
|
typeOfServiceName = json['typeOfServiceName'];
|
||||||
|
executionTimeFrameId = json['executionTimeFrameId'];
|
||||||
|
executionTimeFrameName = json['executionTimeFrameName'];
|
||||||
|
externalEngineer = json['externalEngineer'];
|
||||||
|
telephone = json['telephone'];
|
||||||
|
groupLeaderReviewId = json['groupLeaderReviewId'];
|
||||||
|
groupLeaderReviewName = json['groupLeaderReviewName'];
|
||||||
|
timePeriodId = json['timePeriodId'];
|
||||||
|
timePeriodName = json['timePeriodName'];
|
||||||
|
if (json['vCalibrationTools'] != null) {
|
||||||
|
vCalibrationTools = <VCalibrationTools>[];
|
||||||
|
json['vCalibrationTools'].forEach((v) {
|
||||||
|
vCalibrationTools!.add(VCalibrationTools.fromJson(v));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (json['vKits'] != null) {
|
||||||
|
vKits = <VKits>[];
|
||||||
|
json['vKits'].forEach((v) {
|
||||||
|
vKits!.add(VKits.fromJson(v));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (json['vContacts'] != null) {
|
||||||
|
vContacts = <VContacts>[];
|
||||||
|
json['vContacts'].forEach((v) {
|
||||||
|
vContacts!.add(VContacts.fromJson(v));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (json['vChecklists'] != null) {
|
||||||
|
vChecklists = <VChecklists>[];
|
||||||
|
json['vChecklists'].forEach((v) {
|
||||||
|
vChecklists!.add(VChecklists.fromJson(v));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
vAttachments = json['vAttachments'].cast<String>();
|
||||||
|
visitStatusId = json['visitStatusId'];
|
||||||
|
visitStatusName = json['visitStatusName'];
|
||||||
|
startDate = json['startDate'];
|
||||||
|
endDate = json['endDate'];
|
||||||
|
workingHours = json['workingHours'];
|
||||||
|
travelingHours = json['travelingHours'];
|
||||||
|
deviceStatusId = json['deviceStatusId'];
|
||||||
|
deviceStatusName = json['deviceStatusName'];
|
||||||
|
comments = json['comments'];
|
||||||
|
workPerformed = json['workPerformed'];
|
||||||
|
supplierId = json['supplierId'];
|
||||||
|
supplierName = json['supplierName'];
|
||||||
|
ppmSupplierId = json['ppmSupplierId'];
|
||||||
|
ppmSupplierName = json['ppmSupplierName'];
|
||||||
|
createdOn = json['createdOn'];
|
||||||
|
modifiedOn = json['modifiedOn'];
|
||||||
|
taskStatusId = json['taskStatusId'];
|
||||||
|
taskStatusName = json['taskStatusName'];
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
final Map<String, dynamic> data = <String, dynamic>{};
|
||||||
|
data['id'] = id;
|
||||||
|
data['visitNo'] = visitNo;
|
||||||
|
data['visitCode'] = visitCode;
|
||||||
|
data['ppmId'] = ppmId;
|
||||||
|
data['planNo'] = planNo;
|
||||||
|
data['planCode'] = planCode;
|
||||||
|
data['ppmScheduleId'] = ppmScheduleId;
|
||||||
|
data['ppmScheduleNo'] = ppmScheduleNo;
|
||||||
|
data['ppmScheduleCode'] = ppmScheduleCode;
|
||||||
|
data['assetId'] = assetId;
|
||||||
|
data['assetName'] = assetName;
|
||||||
|
data['assetSerialNo'] = assetSerialNo;
|
||||||
|
data['assetNumber'] = assetNumber;
|
||||||
|
data['warrantyEndDate'] = warrantyEndDate;
|
||||||
|
data['modelId'] = modelId;
|
||||||
|
data['modelName'] = modelName;
|
||||||
|
data['manufacturerId'] = manufacturerId;
|
||||||
|
data['manufacturerName'] = manufacturerName;
|
||||||
|
data['siteId'] = siteId;
|
||||||
|
data['siteName'] = siteName;
|
||||||
|
data['assignedToId'] = assignedToId;
|
||||||
|
data['assignedToName'] = assignedToName;
|
||||||
|
data['jobSheetNo'] = jobSheetNo;
|
||||||
|
data['assignedEmployeeId'] = assignedEmployeeId;
|
||||||
|
data['assignedEmployeeName'] = assignedEmployeeName;
|
||||||
|
data['expectedDate'] = expectedDate;
|
||||||
|
data['actualDate'] = actualDate;
|
||||||
|
data['nextDate'] = nextDate;
|
||||||
|
data['forwardToId'] = forwardToId;
|
||||||
|
data['forwardToName'] = forwardToName;
|
||||||
|
data['maintenanceContractId'] = maintenanceContractId;
|
||||||
|
data['contractNumber'] = contractNumber;
|
||||||
|
data['typeOfServiceId'] = typeOfServiceId;
|
||||||
|
data['typeOfServiceName'] = typeOfServiceName;
|
||||||
|
data['executionTimeFrameId'] = executionTimeFrameId;
|
||||||
|
data['executionTimeFrameName'] = executionTimeFrameName;
|
||||||
|
data['externalEngineer'] = externalEngineer;
|
||||||
|
data['telephone'] = telephone;
|
||||||
|
data['groupLeaderReviewId'] = groupLeaderReviewId;
|
||||||
|
data['groupLeaderReviewName'] = groupLeaderReviewName;
|
||||||
|
data['timePeriodId'] = timePeriodId;
|
||||||
|
data['timePeriodName'] = timePeriodName;
|
||||||
|
if (vCalibrationTools != null) {
|
||||||
|
data['vCalibrationTools'] = vCalibrationTools!.map((v) => v.toJson()).toList();
|
||||||
|
}
|
||||||
|
if (vKits != null) {
|
||||||
|
data['vKits'] = vKits!.map((v) => v.toJson()).toList();
|
||||||
|
}
|
||||||
|
if (vContacts != null) {
|
||||||
|
data['vContacts'] = vContacts!.map((v) => v.toJson()).toList();
|
||||||
|
}
|
||||||
|
if (vChecklists != null) {
|
||||||
|
data['vChecklists'] = vChecklists!.map((v) => v.toJson()).toList();
|
||||||
|
}
|
||||||
|
data['vAttachments'] = vAttachments;
|
||||||
|
data['visitStatusId'] = visitStatusId;
|
||||||
|
data['visitStatusName'] = visitStatusName;
|
||||||
|
data['startDate'] = startDate;
|
||||||
|
data['endDate'] = endDate;
|
||||||
|
data['workingHours'] = workingHours;
|
||||||
|
data['travelingHours'] = travelingHours;
|
||||||
|
data['deviceStatusId'] = deviceStatusId;
|
||||||
|
data['deviceStatusName'] = deviceStatusName;
|
||||||
|
data['comments'] = comments;
|
||||||
|
data['workPerformed'] = workPerformed;
|
||||||
|
data['supplierId'] = supplierId;
|
||||||
|
data['supplierName'] = supplierName;
|
||||||
|
data['ppmSupplierId'] = ppmSupplierId;
|
||||||
|
data['ppmSupplierName'] = ppmSupplierName;
|
||||||
|
data['createdOn'] = createdOn;
|
||||||
|
data['modifiedOn'] = modifiedOn;
|
||||||
|
data['taskStatusId'] = taskStatusId;
|
||||||
|
data['taskStatusName'] = taskStatusName;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class VCalibrationTools {
|
||||||
|
int? id;
|
||||||
|
int? visitId;
|
||||||
|
int? assetId;
|
||||||
|
String? assetSerialNo;
|
||||||
|
String? calibrationDateOfTesters;
|
||||||
|
|
||||||
|
VCalibrationTools({this.id, this.visitId, this.assetId, this.assetSerialNo, this.calibrationDateOfTesters});
|
||||||
|
|
||||||
|
VCalibrationTools.fromJson(Map<String, dynamic> json) {
|
||||||
|
id = json['id'];
|
||||||
|
visitId = json['visitId'];
|
||||||
|
assetId = json['assetId'];
|
||||||
|
assetSerialNo = json['assetSerialNo'];
|
||||||
|
calibrationDateOfTesters = json['calibrationDateOfTesters'];
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
final Map<String, dynamic> data = <String, dynamic>{};
|
||||||
|
data['id'] = id;
|
||||||
|
data['visitId'] = visitId;
|
||||||
|
data['assetId'] = assetId;
|
||||||
|
data['assetSerialNo'] = assetSerialNo;
|
||||||
|
data['calibrationDateOfTesters'] = calibrationDateOfTesters;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class VKits {
|
||||||
|
int? id;
|
||||||
|
int? visitId;
|
||||||
|
int? partCatalogItemId;
|
||||||
|
String? partNumber;
|
||||||
|
String? oracleCode;
|
||||||
|
String? partName;
|
||||||
|
String? partName2;
|
||||||
|
|
||||||
|
VKits({this.id, this.visitId, this.partCatalogItemId, this.partNumber, this.oracleCode, this.partName, this.partName2});
|
||||||
|
|
||||||
|
VKits.fromJson(Map<String, dynamic> json) {
|
||||||
|
id = json['id'];
|
||||||
|
visitId = json['visitId'];
|
||||||
|
partCatalogItemId = json['partCatalogItemId'];
|
||||||
|
partNumber = json['partNumber'];
|
||||||
|
oracleCode = json['oracleCode'];
|
||||||
|
partName = json['partName'];
|
||||||
|
partName2 = json['partName2'];
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
final Map<String, dynamic> data = <String, dynamic>{};
|
||||||
|
data['id'] = id;
|
||||||
|
data['visitId'] = visitId;
|
||||||
|
data['partCatalogItemId'] = partCatalogItemId;
|
||||||
|
data['partNumber'] = partNumber;
|
||||||
|
data['oracleCode'] = oracleCode;
|
||||||
|
data['partName'] = partName;
|
||||||
|
data['partName2'] = partName2;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class VContacts {
|
||||||
|
int? id;
|
||||||
|
int? visitId;
|
||||||
|
String? title;
|
||||||
|
String? person;
|
||||||
|
String? job;
|
||||||
|
String? email;
|
||||||
|
String? telephone;
|
||||||
|
String? landLine;
|
||||||
|
|
||||||
|
VContacts({this.id, this.visitId, this.title, this.person, this.job, this.email, this.telephone, this.landLine});
|
||||||
|
|
||||||
|
VContacts.fromJson(Map<String, dynamic> json) {
|
||||||
|
id = json['id'];
|
||||||
|
visitId = json['visitId'];
|
||||||
|
title = json['title'];
|
||||||
|
person = json['person'];
|
||||||
|
job = json['job'];
|
||||||
|
email = json['email'];
|
||||||
|
telephone = json['telephone'];
|
||||||
|
landLine = json['landLine'];
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
final Map<String, dynamic> data = <String, dynamic>{};
|
||||||
|
data['id'] = id;
|
||||||
|
data['visitId'] = visitId;
|
||||||
|
data['title'] = title;
|
||||||
|
data['person'] = person;
|
||||||
|
data['job'] = job;
|
||||||
|
data['email'] = email;
|
||||||
|
data['telephone'] = telephone;
|
||||||
|
data['landLine'] = landLine;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class VChecklists {
|
||||||
|
int? id;
|
||||||
|
int? visitId;
|
||||||
|
String? task;
|
||||||
|
int? taskStatusId;
|
||||||
|
String? taskStatusName;
|
||||||
|
String? taskComment;
|
||||||
|
String? measuredValue;
|
||||||
|
|
||||||
|
VChecklists({this.id, this.visitId, this.task, this.taskStatusId, this.taskStatusName, this.taskComment, this.measuredValue});
|
||||||
|
|
||||||
|
VChecklists.fromJson(Map<String, dynamic> json) {
|
||||||
|
id = json['id'];
|
||||||
|
visitId = json['visitId'];
|
||||||
|
task = json['task'];
|
||||||
|
taskStatusId = json['taskStatusId'];
|
||||||
|
taskStatusName = json['taskStatusName'];
|
||||||
|
taskComment = json['taskComment'];
|
||||||
|
measuredValue = json['measuredValue'];
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
final Map<String, dynamic> data = <String, dynamic>{};
|
||||||
|
data['id'] = id;
|
||||||
|
data['visitId'] = visitId;
|
||||||
|
data['task'] = task;
|
||||||
|
data['taskStatusId'] = taskStatusId;
|
||||||
|
data['taskStatusName'] = taskStatusName;
|
||||||
|
data['taskComment'] = taskComment;
|
||||||
|
data['measuredValue'] = measuredValue;
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,39 +1,31 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class AppStyle {
|
class AppStyle {
|
||||||
AppStyle._();
|
AppStyle._();
|
||||||
|
|
||||||
static const double borderRadius = 10;
|
static const double borderRadius = 10;
|
||||||
|
|
||||||
static const BoxShadow boxShadow = BoxShadow(
|
static const BoxShadow boxShadow = BoxShadow(color: Colors.black26, blurRadius: 3, offset: Offset(0, 2));
|
||||||
color: Colors.black26,
|
|
||||||
blurRadius: 3,
|
|
||||||
offset: Offset(0,2)
|
|
||||||
);
|
|
||||||
|
|
||||||
static double getBorderRadius(BuildContext context){
|
static double getBorderRadius(BuildContext context) {
|
||||||
return borderRadius * getScaleFactor(context);
|
return borderRadius * getScaleFactor(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static double getScaleFactor(BuildContext context){
|
static double getScaleFactor(BuildContext context) {
|
||||||
return MediaQuery.of(context).orientation == Orientation.portrait
|
return MediaQuery.of(context).orientation == Orientation.portrait
|
||||||
? MediaQuery.of(context).size.width/(360) > 1.5
|
? MediaQuery.of(context).size.width / (360) > 1.5
|
||||||
? 1.5 : MediaQuery.of(context).size.width/(360)
|
? 1.5
|
||||||
: MediaQuery.of(context).size.height/(360) > 1.5
|
: MediaQuery.of(context).size.width / (360)
|
||||||
? 1.5 : MediaQuery.of(context).size.height/(360);
|
: MediaQuery.of(context).size.height / (360) > 1.5
|
||||||
|
? 1.5
|
||||||
|
: MediaQuery.of(context).size.height / (360);
|
||||||
}
|
}
|
||||||
|
|
||||||
static BorderRadius getCardBorder(BuildContext context){
|
static BorderRadius getCardBorder(BuildContext context) {
|
||||||
return BorderRadius.only(
|
return BorderRadius.only(
|
||||||
topRight: Radius.circular(
|
topRight: Radius.circular(AppStyle.borderRadius * AppStyle.getScaleFactor(context)),
|
||||||
AppStyle.borderRadius * AppStyle.getScaleFactor(context)
|
topLeft: Radius.circular(AppStyle.borderRadius * AppStyle.getScaleFactor(context)),
|
||||||
),
|
bottomRight: Radius.circular(AppStyle.borderRadius * AppStyle.getScaleFactor(context)),
|
||||||
topLeft: Radius.circular(
|
|
||||||
AppStyle.borderRadius * AppStyle.getScaleFactor(context)
|
|
||||||
),
|
|
||||||
bottomRight: Radius.circular(
|
|
||||||
AppStyle.borderRadius * AppStyle.getScaleFactor(context)
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|||||||
@ -1,43 +1,44 @@
|
|||||||
import 'package:test_sa/controllers/localization/localization.dart';
|
|
||||||
import 'package:test_sa/models/app_notification.dart';
|
|
||||||
import 'package:test_sa/models/subtitle.dart';
|
|
||||||
import 'package:test_sa/views/pages/user/requests/future_request_service_details.dart';
|
|
||||||
import 'package:test_sa/views/widgets/loaders/lazy_loading.dart';
|
|
||||||
import 'package:test_sa/views/widgets/loaders/no_item_found.dart';
|
|
||||||
import 'package:test_sa/views/widgets/notifications/notification_item.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import '../../../../controllers/localization/localization.dart';
|
||||||
|
import '../../../../models/app_notification.dart';
|
||||||
|
import '../../../../models/subtitle.dart';
|
||||||
|
import '../../../widgets/loaders/lazy_loading.dart';
|
||||||
|
import '../../../widgets/loaders/no_item_found.dart';
|
||||||
|
import '../../../widgets/notifications/notification_item.dart';
|
||||||
|
import '../requests/future_request_service_details.dart';
|
||||||
|
|
||||||
class NotificationsList extends StatelessWidget {
|
class NotificationsList extends StatelessWidget {
|
||||||
final List<AppNotification> notifications;
|
final List<AppNotification>? notifications;
|
||||||
final bool nextPage;
|
final bool? nextPage;
|
||||||
final Future<void> Function() onLazyLoad;
|
final Future<void> Function()? onLazyLoad;
|
||||||
|
|
||||||
const NotificationsList({Key key, this.notifications, this.nextPage, this.onLazyLoad}) : super(key: key);
|
const NotificationsList({Key? key, this.notifications, this.nextPage, this.onLazyLoad}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
Subtitle _subtitle = AppLocalization.of(context).subtitle;
|
Subtitle? _subtitle = AppLocalization.of(context)?.subtitle;
|
||||||
if(notifications.length == 0){
|
if ((notifications?.isEmpty ?? false)) {
|
||||||
return NoItemFound(message: _subtitle.notificationsNotFound,);
|
return NoItemFound(
|
||||||
|
message: _subtitle?.notificationsNotFound ?? "",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return LazyLoading(
|
return LazyLoading(
|
||||||
nextPage: nextPage,
|
nextPage: nextPage ?? false,
|
||||||
onLazyLoad: onLazyLoad,
|
onLazyLoad: onLazyLoad ?? () async {},
|
||||||
|
onLoadingEnd: () {},
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
physics: BouncingScrollPhysics(),
|
physics: BouncingScrollPhysics(),
|
||||||
itemCount: notifications.length,
|
itemCount: notifications?.length,
|
||||||
padding: EdgeInsets.symmetric(horizontal: 16,vertical: 8),
|
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||||
itemBuilder: (context,itemIndex){
|
itemBuilder: (context, itemIndex) {
|
||||||
return NotificationItem(
|
return NotificationItem(
|
||||||
notification: notifications[itemIndex],
|
notification: notifications![itemIndex],
|
||||||
onPressed: (notification){
|
onPressed: (notification) {
|
||||||
Navigator.of(context).pushNamed(
|
Navigator.of(context).pushNamed(FutureRequestServiceDetails.id, arguments: notification.requestId);
|
||||||
FutureRequestServiceDetails.id,
|
|
||||||
arguments: notification.requestId
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue