From 1a3232dbe16d5406d2e1dddd9ee0bc971423c71b Mon Sep 17 00:00:00 2001 From: zaid_daoud Date: Mon, 27 Mar 2023 12:14:23 +0300 Subject: [PATCH] Changing User Model --- lib/api/api_client.dart | 2 +- lib/api/service_request_api_client.dart | 34 +-- lib/api/user_api_client.dart | 6 +- .../providers/api/devices_provider.dart | 6 +- lib/controllers/providers/user_provider.dart | 26 +-- lib/models/user.dart | 209 ++++++++++++------ lib/views/pages/register.dart | 56 +++-- .../user/gas_refill/gas_refill_details.dart | 5 +- lib/views/pages/user/land_page.dart | 4 +- .../notifications/notifications_page.dart | 17 +- lib/views/pages/user/profile_page.dart | 59 +++-- .../pages/user/requests/create_request.dart | 37 ++-- .../pages/user/requests/request_details.dart | 6 +- .../equipment/single_device_picker.dart | 5 +- .../pentry/pentry_calibration_tool_form.dart | 3 +- .../requests/service_request_item.dart | 4 +- lib/views/widgets/visits/visit_item.dart | 7 +- 17 files changed, 268 insertions(+), 218 deletions(-) diff --git a/lib/api/api_client.dart b/lib/api/api_client.dart index d719586f..1ac91bfa 100644 --- a/lib/api/api_client.dart +++ b/lib/api/api_client.dart @@ -67,7 +67,7 @@ class ApiClient { factory ApiClient() => _instance; Future postJsonForObject(FactoryConstructor factoryConstructor, String url, T jsonObject, - {String? token, Map? queryParameters, Map? headers, int retryTimes = 0, bool isFormData = true}) async { + {String? token, Map? queryParameters, Map? headers, int retryTimes = 0, bool isFormData = false}) async { var defaultHeaders = {'Accept': 'application/json'}; if (headers != null && headers.isNotEmpty) { defaultHeaders.addAll(headers); diff --git a/lib/api/service_request_api_client.dart b/lib/api/service_request_api_client.dart index 2e35eef9..a702319a 100644 --- a/lib/api/service_request_api_client.dart +++ b/lib/api/service_request_api_client.dart @@ -29,16 +29,16 @@ class ServiceRequestApiClient { }, '${URLs.host1}${URLs.createRequest}', { - "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, + // "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, }, ); } @@ -49,13 +49,13 @@ class ServiceRequestApiClient { final response = await ApiClient().getJsonForResponse( '${URLs.host1}${URLs.getServiceRequests}', headers: {"Content-Type": "application/json; charset=utf-8"}, - queryParameters: { - 'uid': user?.id, - if (user?.hospital?.id != null) 'client_nid': user?.hospital?.id, - 'token': user?.token, - 'page': '${(serviceRequests.length) ~/ pageItemNumber}', - if (search != null) ...search.queryParameters(), - }, + // queryParameters: { + // 'uid': user?.id, + // if (user?.hospital?.id != null) 'client_nid': user?.hospital?.id, + // 'token': user?.token, + // 'page': '${(serviceRequests.length) ~/ pageItemNumber}', + // if (search != null) ...search.queryParameters(), + // }, ); List requestsListJson = json.decode(utf8.decode(response.bodyBytes)); List serviceRequestsPage = requestsListJson.map((request) => ServiceRequest.fromJson(request)).toList(); diff --git a/lib/api/user_api_client.dart b/lib/api/user_api_client.dart index c3d47fdd..24d8337b 100644 --- a/lib/api/user_api_client.dart +++ b/lib/api/user_api_client.dart @@ -21,13 +21,11 @@ class UserApiClient { Future login({required User user}) async { return await ApiClient().postJsonForObject( (json) { - this.user = User.fromJson(json[0]); + this.user = User.fromJson(json); }, "${URLs.host1}${URLs.login}", await user.toLoginJson(), //body - headers: { - 'Content-Type': 'application/json; charset=utf-8', - }, + isFormData: false, ); } diff --git a/lib/controllers/providers/api/devices_provider.dart b/lib/controllers/providers/api/devices_provider.dart index ed1f7c4b..07d5a169 100644 --- a/lib/controllers/providers/api/devices_provider.dart +++ b/lib/controllers/providers/api/devices_provider.dart @@ -25,7 +25,8 @@ class DevicesProvider extends LoadingNotifier { /// - [_searchableList] will be filled after the request succeed. /// /// ### NOTE : if [hospitalId] is [NULL] nothing will happen - Future getEquipment({required String? hospitalId}) async { + Future getEquipment() async { + final hospitalId = /*UserApiClient().user?.hospital?.id ??*/ ''; if (hospitalId != null) { _searchableList.clear(); await waitApiRequest( @@ -56,7 +57,8 @@ class DevicesProvider extends LoadingNotifier { /// Returns a list of devices by [hospitalId] (and optionally) [serialNumber] /// /// ### NOTE : if [hospitalId] is [NULL] empty list will be returned - Future> getDevicesListBySN({required String? hospitalId, required String serialNumber}) { + Future> getDevicesListBySN({required String serialNumber}) { + final hospitalId = /*UserApiClient().user?.hospital?.id ??*/ ""; if (hospitalId == null) return Future.value(const []); return DevicesApiClient().getDevicesListBySN(hospitalId: hospitalId, serialNumber: serialNumber); } diff --git a/lib/controllers/providers/user_provider.dart b/lib/controllers/providers/user_provider.dart index 2d8ae6ab..31f86560 100644 --- a/lib/controllers/providers/user_provider.dart +++ b/lib/controllers/providers/user_provider.dart @@ -31,7 +31,7 @@ class UserProvider extends LoadingNotifier { onSuccess: () { if (context.mounted) { Provider.of(context, listen: false).setUser(UserApiClient().user ?? User()); - if (UserApiClient().user?.isActive ?? false) { + if (UserApiClient().user?.isAuthenticated ?? false) { Navigator.of(context).pushNamed(LandPage.id); } else { Fluttertoast.showToast(msg: subtitle?.activationAlert ?? ""); @@ -50,14 +50,14 @@ class UserProvider extends LoadingNotifier { /// - 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; - } + // 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); @@ -82,10 +82,10 @@ class UserProvider extends LoadingNotifier { /// - 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; - } + // if (updatedUser.department?.id == null) { + // ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(subtitle?.unitRequired ?? ""))); + // return; + // } waitApiRequest( () async { await UserApiClient().updateProfile(updatedUser: updatedUser); diff --git a/lib/models/user.dart b/lib/models/user.dart index adb33a7c..3e2d908f 100644 --- a/lib/models/user.dart +++ b/lib/models/user.dart @@ -1,23 +1,141 @@ import '../controllers/notification/firebase_notification_manger.dart'; -import 'department.dart'; -import 'enums/user_types.dart'; -import 'hospital.dart'; class User { + String? clientId; + String? clientName; + int? departmentId; + String? departmentName; + String? message; + String? username; + String? userID; + String? email; + String? password; + String? token; + String? roles; + List? userRoles; + String? tokenlife; + bool? isAuthenticated; + bool? hasError; + String? profilePhotoName; String? id; - String userName; - String password; - String email; - String? image; - Hospital? hospital; - Department? department; - UsersTypes? type; + String? userName; + String? normalizedUserName; + String? normalizedEmail; + bool? emailConfirmed; + String? passwordHash; + String? securityStamp; + String? concurrencyStamp; + + ///I'm not sure from the datatype String? phoneNumber; - String? whatsApp; - String? token; - bool isActive; + bool? phoneNumberConfirmed; + bool? twoFactorEnabled; + + ///I'm not sure from the datatype + String? lockoutEnd; + bool? lockoutEnabled; + int? accessFailedCount; + + User({ + this.clientId, + this.clientName, + this.departmentId, + this.departmentName, + this.message, + this.username, + this.userID, + this.email, + this.password, + this.token, + this.roles, + this.userRoles, + this.tokenlife, + this.isAuthenticated, + this.hasError, + this.profilePhotoName, + this.id, + this.userName, + this.normalizedUserName, + this.normalizedEmail, + this.emailConfirmed, + this.passwordHash, + this.securityStamp, + this.concurrencyStamp, + this.phoneNumber, + this.phoneNumberConfirmed, + this.twoFactorEnabled, + this.lockoutEnd, + this.lockoutEnabled, + this.accessFailedCount, + }); - User({this.id, this.userName = "", this.email = "", this.password = "", this.phoneNumber, this.hospital, this.image, this.department, this.type, this.whatsApp, this.token, this.isActive = false}); + User.fromJson(Map json) { + clientId = json['client_id']; + clientName = json['client_name']; + departmentId = json['department_id']; + departmentName = json['department_name']; + message = json['message']; + username = json['username']; + userID = json['userID']; + email = json['email']; + password = json['password']; + token = json['token']; + roles = json['roles']; + userRoles = json['userRoles'] as List?; + tokenlife = json['tokenlife']; + isAuthenticated = json['isAuthenticated']; + hasError = json['hasError']; + profilePhotoName = json['profilePhotoName']; + id = json['id']; + userName = json['userName']; + normalizedUserName = json['normalizedUserName']; + normalizedEmail = json['normalizedEmail']; + emailConfirmed = json['emailConfirmed']; + passwordHash = json['passwordHash']; + securityStamp = json['securityStamp']; + concurrencyStamp = json['concurrencyStamp']; + phoneNumber = json['phoneNumber']; + phoneNumberConfirmed = json['phoneNumberConfirmed']; + twoFactorEnabled = json['twoFactorEnabled']; + lockoutEnd = json['lockoutEnd']; + lockoutEnabled = json['lockoutEnabled']; + accessFailedCount = json['accessFailedCount']; + } + + Map toJson() { + final Map data = {}; + data['client_id'] = clientId; + data['client_name'] = clientName; + data['department_id'] = departmentId; + data['department_name'] = departmentName; + data['message'] = message; + data['username'] = username; + data['userID'] = userID; + data['email'] = email; + data['password'] = password; + data['token'] = token; + data['roles'] = roles; + data['userRoles'] = userRoles; + data['tokenlife'] = tokenlife; + data['isAuthenticated'] = isAuthenticated; + data['hasError'] = hasError; + data['profilePhotoName'] = profilePhotoName; + data['id'] = id; + data['userName'] = userName; + data['normalizedUserName'] = normalizedUserName; + data['normalizedEmail'] = normalizedEmail; + data['emailConfirmed'] = emailConfirmed; + data['passwordHash'] = passwordHash; + data['securityStamp'] = securityStamp; + data['concurrencyStamp'] = concurrencyStamp; + data['phoneNumber'] = phoneNumber; + data['phoneNumberConfirmed'] = phoneNumberConfirmed; + data['twoFactorEnabled'] = twoFactorEnabled; + data['lockoutEnd'] = lockoutEnd; + data['lockoutEnabled'] = lockoutEnabled; + data['accessFailedCount'] = accessFailedCount; + return data; + } Future> toLoginJson() async { if (FirebaseNotificationManger.token == null) await FirebaseNotificationManger.getToken(); @@ -30,9 +148,9 @@ class User { Map toUpdateProfileJson() { Map jsonObject = {}; - if (department?.id != null && (department?.id?.isNotEmpty ?? false)) jsonObject["department"] = department?.id ?? ""; - if (whatsApp != null && (whatsApp?.isNotEmpty ?? false)) jsonObject["whatsapp"] = whatsApp; - if (phoneNumber != null && (phoneNumber?.isNotEmpty ?? false)) jsonObject["phone"] = phoneNumber; + // if (department?.id != null && (department?.id?.isNotEmpty ?? false)) jsonObject["department"] = department?.id ?? ""; + // if (whatsApp != null && (whatsApp?.isNotEmpty ?? false)) jsonObject["whatsapp"] = whatsApp; + // if (phoneNumber != null && (phoneNumber?.isNotEmpty ?? false)) jsonObject["phoneNumber"] = phoneNumber; return jsonObject; } @@ -41,59 +159,12 @@ class User { return { "username": userName, "email": email, - "whatsapp": whatsApp, - "client": hospital?.id, - "department": department?.id, - "phone": phoneNumber, - "pass": password, - "firebase_token": FirebaseNotificationManger.token ?? "", - }; - } - - Map toJson() { - return { - "uid": id, - "name": userName, - "email": email, - "token": token, - "phone": phoneNumber, - "whatsapp": whatsApp, - "client": hospital?.id, - "client_name": hospital?.name, - "department": department?.id, - "department_name": department?.name, + // "whatsapp": whatsApp, + // "client": hospital?.id, + // "department": department?.id, + "phoneNumber": phoneNumber, "password": password, - "picture": image, - "active": isActive ? 1 : 0, - "role": type == UsersTypes.engineer ? "field_engineer" : "normal_user", - // "token":token, pass is token + "fireBaseToken": FirebaseNotificationManger.token ?? "", }; } - - factory User.fromJson(Map parsedJson) { - UsersTypes type; - switch (parsedJson["role"]) { - case "field_engineer": - type = UsersTypes.engineer; - break; - default: - type = UsersTypes.normal_user; - break; - } - return User( - id: parsedJson["uid"], - userName: parsedJson["name"] ?? parsedJson["title"], - email: parsedJson["mail"] ?? parsedJson["email"], - hospital: Hospital(id: parsedJson["client"], name: parsedJson["client_name"]), - department: Department( - id: parsedJson["department"], - name: parsedJson["department_name"], - ), - image: parsedJson["picture"], - phoneNumber: parsedJson["phone"], - whatsApp: parsedJson["whatsapp"], - token: parsedJson["token"], - isActive: parsedJson["active"] == "1", - type: type); - } } diff --git a/lib/views/pages/register.dart b/lib/views/pages/register.dart index bd7b9a26..86a12103 100644 --- a/lib/views/pages/register.dart +++ b/lib/views/pages/register.dart @@ -1,18 +1,14 @@ import 'package:flutter/material.dart'; -import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:provider/provider.dart'; import '../../controllers/localization/localization.dart'; import '../../controllers/providers/user_provider.dart'; import '../../controllers/validator/validator.dart'; -import '../../models/hospital.dart'; import '../../models/subtitle.dart'; import '../../models/user.dart'; import '../widgets/app_text_form_field.dart'; import '../widgets/buttons/app_back_button.dart'; import '../widgets/buttons/app_button.dart'; -import '../widgets/departments/department_button.dart'; -import '../widgets/hospitals/hospital_button.dart'; import '../widgets/loaders/loading_manager.dart'; class Register extends StatefulWidget { @@ -119,21 +115,21 @@ class RegisterState extends State { }, ), const SizedBox(height: 12), - HospitalButton( - hospital: _user.hospital ?? Hospital(), - onHospitalPick: (hospital) { - _user.hospital = hospital; - setState(() {}); - }, - ), + // HospitalButton( + // hospital: _user.hospital ?? Hospital(), + // onHospitalPick: (hospital) { + // _user.hospital = hospital; + // setState(() {}); + // }, + // ), const SizedBox(height: 12), - DepartmentButton( - department: _user.department, - onDepartmentPick: (department) { - _user.department = department; - setState(() {}); - }, - ), + // DepartmentButton( + // department: _user.department, + // onDepartmentPick: (department) { + // _user.department = department; + // setState(() {}); + // }, + // ), const SizedBox(height: 12), ATextFormField( initialValue: _user.phoneNumber ?? "", @@ -147,18 +143,18 @@ class RegisterState extends State { }, ), const SizedBox(height: 8), - ATextFormField( - initialValue: _user.whatsApp ?? "", - hintText: subtitle?.whatsApp ?? "", - style: Theme.of(context).textTheme.titleLarge, - prefixIconData: FontAwesomeIcons.whatsapp, - prefixIconSize: 36, - validator: (value) => (Validator.isPhoneNumber(value!)) ? "" : subtitle?.phoneNumberValidateMessage ?? "", - textInputType: TextInputType.phone, - onSaved: (value) { - _user.whatsApp = value; - }, - ), + // ATextFormField( + // initialValue: _user.whatsApp ?? "", + // hintText: subtitle?.whatsApp ?? "", + // style: Theme.of(context).textTheme.titleLarge, + // prefixIconData: FontAwesomeIcons.whatsapp, + // prefixIconSize: 36, + // validator: (value) => (Validator.isPhoneNumber(value!)) ? "" : subtitle?.phoneNumberValidateMessage ?? "", + // textInputType: TextInputType.phone, + // onSaved: (value) { + // _user.whatsApp = value; + // }, + // ), const SizedBox(height: 12), AButton( text: subtitle?.signUp ?? "", diff --git a/lib/views/pages/user/gas_refill/gas_refill_details.dart b/lib/views/pages/user/gas_refill/gas_refill_details.dart index 478a3783..a20ab9a2 100644 --- a/lib/views/pages/user/gas_refill/gas_refill_details.dart +++ b/lib/views/pages/user/gas_refill/gas_refill_details.dart @@ -6,12 +6,9 @@ import '../../../../api/user_api_client.dart'; import '../../../../controllers/http_status_manger/http_status_manger.dart'; import '../../../../controllers/localization/localization.dart'; import '../../../../controllers/providers/api/gas_refill_provider.dart'; -import '../../../../controllers/providers/settings/setting_provider.dart'; -import '../../../../controllers/providers/user_provider.dart'; import '../../../../models/enums/user_types.dart'; import '../../../../models/gas_refill/gas_refill_model.dart'; import '../../../../models/subtitle.dart'; -import '../../../../models/user.dart'; import '../../../app_style/colors.dart'; import '../../../app_style/sizing.dart'; import '../../../widgets/buttons/app_back_button.dart'; @@ -105,7 +102,7 @@ class _GasRefillDetailsState extends State { ), ), ), - if (UserApiClient().user?.type == UsersTypes.engineer) + if (UserApiClient().user?.roles == UsersTypes.engineer.name) AIconButton( iconData: _enableEdit ? Icons.cancel : Icons.edit, color: Theme.of(context).colorScheme.onPrimary, diff --git a/lib/views/pages/user/land_page.dart b/lib/views/pages/user/land_page.dart index ee20a72d..9a9c1b37 100644 --- a/lib/views/pages/user/land_page.dart +++ b/lib/views/pages/user/land_page.dart @@ -153,7 +153,7 @@ class _LandPageState extends State { mainAxisSpacing: 12, childAspectRatio: 1, children: [ - if (UserApiClient().user!.type == UsersTypes.normal_user) + if (UserApiClient().user!.roles == UsersTypes.normal_user.name) LandPageItem( text: _subtitle.newServiceRequest, icon: FontAwesomeIcons.tools, @@ -184,7 +184,7 @@ class _LandPageState extends State { // Navigator.of(context).pushNamed(PreventiveMaintenanceVisitsPage.id); // }, // ), - if (UserApiClient().user?.type != UsersTypes.engineer) + if (UserApiClient().user?.roles != UsersTypes.engineer.name) LandPageItem( text: "Request Gas Refill", icon: FontAwesomeIcons.truckFast, diff --git a/lib/views/pages/user/notifications/notifications_page.dart b/lib/views/pages/user/notifications/notifications_page.dart index 453c8ac7..b256a4d4 100644 --- a/lib/views/pages/user/notifications/notifications_page.dart +++ b/lib/views/pages/user/notifications/notifications_page.dart @@ -5,7 +5,6 @@ import '../../../../api/user_api_client.dart'; import '../../../../controllers/localization/localization.dart'; import '../../../../controllers/providers/api/notifications_provider.dart'; import '../../../../controllers/providers/settings/setting_provider.dart'; -import '../../../../controllers/providers/user_provider.dart'; import '../../../../models/subtitle.dart'; import '../../../../models/user.dart'; import '../../../app_style/colors.dart'; @@ -14,20 +13,18 @@ import '../../../widgets/loaders/loading_manager.dart'; import 'notifications_list.dart'; class NotificationsPage extends StatefulWidget { - static final String id = "/notifications"; + static const String id = "/notifications"; @override _NotificationsPageState createState() => _NotificationsPageState(); } class _NotificationsPageState extends State with TickerProviderStateMixin { NotificationsProvider? _notificationsProvider; - UserProvider? _userProvider; SettingProvider? _settingProvider; Subtitle? _subtitle; @override Widget build(BuildContext context) { _notificationsProvider = Provider.of(context); - _userProvider = Provider.of(context); _settingProvider = Provider.of(context); _subtitle = AppLocalization.of(context)?.subtitle; return Scaffold( @@ -41,7 +38,7 @@ class _NotificationsPageState extends State with TickerProvid await _notificationsProvider?.getNotifications( user: UserApiClient().user ?? User(), host: _settingProvider?.host ?? "", - hospitalId: UserApiClient().user?.hospital?.id ?? "", + hospitalId: /*UserApiClient().user?.hospital?.id ??*/ "", ); }, child: Stack( @@ -55,18 +52,16 @@ class _NotificationsPageState extends State with TickerProvid children: [ Row( children: [ - ABackButton(), + const ABackButton(), Expanded( child: Center( child: Text( _subtitle?.notifications ?? "", - style: Theme.of(context).textTheme.headline6?.copyWith(color: AColors.white, fontStyle: FontStyle.italic), + style: Theme.of(context).textTheme.titleLarge?.copyWith(color: AColors.white, fontStyle: FontStyle.italic), ), ), ), - SizedBox( - width: 48, - ) + const SizedBox(width: 48) ], ), ], @@ -79,7 +74,7 @@ class _NotificationsPageState extends State with TickerProvid await _notificationsProvider?.getNotifications( user: UserApiClient().user ?? User(), host: _settingProvider?.host ?? "", - hospitalId: UserApiClient().user?.hospital?.id ?? "", + hospitalId: /*UserApiClient().user?.hospital?.id ??*/ "", ); }, notifications: _notificationsProvider?.notifications, diff --git a/lib/views/pages/user/profile_page.dart b/lib/views/pages/user/profile_page.dart index 3a91bb79..a3ee0f4c 100644 --- a/lib/views/pages/user/profile_page.dart +++ b/lib/views/pages/user/profile_page.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:provider/provider.dart'; import '../../../api/user_api_client.dart'; @@ -14,8 +13,6 @@ import '../../app_style/sizing.dart'; import '../../widgets/app_text_form_field.dart'; import '../../widgets/buttons/app_back_button.dart'; import '../../widgets/buttons/app_button.dart'; -import '../../widgets/departments/department_button.dart'; -import '../../widgets/hospitals/hospital_button.dart'; import '../../widgets/loaders/loading_manager.dart'; class ProfilePage extends StatefulWidget { @@ -105,23 +102,23 @@ class ProfilePageState extends State { }, ), const SizedBox(height: 8), - AbsorbPointer( - child: HospitalButton( - hospital: _user.hospital!, - onHospitalPick: (hospital) { - _user.hospital = hospital; - setState(() {}); - }, - ), - ), + // AbsorbPointer( + // child: HospitalButton( + // hospital: _user.hospital!, + // onHospitalPick: (hospital) { + // _user.hospital = hospital; + // setState(() {}); + // }, + // ), + // ), const SizedBox(height: 8), - DepartmentButton( - department: _user.department, - onDepartmentPick: (department) { - _user.department = department; - setState(() {}); - }, - ), + // DepartmentButton( + // department: _user.department, + // onDepartmentPick: (department) { + // _user.department = department; + // setState(() {}); + // }, + // ), const SizedBox(height: 8), ATextFormField( initialValue: _user.phoneNumber, @@ -135,18 +132,18 @@ class ProfilePageState extends State { }, ), const SizedBox(height: 8), - ATextFormField( - initialValue: _user.whatsApp, - hintText: subtitle.whatsApp, - style: Theme.of(context).textTheme.titleLarge, - prefixIconData: FontAwesomeIcons.whatsapp, - prefixIconSize: 36, - validator: (value) => Validator.isPhoneNumber(value!) ? '' : subtitle.phoneNumberValidateMessage, - textInputType: TextInputType.phone, - onSaved: (value) { - _user.whatsApp = value; - }, - ), + // ATextFormField( + // initialValue: _user.whatsApp, + // hintText: subtitle.whatsApp, + // style: Theme.of(context).textTheme.titleLarge, + // prefixIconData: FontAwesomeIcons.whatsapp, + // prefixIconSize: 36, + // validator: (value) => Validator.isPhoneNumber(value!) ? '' : subtitle.phoneNumberValidateMessage, + // textInputType: TextInputType.phone, + // onSaved: (value) { + // _user.whatsApp = value; + // }, + // ), ], ), ), diff --git a/lib/views/pages/user/requests/create_request.dart b/lib/views/pages/user/requests/create_request.dart index 48d3f821..6904d98d 100644 --- a/lib/views/pages/user/requests/create_request.dart +++ b/lib/views/pages/user/requests/create_request.dart @@ -4,7 +4,6 @@ import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:provider/provider.dart'; -import '../../../../api/user_api_client.dart'; import '../../../../controllers/localization/localization.dart'; import '../../../../controllers/providers/api/service_requests_provider.dart'; import '../../../../controllers/validator/validator.dart'; @@ -101,25 +100,25 @@ class CreateRequestPageState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ 12.height, - UserApiClient().user?.hospital == null - ? const SizedBox.shrink() - : ATextFormField( - enable: false, - initialValue: UserApiClient().user?.hospital?.name ?? _subtitle?.noHospitalFound, - hintText: _subtitle?.hospital, - prefixIconData: FontAwesomeIcons.hospital, - style: Theme.of(context).textTheme.titleMedium, - ), + // UserApiClient().user?.hospital == null + // ? const SizedBox.shrink() + // : ATextFormField( + // enable: false, + // initialValue: UserApiClient().user?.hospital?.name ?? _subtitle?.noHospitalFound, + // hintText: _subtitle?.hospital, + // prefixIconData: FontAwesomeIcons.hospital, + // style: Theme.of(context).textTheme.titleMedium, + // ), 12.height, - UserApiClient().user?.department == null - ? const SizedBox.shrink() - : ATextFormField( - enable: false, - initialValue: UserApiClient().user?.department?.name ?? _subtitle?.noUniteFound, - hintText: _subtitle?.unite, - prefixIconData: FontAwesomeIcons.hospitalUser, - style: Theme.of(context).textTheme.titleMedium, - ), + // UserApiClient().user?.department == null + // ? const SizedBox.shrink() + // : ATextFormField( + // enable: false, + // initialValue: UserApiClient().user?.department?.name ?? _subtitle?.noUniteFound, + // hintText: _subtitle?.unite, + // prefixIconData: FontAwesomeIcons.hospitalUser, + // style: Theme.of(context).textTheme.titleMedium, + // ), 12.height, DeviceButton( device: _device, diff --git a/lib/views/pages/user/requests/request_details.dart b/lib/views/pages/user/requests/request_details.dart index 8c783354..f29fea5d 100644 --- a/lib/views/pages/user/requests/request_details.dart +++ b/lib/views/pages/user/requests/request_details.dart @@ -54,7 +54,7 @@ class RequestDetailsPage extends StatelessWidget { ), ), Visibility( - visible: UserApiClient().user?.type == UsersTypes.normal_user, + visible: UserApiClient().user?.roles == UsersTypes.normal_user.name, replacement: AIconButton( iconData: Icons.edit, color: AColors.white, @@ -207,7 +207,7 @@ class RequestDetailsPage extends StatelessWidget { RequestInfoRow(title: subtitle?.workPerformed, content: serviceRequest.workPerformed), RequestInfoRow(title: subtitle?.visitDate, info: serviceRequest.visitDate), RequestInfoRow(title: subtitle?.jobSheetNumber, info: serviceRequest.jobSheetNumber), - UserApiClient().user?.type == UsersTypes.engineer + UserApiClient().user?.roles == UsersTypes.engineer.name ? Padding( padding: const EdgeInsets.all(32), child: AButton( @@ -222,7 +222,7 @@ class RequestDetailsPage extends StatelessWidget { : const SizedBox.shrink(), ], ) - : UserApiClient().user?.type == UsersTypes.engineer + : UserApiClient().user?.roles == UsersTypes.engineer.name ? Center( child: Padding( padding: const EdgeInsets.all(32), diff --git a/lib/views/widgets/equipment/single_device_picker.dart b/lib/views/widgets/equipment/single_device_picker.dart index d8ca8491..5b812e39 100644 --- a/lib/views/widgets/equipment/single_device_picker.dart +++ b/lib/views/widgets/equipment/single_device_picker.dart @@ -2,7 +2,6 @@ import 'package:flutter/material.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:provider/provider.dart'; import 'package:test_sa/api/devices_api_client.dart'; -import 'package:test_sa/api/user_api_client.dart'; import '../../../controllers/localization/localization.dart'; import '../../../controllers/providers/api/devices_provider.dart'; @@ -36,7 +35,7 @@ class SingleDevicePickerState extends State { builder: (dialogContext) { return const Center(child: CircularProgressIndicator()); }); - List devices = await _devicesProvider.getDevicesListBySN(hospitalId: UserApiClient().user?.hospital?.id ?? "", serialNumber: result); + List devices = await _devicesProvider.getDevicesListBySN(serialNumber: result); Navigator.of(context).pop(); if (devices.isEmpty) { Fluttertoast.showToast(msg: _subtitle?.noDeviceFound ?? ""); @@ -67,7 +66,7 @@ class SingleDevicePickerState extends State { stateCode: _devicesProvider.stateCode, onRefresh: () async { _devicesProvider.reset(); - await _devicesProvider.getEquipment(hospitalId: UserApiClient().user?.hospital?.id); + await _devicesProvider.getEquipment(); }, child: Column( children: [ diff --git a/lib/views/widgets/pentry/pentry_calibration_tool_form.dart b/lib/views/widgets/pentry/pentry_calibration_tool_form.dart index d9cfc092..968ff1b5 100644 --- a/lib/views/widgets/pentry/pentry_calibration_tool_form.dart +++ b/lib/views/widgets/pentry/pentry_calibration_tool_form.dart @@ -1,7 +1,6 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; -import '../../../api/user_api_client.dart'; import '../../../controllers/localization/localization.dart'; import '../../../controllers/providers/user_provider.dart'; import '../../../models/pantry/calibration_tools.dart'; @@ -73,7 +72,7 @@ class _PentryCalibrationToolFormState extends State { ), AutoCompleteDeviceNumberField( initialValue: model.assetsNumber, - hospitalId: UserApiClient().user?.hospital?.id, + hospitalId: /*UserApiClient().user?.hospital?.id*/ '', onPick: (number) { model.assetsNumber = number; }, diff --git a/lib/views/widgets/requests/service_request_item.dart b/lib/views/widgets/requests/service_request_item.dart index a3718f87..3067b10a 100644 --- a/lib/views/widgets/requests/service_request_item.dart +++ b/lib/views/widgets/requests/service_request_item.dart @@ -47,7 +47,7 @@ class ServiceRequestItem extends StatelessWidget { }, child: Row( children: [ - UserApiClient().user?.type == UsersTypes.normal_user && (request.devicePhotos?.isEmpty ?? true) + UserApiClient().user?.roles == UsersTypes.normal_user.name && (request.devicePhotos?.isEmpty ?? true) ? const SizedBox.shrink() : SizedBox( width: 80, @@ -72,7 +72,7 @@ class ServiceRequestItem extends StatelessWidget { ], ), - UserApiClient().user?.type == UsersTypes.engineer + UserApiClient().user?.roles == UsersTypes.engineer.name ? Material( color: onItemColor, elevation: 6, diff --git a/lib/views/widgets/visits/visit_item.dart b/lib/views/widgets/visits/visit_item.dart index 73db092d..4dc3d715 100644 --- a/lib/views/widgets/visits/visit_item.dart +++ b/lib/views/widgets/visits/visit_item.dart @@ -1,9 +1,7 @@ import 'package:flutter/material.dart'; -import 'package:provider/provider.dart'; import '../../../api/user_api_client.dart'; import '../../../controllers/localization/localization.dart'; -import '../../../controllers/providers/user_provider.dart'; import '../../../models/enums/user_types.dart'; import '../../../models/visits/visit.dart'; import '../../app_style/sizing.dart'; @@ -31,7 +29,6 @@ class VisitItem extends StatelessWidget { @override Widget build(BuildContext context) { - UserProvider userProvider = Provider.of(context); Color itemColor = index % 2 == 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.onPrimary; Color onItemColor = index % 2 != 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.onPrimary; final subtitle = AppLocalization.of(context)?.subtitle; @@ -46,13 +43,13 @@ class VisitItem extends StatelessWidget { ), ), onPressed: () { - if (activeSelectMod && UserApiClient().user?.type == UsersTypes.engineer) { + if (activeSelectMod && UserApiClient().user?.roles == UsersTypes.engineer.name) { onSelect(visit); } else { onPressed(visit); } }, - onLongPress: UserApiClient().user?.type == UsersTypes.engineer + onLongPress: UserApiClient().user?.roles == UsersTypes.engineer.name ? () { onLongPress(visit); }