Changing User Model

merge-requests/17/head
zaid_daoud 3 years ago
parent b8e253e685
commit 1a3232dbe1

@ -67,7 +67,7 @@ class ApiClient {
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 = true}) async {
{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);

@ -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<ServiceRequest> serviceRequestsPage = requestsListJson.map((request) => ServiceRequest.fromJson(request)).toList();

@ -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,
);
}

@ -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<List<Device>> getDevicesListBySN({required String? hospitalId, required String serialNumber}) {
Future<List<Device>> getDevicesListBySN({required String serialNumber}) {
final hospitalId = /*UserApiClient().user?.hospital?.id ??*/ "";
if (hospitalId == null) return Future.value(const []);
return DevicesApiClient().getDevicesListBySN(hospitalId: hospitalId, serialNumber: serialNumber);
}

@ -31,7 +31,7 @@ class UserProvider extends LoadingNotifier {
onSuccess: () {
if (context.mounted) {
Provider.of<SettingProvider>(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);

@ -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<String>? 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<String, dynamic> 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<String>?;
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<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
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<Map<String, dynamic>> toLoginJson() async {
if (FirebaseNotificationManger.token == null) await FirebaseNotificationManger.getToken();
@ -30,9 +148,9 @@ class User {
Map<String, dynamic> toUpdateProfileJson() {
Map<String, dynamic> 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<String, dynamic> 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<String, dynamic> 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);
}
}

@ -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<Register> {
},
),
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<Register> {
},
),
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 ?? "",

@ -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<GasRefillDetails> {
),
),
),
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,

@ -153,7 +153,7 @@ class _LandPageState extends State<LandPage> {
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<LandPage> {
// 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,

@ -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<NotificationsPage> with TickerProviderStateMixin {
NotificationsProvider? _notificationsProvider;
UserProvider? _userProvider;
SettingProvider? _settingProvider;
Subtitle? _subtitle;
@override
Widget build(BuildContext context) {
_notificationsProvider = Provider.of<NotificationsProvider>(context);
_userProvider = Provider.of<UserProvider>(context);
_settingProvider = Provider.of<SettingProvider>(context);
_subtitle = AppLocalization.of(context)?.subtitle;
return Scaffold(
@ -41,7 +38,7 @@ class _NotificationsPageState extends State<NotificationsPage> 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<NotificationsPage> 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<NotificationsPage> 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,

@ -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<ProfilePage> {
},
),
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<ProfilePage> {
},
),
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;
// },
// ),
],
),
),

@ -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<CreateRequestPage> {
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,

@ -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),

@ -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<SingleDevicePicker> {
builder: (dialogContext) {
return const Center(child: CircularProgressIndicator());
});
List<Device> devices = await _devicesProvider.getDevicesListBySN(hospitalId: UserApiClient().user?.hospital?.id ?? "", serialNumber: result);
List<Device> 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<SingleDevicePicker> {
stateCode: _devicesProvider.stateCode,
onRefresh: () async {
_devicesProvider.reset();
await _devicesProvider.getEquipment(hospitalId: UserApiClient().user?.hospital?.id);
await _devicesProvider.getEquipment();
},
child: Column(
children: [

@ -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<PentryCalibrationToolForm> {
),
AutoCompleteDeviceNumberField(
initialValue: model.assetsNumber,
hospitalId: UserApiClient().user?.hospital?.id,
hospitalId: /*UserApiClient().user?.hospital?.id*/ '',
onPick: (number) {
model.assetsNumber = number;
},

@ -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,

@ -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<UserProvider>(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);
}

Loading…
Cancel
Save