From 8d54c4411894e90eb937df6cdde6f4092d916e4d Mon Sep 17 00:00:00 2001 From: zaid_daoud Date: Tue, 28 Feb 2023 09:17:21 +0300 Subject: [PATCH] Create Request Screen --- .../pages/user/requests/create_request.dart | 61 +++++++++++++------ 1 file changed, 43 insertions(+), 18 deletions(-) diff --git a/lib/views/pages/user/requests/create_request.dart b/lib/views/pages/user/requests/create_request.dart index b39505ee..683755f1 100644 --- a/lib/views/pages/user/requests/create_request.dart +++ b/lib/views/pages/user/requests/create_request.dart @@ -30,7 +30,6 @@ import '../../../widgets/status/service_request/service_request_defect_types_mun import '../../../widgets/status/service_request/service_request_priority_mune.dart'; import '../../../widgets/titles/app_sub_title.dart'; - class CreateRequestPage extends StatefulWidget { static final String id = "/create-request"; @@ -46,7 +45,7 @@ class _CreateRequestPageState extends State { ServiceRequest _serviceRequest = ServiceRequest(); List _deviceImages = []; bool _isLoading = false; - late Device _device; + Device? _device; late Subtitle _subtitle; final GlobalKey _formKey = GlobalKey(); final GlobalKey _scaffoldKey = GlobalKey(); @@ -101,7 +100,12 @@ class _CreateRequestPageState extends State { padding: const EdgeInsets.all(8.0), child: Text( _subtitle.newServiceRequest, - style: Theme.of(context).textTheme.headline5?.copyWith(color: AColors.cyan, fontWeight: FontWeight.w600), + style: Theme.of(context) + .textTheme + .headline5 + ?.copyWith( + color: AColors.cyan, + fontWeight: FontWeight.w600), ), ), ), @@ -113,7 +117,9 @@ class _CreateRequestPageState extends State { ? SizedBox.shrink() : ATextFormField( enable: false, - initialValue: _userProvider.user?.hospital?.name ?? _subtitle.noHospitalFound, + initialValue: + _userProvider.user?.hospital?.name ?? + _subtitle.noHospitalFound, hintText: _subtitle.hospital, prefixIconData: FontAwesomeIcons.hospital, style: Theme.of(context).textTheme.subtitle1, @@ -123,7 +129,9 @@ class _CreateRequestPageState extends State { ? SizedBox.shrink() : ATextFormField( enable: false, - initialValue: _userProvider.user?.department?.name ?? _subtitle.noUniteFound, + initialValue: + _userProvider.user?.department?.name ?? + _subtitle.noUniteFound, hintText: _subtitle.unite, prefixIconData: FontAwesomeIcons.hospitalUser, style: Theme.of(context).textTheme.subtitle1, @@ -136,21 +144,29 @@ class _CreateRequestPageState extends State { setState(() {}); }, ), - const SizedBox(height: 8,), + const SizedBox( + height: 8, + ), const ASubTitle("Priority"), - const SizedBox(height: 4,), + const SizedBox( + height: 4, + ), ServiceRequestPriorityMenu( initialValue: _serviceRequest.priority, - onSelect: (status){ + onSelect: (status) { _serviceRequest.priority = status; }, ), - const SizedBox(height: 8,), + const SizedBox( + height: 8, + ), const ASubTitle("Defect Type"), - const SizedBox(height: 4,), + const SizedBox( + height: 4, + ), ServiceRequestDefectTypesMenu( initialValue: _serviceRequest.defectType, - onSelect: (status){ + onSelect: (status) { _serviceRequest.defectType = status; }, ), @@ -169,7 +185,9 @@ class _CreateRequestPageState extends State { prefixIconData: FontAwesomeIcons.triangleExclamation, style: Theme.of(context).textTheme.headline6, textInputType: TextInputType.multiline, - validator: (value) => Validator.hasValue(value!) ? '' : _subtitle.maintenanceIssueRequired, + validator: (value) => Validator.hasValue(value!) + ? '' + : _subtitle.maintenanceIssueRequired, onSaved: (value) { _serviceRequest.maintenanceIssue = value; }, @@ -186,19 +204,24 @@ class _CreateRequestPageState extends State { child: AButton( text: _subtitle.submit, onPressed: () async { - if (!(_formKey.currentState?.validate()??false)) return; + if (!(_formKey.currentState?.validate() ?? false)) + return; _formKey.currentState?.save(); _serviceRequest.deviceId = _device?.id ?? ""; _isLoading = true; setState(() {}); - _serviceRequest.devicePhotos = _deviceImages.map((e) => base64Encode(e.readAsBytesSync())).toList(); + _serviceRequest.devicePhotos = _deviceImages + .map((e) => base64Encode(e.readAsBytesSync())) + .toList(); if (_serviceRequest.audio != null) { final file = File(_serviceRequest.audio!); - _serviceRequest.audio = base64Encode(file.readAsBytesSync()); + _serviceRequest.audio = + base64Encode(file.readAsBytesSync()); } - int status = await _serviceRequestsProvider.createRequest( + int status = + await _serviceRequestsProvider.createRequest( user: _userProvider.user!, - host: _settingProvider.host??"", + host: _settingProvider.host ?? "", serviceRequest: _serviceRequest, ); _isLoading = false; @@ -209,7 +232,9 @@ class _CreateRequestPageState extends State { ); Navigator.of(context).pop(); } else { - String errorMessage = HttpStatusManger.getStatusMessage(status: status, subtitle: _subtitle); + String errorMessage = + HttpStatusManger.getStatusMessage( + status: status, subtitle: _subtitle); ScaffoldMessenger.of(context).showSnackBar(SnackBar( content: Text(errorMessage), ));