diff --git a/lib/controllers/providers/api/service_requests_provider.dart b/lib/controllers/providers/api/service_requests_provider.dart index 21b690a7..3a035551 100644 --- a/lib/controllers/providers/api/service_requests_provider.dart +++ b/lib/controllers/providers/api/service_requests_provider.dart @@ -623,7 +623,6 @@ class ServiceRequestsProvider extends ChangeNotifier { return null; } } catch (error) { - print(error); return null; } } diff --git a/lib/models/service_request/service_request.dart b/lib/models/service_request/service_request.dart index 78828a29..98457831 100644 --- a/lib/models/service_request/service_request.dart +++ b/lib/models/service_request/service_request.dart @@ -1,5 +1,6 @@ import 'package:test_sa/controllers/api_routes/urls.dart'; import 'package:test_sa/models/device/device.dart'; +import 'package:test_sa/models/fault_description.dart'; import 'package:test_sa/models/lookup.dart'; class ServiceRequest { @@ -27,8 +28,9 @@ class ServiceRequest { bool viewReport; String engineerMobile; String deviceModel; - String faultDescription; - String workPerformed; + FaultDescription faultDescription; + + //String workPerformed; String visitDate; DateTime nextVisitDate; String jobSheetNumber; @@ -68,7 +70,7 @@ class ServiceRequest { this.jobSheetNumber, this.visitDate, this.nextVisitDate, - this.workPerformed, + //this.workPerformed, this.reportID, this.defectType, this.priority, @@ -116,11 +118,16 @@ class ServiceRequest { viewReport: parsedJson["workOrder"] != null, deviceModel: parsedJson["asset"]["modelDefinition"]["modelName"], engineerMobile: parsedJson["assignedEmployee"] == null ? null : parsedJson["assignedEmployee"]["phone"], - faultDescription: parsedJson["workOrder"] != null ? parsedJson["workOrder"]["faultDescription"] : null, + faultDescription: parsedJson["workOrder"] != null + ? parsedJson["workOrder"]["faultDescription"] != null + ? FaultDescription.fromJson(parsedJson["workOrder"]["faultDescription"]) + : null + : null, + jobSheetNumber: parsedJson["workOrder"] != null ? parsedJson["workOrder"]["jobSheetNumber"] : null, visitDate: DateTime.tryParse(parsedJson["visitDate"] ?? "").toString().split(" ").first, nextVisitDate: DateTime.tryParse(parsedJson["nextVisitDate"] ?? ""), - workPerformed: parsedJson["workOrder"] != null ? parsedJson["workOrder"]["workPerformed"] : null, + //workPerformed: parsedJson["workOrder"] != null ? parsedJson["workOrder"]["workPerformed"] : null, device: Device.fromJson(parsedJson["asset"]), reviewComment: parsedJson["reviewComment"], type: Lookup.fromJson(parsedJson['typeofRequest']), diff --git a/lib/views/pages/user/requests/create_request.dart b/lib/views/pages/user/requests/create_request.dart index 96321251..db5b9fda 100644 --- a/lib/views/pages/user/requests/create_request.dart +++ b/lib/views/pages/user/requests/create_request.dart @@ -83,25 +83,25 @@ class CreateRequestPageState extends State { super.initState(); } - - getServiceRequestById(String id) async { - try { - ServiceRequest request = await _serviceRequestsProvider.getServiceRequestObjectById(requestId: id) ?? ""; - _serviceRequest = request; - _device = _serviceRequest.device; - _deviceImages.addAll(_serviceRequest.devicePhotos.map((e) { - return File(e); - }).toList()); - _showDatePicker = _serviceRequest.firstAction != null && _serviceRequest.firstAction.name == "Need a visit"; - if (_showDatePicker && _serviceRequest.visitDate != null) { - _dateTime = DateTime.tryParse(_serviceRequest.visitDate); - } - _isLoading = false; - } catch (ex) { - _isLoading = false; - } - setState(() {}); - } + // + // getServiceRequestById(String id) async { + // try { + // ServiceRequest request = await _serviceRequestsProvider.getServiceRequestObjectById(requestId: id) ?? ""; + // _serviceRequest = request; + // _device = _serviceRequest.device; + // _deviceImages.addAll(_serviceRequest.devicePhotos.map((e) { + // return File(e); + // }).toList()); + // _showDatePicker = _serviceRequest.firstAction != null && _serviceRequest.firstAction.name == "Need a visit"; + // if (_showDatePicker && _serviceRequest.visitDate != null) { + // _dateTime = DateTime.tryParse(_serviceRequest.visitDate); + // } + // _isLoading = false; + // } catch (ex) { + // _isLoading = false; + // } + // setState(() {}); + // } @override void dispose() { @@ -121,13 +121,7 @@ class CreateRequestPageState extends State { _userProvider = Provider.of(context); _settingProvider = Provider.of(context); _subtitle = AppLocalization.of(context).subtitle; - if (_serviceRequestsProvider == null) { - _serviceRequestsProvider = Provider.of(context); - if (widget.serviceRequest?.id != null) { - _isLoading = true; - getServiceRequestById(widget.serviceRequest.id); - } - } + _serviceRequestsProvider = Provider.of(context); return Scaffold( key: _scaffoldKey, diff --git a/lib/views/pages/user/requests/request_details.dart b/lib/views/pages/user/requests/request_details.dart index a794e5f5..de049dca 100644 --- a/lib/views/pages/user/requests/request_details.dart +++ b/lib/views/pages/user/requests/request_details.dart @@ -6,6 +6,7 @@ import 'package:test_sa/controllers/providers/api/service_requests_provider.dart import 'package:test_sa/controllers/providers/api/user_provider.dart'; import 'package:test_sa/controllers/providers/settings/setting_provider.dart'; import 'package:test_sa/extensions/int_extensions.dart'; +import 'package:test_sa/extensions/widget_extensions.dart'; import 'package:test_sa/models/enums/user_types.dart'; import 'package:test_sa/models/service_request/service_request.dart'; import 'package:test_sa/models/subtitle.dart'; @@ -16,7 +17,9 @@ import 'package:test_sa/views/pages/user/requests/report/create_service_report.d import 'package:test_sa/views/widgets/buttons/app_back_button.dart'; import 'package:test_sa/views/widgets/buttons/app_button.dart'; import 'package:test_sa/views/widgets/buttons/app_icon_button.dart'; +import 'package:test_sa/views/widgets/images/files_list.dart'; import 'package:test_sa/views/widgets/images/images_list.dart'; +import 'package:test_sa/views/widgets/loaders/app_loading.dart'; import 'package:test_sa/views/widgets/loaders/image_loader.dart'; import 'package:test_sa/views/widgets/requests/info_row.dart'; import 'package:test_sa/views/widgets/requests/request_status.dart'; @@ -28,9 +31,9 @@ import 'report/future_service_report.dart'; class RequestDetailsPage extends StatelessWidget { static const String id = "/call-details"; - final ServiceRequest serviceRequest; + ServiceRequest serviceRequest; - const RequestDetailsPage({Key key, this.serviceRequest}) : super(key: key); + RequestDetailsPage({Key key, this.serviceRequest}) : super(key: key); @override Widget build(BuildContext context) { @@ -39,404 +42,423 @@ class RequestDetailsPage extends StatelessWidget { SettingProvider _settingProvider = Provider.of(context); List workOrders = []; ServiceRequestsProvider _serviceRequestsProvider = Provider.of(context); + _serviceRequestsProvider.getServiceRequestObjectById(requestId: serviceRequest.id); + return DefaultTabController( length: 2, child: Scaffold( body: SafeArea( - child: Column( - children: [ - Container( - color: AColors.primaryColor, - padding: const EdgeInsets.symmetric(horizontal: 0, vertical: 4), - child: Row( - children: [ - ABackButton(), - Expanded( - child: Center( - child: Text( - _subtitle.details, - style: Theme.of(context).textTheme.headline6.copyWith(color: AColors.white, fontStyle: FontStyle.italic), - ), - ), - ), - _userProvider.user.type == UsersTypes.normal_user - ? - // AIconButton( - // iconData: Icons.warning_amber_rounded, - // color: AColors.white, - // buttonSize: 42, - // backgroundColor: AColors.deepOrange, - // onPressed: (){ - // Navigator.of(context).push( - // MaterialPageRoute( - // builder: (_) => ReportIssuesPage(serviceRequest: serviceRequest,) - // ) - // ); - // }, - // ) - const SizedBox( - width: 48, - ) - : AIconButton( - iconData: Icons.edit, - color: AColors.white, - buttonSize: 42, - backgroundColor: AColors.green, - onPressed: () async { - Navigator.of(context).push( - MaterialPageRoute(builder: (_) => CreateRequestPage(serviceRequest: serviceRequest)), - ); - // showModalBottomSheet( - // context: context, - // builder: (context) { - // return ServiceRequestsUpdateDialog( - // request: serviceRequest, - // ); - // }); - // DateTime picked = await showDatePicker( - // context: context, - // initialDate: DateTime.now(), - // firstDate: DateTime.now(), - // lastDate: DateTime.now().add(Duration(days: 182)) - // ); - // if(picked == null){return;} - // showDialog( - // context: context, - // barrierDismissible: false, - // builder: (BuildContext context) { - // return CupertinoAlertDialog( - // title: Text(_subtitle.updatingDots), - // content: Center(child: CircularProgressIndicator()), - // ); - // }, - // ); - // int status = await _serviceRequestsProvider.updateDate( - // user: _userProvider.user, - // host: _settingProvider.host, - // request: serviceRequest, - // newDate: picked.toString().split(" ").first - // ); - // Navigator.of(context).pop(); - // Fluttertoast.showToast( - // msg: HttpStatusManger.getStatusMessage(status: status, subtitle: _subtitle), - // ); - }, - ), - SizedBox( - width: 16, - ) - ], - ), - ), - serviceRequest.devicePhotos.isEmpty - ? SizedBox.shrink() - : Column( - children: [ - SizedBox( - height: 8, - ), - MaterialButton( - padding: EdgeInsets.zero, - onPressed: () { - Navigator.of(context).push(MaterialPageRoute( - builder: (_) => Scaffold( - body: InteractiveViewer( - child: Center( - child: ImageLoader( - url: serviceRequest.devicePhotos.first, - boxFit: BoxFit.contain, - ), - ), - ), - ))); - }, - child: SizedBox( - height: 140 * AppStyle.getScaleFactor(context), - width: MediaQuery.of(context).size.width, - child: ImageLoader( - url: serviceRequest.devicePhotos.first, - boxFit: BoxFit.cover, - ), - ), - ), - SizedBox(height: 8), - SizedBox( - height: 60 * AppStyle.getScaleFactor(context), - child: ImagesList( - images: serviceRequest.devicePhotos, - ), - ), - ], - ), - TabBar(labelColor: AColors.primaryColor, tabs: [ - Tab( - text: _subtitle.general, - ), - Tab( - text: _subtitle.serviceRequestInformation, - ), - ]), - SizedBox( - height: 8, - ), - Expanded( - child: TabBarView( - children: [ - ListView( - padding: EdgeInsets.symmetric(horizontal: 16), - children: [ - RequestInfoRow( - title: _subtitle.callId, - info: serviceRequest.requestCode, - ), - RequestInfoRow( - title: "Asset Number", - info: serviceRequest.deviceNumber, - ), - RequestInfoRow( - title: _subtitle.assetName, - info: serviceRequest.deviceEnName, - ), - RequestInfoRow( - title: _subtitle.deviceModel, - info: serviceRequest.deviceModel, - ), - RequestInfoRow( - title: _subtitle.engineerName, - info: serviceRequest.engineerName, - ), - RequestInfoRow( - title: _subtitle.engineerPhone, - info: serviceRequest.engineerMobile, - ), - RequestInfoRow( - title: _subtitle.date, - info: serviceRequest.date, - ), - serviceRequest.nextVisitDate == null - ? SizedBox.shrink() - : RequestInfoRow( - title: _subtitle.nextVisitDate, - info: DateFormat('EE dd/MM/yyyy').format(serviceRequest.nextVisitDate), - ), - Row( + child: FutureBuilder( + future: _serviceRequestsProvider.getServiceRequestObjectById(requestId: serviceRequest.id), + builder: (context, snap) { + if (snap.connectionState == ConnectionState.waiting) { + return const ALoading(); + } else if (snap.hasData) { + serviceRequest = snap.data; + return Column( + children: [ + Container( + color: AColors.primaryColor, + padding: const EdgeInsets.symmetric(horizontal: 0, vertical: 4), + child: Row( children: [ + ABackButton(), Expanded( - child: Text( - "${_subtitle.status} : ", - style: Theme.of(context).textTheme.subtitle1, - textScaleFactor: AppStyle.getScaleFactor(context), + child: Center( + child: Text( + _subtitle.details, + style: Theme.of(context).textTheme.headline6.copyWith(color: AColors.white, fontStyle: FontStyle.italic), + ), ), ), - StatusLabel(label: serviceRequest.statusLabel, color: AColors.getRequestStatusColor(serviceRequest.statusValue)), + _userProvider.user.type == UsersTypes.normal_user + ? + // AIconButton( + // iconData: Icons.warning_amber_rounded, + // color: AColors.white, + // buttonSize: 42, + // backgroundColor: AColors.deepOrange, + // onPressed: (){ + // Navigator.of(context).push( + // MaterialPageRoute( + // builder: (_) => ReportIssuesPage(serviceRequest: serviceRequest,) + // ) + // ); + // }, + // ) + const SizedBox( + width: 48, + ) + : AIconButton( + iconData: Icons.edit, + color: AColors.white, + buttonSize: 42, + backgroundColor: AColors.green, + onPressed: () async { + Navigator.of(context).push( + MaterialPageRoute(builder: (_) => CreateRequestPage(serviceRequest: serviceRequest)), + ); + // showModalBottomSheet( + // context: context, + // builder: (context) { + // return ServiceRequestsUpdateDialog( + // request: serviceRequest, + // ); + // }); + // DateTime picked = await showDatePicker( + // context: context, + // initialDate: DateTime.now(), + // firstDate: DateTime.now(), + // lastDate: DateTime.now().add(Duration(days: 182)) + // ); + // if(picked == null){return;} + // showDialog( + // context: context, + // barrierDismissible: false, + // builder: (BuildContext context) { + // return CupertinoAlertDialog( + // title: Text(_subtitle.updatingDots), + // content: Center(child: CircularProgressIndicator()), + // ); + // }, + // ); + // int status = await _serviceRequestsProvider.updateDate( + // user: _userProvider.user, + // host: _settingProvider.host, + // request: serviceRequest, + // newDate: picked.toString().split(" ").first + // ); + // Navigator.of(context).pop(); + // Fluttertoast.showToast( + // msg: HttpStatusManger.getStatusMessage(status: status, subtitle: _subtitle), + // ); + }, + ), + SizedBox( + width: 16, + ) ], ), - Divider( - color: Theme.of(context).primaryColor, - ), - RequestInfoRow( - title: _subtitle.hospital, - info: serviceRequest.hospitalName, - ), - RequestInfoRow( - title: _subtitle.unite, - info: serviceRequest.departmentName, + ), + serviceRequest.devicePhotos.isEmpty + ? const SizedBox.shrink() + : SizedBox( + height: 60 * AppStyle.getScaleFactor(context), + child: FilesList( + images: serviceRequest.devicePhotos, + ), + ).paddingOnly(top: 4, bottom: 4), + + // Column( + // children: [ + // SizedBox( + // height: 8, + // ), + // MaterialButton( + // padding: EdgeInsets.zero, + // onPressed: () { + // Navigator.of(context).push(MaterialPageRoute( + // builder: (_) => Scaffold( + // body: InteractiveViewer( + // child: Center( + // child: ImageLoader( + // url: serviceRequest.devicePhotos.first, + // boxFit: BoxFit.contain, + // ), + // ), + // ), + // ))); + // }, + // child: SizedBox( + // height: 140 * AppStyle.getScaleFactor(context), + // width: MediaQuery.of(context).size.width, + // child: ImageLoader( + // url: serviceRequest.devicePhotos.first, + // boxFit: BoxFit.cover, + // ), + // ), + // ), + // SizedBox(height: 8), + // SizedBox( + // height: 60 * AppStyle.getScaleFactor(context), + // child: FilesList( + // images: serviceRequest.devicePhotos, + // ), + // ), + // ], + // ), + TabBar(labelColor: AColors.primaryColor, tabs: [ + Tab( + text: _subtitle.general, ), - // RequestInfoRow( - // title: _subtitle.deviceArName, - // content: serviceRequest.deviceArName, - // ), - // RequestInfoRow( - // title: _subtitle.deviceName, - // content: serviceRequest.deviceEnName, - // ), - RequestInfoRow( - title: _subtitle.maintenanceIssue, - content: serviceRequest.callComments, + Tab( + text: _subtitle.serviceRequestInformation, ), - if (serviceRequest.audio?.isNotEmpty == true) - ASoundPlayer( - audio: serviceRequest.audio, - ), - // - // Center( - // child: Padding( - // padding: EdgeInsets.all(32), - // child: AButton( - // text: _subtitle.duplicateRequest, - // onPressed: () async { - // bool result = await showDialog( - // context: context, - // builder: (_) => AAlertDialog( - // title: _subtitle.duplicateAlert, - // content: _subtitle.duplicateAlertMessage, - // ) - // ); - // if(result == true){ - // showDialog( - // context: context, - // builder: (context){ - // return Center(child: CircularProgressIndicator()); - // } - // ); - // int status = await _serviceRequestsProvider.createDuplicatedReport( - // host: _settingProvider.host, - // user: _userProvider.user, - // request: serviceRequest - // ); - // Navigator.of(context).pop(); - // ScaffoldMessenger.of(context).showSnackBar( - // SnackBar( - // content: Text( - // HttpStatusManger.getStatusMessage(status: status, subtitle: _subtitle) - // ) - // ) - // ); - // } - // }, - // ), - // ), - // ) - ], - ), - // workOrders.isEmpty ? - FutureBuilder( - future: _serviceRequestsProvider.searchWorkOrders(callId: serviceRequest.requestCode), - builder: (context, snap) { - workOrders = snap.data as List; - if (snap.connectionState == ConnectionState.waiting) return Center(child: CircularProgressIndicator()); - if (snap.connectionState == ConnectionState.done && (snap.data?.length ?? 0) != 0) { - return SingleChildScrollView( - child: Column( + ]), + SizedBox( + height: 8, + ), + Expanded( + child: TabBarView( + children: [ + ListView( + padding: EdgeInsets.symmetric(horizontal: 16), children: [ - ListView.separated( - shrinkWrap: true, - physics: const NeverScrollableScrollPhysics(), - padding: EdgeInsets.all(21), - itemCount: workOrders.length, - separatorBuilder: (czt, index) => 21.height, - itemBuilder: (context, index) { - 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; - - return ElevatedButton( - style: ElevatedButton.styleFrom( - padding: EdgeInsets.symmetric(vertical: 8, horizontal: 8), - primary: itemColor.withOpacity(.7), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(AppStyle.getBorderRadius(context)), - ), - ), - //padding: EdgeInsets.symmetric(vertical: 8,horizontal: 8), - onPressed: () { - // onPressed(request); - }, - child: Column( - children: [ - RequestInfoRow( - title: _subtitle.callId, - content: serviceRequest.requestCode, - ), - RequestInfoRow( - title: _subtitle.orderWorkNumber, - info: workOrders[index].workOrderNo.toString(), - ), - RequestInfoRow( - title: _subtitle.visitDate, - info: workOrders[index].visitDate, - ), - RequestInfoRow(title: _subtitle.assignedEmployee, info: workOrders[index].assignedEmployee?.name ?? ""), - RequestInfoRow( - title: _subtitle.assetSN, - info: workOrders[index].callRequest.asset.assetSerialNo, - ), - RequestInfoRow( - title: _subtitle.assetName, - info: workOrders[index].callRequest.asset.modelDefinition.assetName, - ), - RequestInfoRow( - title: _subtitle.assetNumber, - info: workOrders[index].callRequest.asset.assetNumber, - ), - RequestInfoRow( - title: _subtitle.model, - info: workOrders[index].callRequest.asset.modelDefinition.modelName, - ), - RequestInfoRow( - title: _subtitle.site, - info: workOrders[index].callRequest.asset.site.custName, - ), - RequestInfoRow( - title: "Call last Situation", - info: workOrders[index].currentSituation.name ?? '', - ), - _userProvider.user.type == UsersTypes.engineer && workOrders[index].workOrderNo != null - ? Padding( - padding: EdgeInsets.all(32), - child: AButton( - text: _subtitle.editServiceReport, - onPressed: () { - Navigator.of(context).push( - MaterialPageRoute( - builder: (_) => FutureServiceReport( - request: serviceRequest, - workOrder: workOrders[index], - )), - ); - }, - ), - ) - : SizedBox.shrink(), - ], - ), - ); - }, + RequestInfoRow( + title: _subtitle.callId, + info: serviceRequest.requestCode, + ), + RequestInfoRow( + title: "Asset Number", + info: serviceRequest.deviceNumber, + ), + RequestInfoRow( + title: _subtitle.assetName, + info: serviceRequest.deviceEnName, + ), + RequestInfoRow( + title: _subtitle.deviceModel, + info: serviceRequest.deviceModel, ), - if (_userProvider.user.type == UsersTypes.engineer) - Center( - child: Padding( - padding: const EdgeInsets.all(32), - child: AButton( - text: "Create Work Order", - onPressed: () { - Navigator.of(context).push(MaterialPageRoute(builder: (_) => CreateServiceReport(request: serviceRequest))); - }, + RequestInfoRow( + title: _subtitle.engineerName, + info: serviceRequest.engineerName, + ), + RequestInfoRow( + title: _subtitle.engineerPhone, + info: serviceRequest.engineerMobile, + ), + RequestInfoRow( + title: _subtitle.date, + info: serviceRequest.date, + ), + serviceRequest.nextVisitDate == null + ? SizedBox.shrink() + : RequestInfoRow( + title: _subtitle.nextVisitDate, + info: DateFormat('EE dd/MM/yyyy').format(serviceRequest.nextVisitDate), + ), + Row( + children: [ + Expanded( + child: Text( + "${_subtitle.status} : ", + style: Theme.of(context).textTheme.subtitle1, + textScaleFactor: AppStyle.getScaleFactor(context), ), ), + StatusLabel(label: serviceRequest.statusLabel, color: AColors.getRequestStatusColor(serviceRequest.statusValue)), + ], + ), + Divider( + color: Theme.of(context).primaryColor, + ), + RequestInfoRow( + title: _subtitle.hospital, + info: serviceRequest.hospitalName, + ), + RequestInfoRow( + title: _subtitle.unite, + info: serviceRequest.departmentName, + ), + // RequestInfoRow( + // title: _subtitle.deviceArName, + // content: serviceRequest.deviceArName, + // ), + // RequestInfoRow( + // title: _subtitle.deviceName, + // content: serviceRequest.deviceEnName, + // ), + RequestInfoRow( + title: _subtitle.maintenanceIssue, + content: serviceRequest.callComments, + ), + if (serviceRequest.audio?.isNotEmpty == true) + ASoundPlayer( + audio: serviceRequest.audio, ), + // + // Center( + // child: Padding( + // padding: EdgeInsets.all(32), + // child: AButton( + // text: _subtitle.duplicateRequest, + // onPressed: () async { + // bool result = await showDialog( + // context: context, + // builder: (_) => AAlertDialog( + // title: _subtitle.duplicateAlert, + // content: _subtitle.duplicateAlertMessage, + // ) + // ); + // if(result == true){ + // showDialog( + // context: context, + // builder: (context){ + // return Center(child: CircularProgressIndicator()); + // } + // ); + // int status = await _serviceRequestsProvider.createDuplicatedReport( + // host: _settingProvider.host, + // user: _userProvider.user, + // request: serviceRequest + // ); + // Navigator.of(context).pop(); + // ScaffoldMessenger.of(context).showSnackBar( + // SnackBar( + // content: Text( + // HttpStatusManger.getStatusMessage(status: status, subtitle: _subtitle) + // ) + // ) + // ); + // } + // }, + // ), + // ), + // ) ], ), - ); - } else { - return Column( - children: [ - Expanded( - child: Center( - child: ASubTitle(_subtitle.dataNotFound), - ), - ), - if (_userProvider.user.type == UsersTypes.engineer) - Center( - child: Padding( - padding: const EdgeInsets.all(32), - child: AButton( - text: "Create Work Order", - onPressed: () { - Navigator.of(context).push(MaterialPageRoute(builder: (_) => CreateServiceReport(request: serviceRequest))); - }, + // workOrders.isEmpty ? + FutureBuilder( + future: _serviceRequestsProvider.searchWorkOrders(callId: serviceRequest.requestCode), + builder: (context, snap) { + workOrders = snap.data as List; + if (snap.connectionState == ConnectionState.waiting) return Center(child: CircularProgressIndicator()); + if (snap.connectionState == ConnectionState.done && (snap.data?.length ?? 0) != 0) { + return SingleChildScrollView( + child: Column( + children: [ + ListView.separated( + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + padding: EdgeInsets.all(21), + itemCount: workOrders.length, + separatorBuilder: (czt, index) => 21.height, + itemBuilder: (context, index) { + 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; + + return ElevatedButton( + style: ElevatedButton.styleFrom( + padding: EdgeInsets.symmetric(vertical: 8, horizontal: 8), + primary: itemColor.withOpacity(.7), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(AppStyle.getBorderRadius(context)), + ), + ), + //padding: EdgeInsets.symmetric(vertical: 8,horizontal: 8), + onPressed: () { + // onPressed(request); + }, + child: Column( + children: [ + RequestInfoRow( + title: _subtitle.callId, + content: serviceRequest.requestCode, + ), + RequestInfoRow( + title: _subtitle.orderWorkNumber, + info: workOrders[index].workOrderNo.toString(), + ), + RequestInfoRow( + title: _subtitle.visitDate, + info: workOrders[index].visitDate, + ), + RequestInfoRow(title: _subtitle.assignedEmployee, info: workOrders[index].assignedEmployee?.name ?? ""), + RequestInfoRow( + title: _subtitle.assetSN, + info: workOrders[index].callRequest.asset.assetSerialNo, + ), + RequestInfoRow( + title: _subtitle.assetName, + info: workOrders[index].callRequest.asset.modelDefinition.assetName, + ), + RequestInfoRow( + title: _subtitle.assetNumber, + info: workOrders[index].callRequest.asset.assetNumber, + ), + RequestInfoRow( + title: _subtitle.model, + info: workOrders[index].callRequest.asset.modelDefinition.modelName, + ), + RequestInfoRow( + title: _subtitle.site, + info: workOrders[index].callRequest.asset.site.custName, + ), + RequestInfoRow( + title: "Call last Situation", + info: workOrders[index].currentSituation.name ?? '', + ), + _userProvider.user.type == UsersTypes.engineer && workOrders[index].workOrderNo != null + ? Padding( + padding: EdgeInsets.all(32), + child: AButton( + text: _subtitle.editServiceReport, + onPressed: () { + Navigator.of(context).push( + MaterialPageRoute( + builder: (_) => FutureServiceReport( + request: serviceRequest, + workOrder: workOrders[index], + )), + ); + }, + ), + ) + : SizedBox.shrink(), + ], + ), + ); + }, + ), + if (_userProvider.user.type == UsersTypes.engineer) + Center( + child: Padding( + padding: const EdgeInsets.all(32), + child: AButton( + text: "Create Work Order", + onPressed: () { + Navigator.of(context).push(MaterialPageRoute(builder: (_) => CreateServiceReport(request: serviceRequest))); + }, + ), + ), + ), + ], ), - ), - ), - ], - ); - } - }, - ), - ], - ), - ), - ], - ), + ); + } else { + return Column( + children: [ + Expanded( + child: Center( + child: ASubTitle(_subtitle.dataNotFound), + ), + ), + if (_userProvider.user.type == UsersTypes.engineer) + Center( + child: Padding( + padding: const EdgeInsets.all(32), + child: AButton( + text: "Create Work Order", + onPressed: () { + Navigator.of(context).push(MaterialPageRoute(builder: (_) => CreateServiceReport(request: serviceRequest))); + }, + ), + ), + ), + ], + ); + } + }, + ), + ], + ), + ), + ], + ); + } + return const SizedBox(); + }), ), ), ); diff --git a/lib/views/widgets/images/files_list.dart b/lib/views/widgets/images/files_list.dart new file mode 100644 index 00000000..70bf5305 --- /dev/null +++ b/lib/views/widgets/images/files_list.dart @@ -0,0 +1,73 @@ +import 'dart:io'; + +import 'package:flutter/material.dart'; +import 'package:fluttertoast/fluttertoast.dart'; +import 'package:open_file/open_file.dart'; +import 'package:test_sa/extensions/widget_extensions.dart'; +import 'package:test_sa/views/app_style/sizing.dart'; +import 'package:test_sa/views/widgets/buttons/app_back_button.dart'; +import 'package:test_sa/views/widgets/loaders/image_loader.dart'; +import 'package:url_launcher/url_launcher.dart'; + +import 'image_item.dart'; +import 'images_viewer.dart'; + +class FilesList extends StatelessWidget { + final List images; + final EdgeInsets padding; + + const FilesList({Key key, this.images, this.padding}) : super(key: key); + + @override + Widget build(BuildContext context) { + return ListView.builder( + padding: padding ?? EdgeInsets.symmetric(horizontal: 32 * AppStyle.getScaleFactor(context)), + scrollDirection: Axis.horizontal, + itemCount: images.length, + itemBuilder: (context, itemIndex) { + var isImage = + images[itemIndex].split(".").last.toLowerCase() == "png" || images[itemIndex].split(".").last.toLowerCase() == "jpg" || images[itemIndex].split(".").last.toLowerCase() == "jpeg"; + var isPdf = images[itemIndex].split(".").last.toLowerCase() == "pdf"; + var isExcel = images[itemIndex].split(".").last.toLowerCase() == "xlsx"; + + return (isImage + ? (_isLocalUrl(images[itemIndex]) + ? Image.file(File(images[itemIndex])) + : ImageLoader( + url: images[itemIndex], + boxFit: BoxFit.cover, + )) + : Image.asset("assets/images/${isPdf ? "pdf" : isExcel ? "excel" : "doc"}.png")) + .onPress(() async { + if (isImage) { + Navigator.of(context).push( + MaterialPageRoute( + builder: (_) => Scaffold( + body: SafeArea( + child: Stack( + children: [ + InteractiveViewer(child: Image(image: (_isLocalUrl(images[itemIndex]) ? FileImage(File(images[itemIndex])) : NetworkImage(images[itemIndex])))).center, + const ABackButton(), + ], + ), + ), + ), + ), + ); + } else if (_isLocalUrl(images[itemIndex])) { + OpenFile.open(images[itemIndex]); + } else { + if (!await launchUrl(Uri.parse(images[itemIndex]), mode: LaunchMode.externalApplication)) { + Fluttertoast.showToast(msg: "UnExpected Error with file."); + throw Exception('Could not launch '); + } + } + }); + }); + } + + bool _isLocalUrl(String url) { + if (url?.isEmpty != false) return false; + return url.startsWith("/") || url.startsWith("file://") || url.substring(1).startsWith(':\\'); + } +} diff --git a/lib/views/widgets/images/multi_image_picker_item.dart b/lib/views/widgets/images/multi_image_picker_item.dart index 5cddee73..d5b00011 100644 --- a/lib/views/widgets/images/multi_image_picker_item.dart +++ b/lib/views/widgets/images/multi_image_picker_item.dart @@ -7,6 +7,7 @@ import 'package:test_sa/extensions/widget_extensions.dart'; import 'package:test_sa/views/app_style/colors.dart'; import 'package:test_sa/views/app_style/sizing.dart'; import 'package:test_sa/views/widgets/buttons/app_back_button.dart'; +import 'package:test_sa/views/widgets/loaders/image_loader.dart'; import 'package:url_launcher/url_launcher.dart'; class MultiFilesPickerItem extends StatelessWidget { @@ -43,7 +44,14 @@ class MultiFilesPickerItem extends StatelessWidget { body: SafeArea( child: Stack( children: [ - InteractiveViewer(child: Image(image: (_isLocalUrl(file.path) ? FileImage(file) : NetworkImage(file.path)))).center, + InteractiveViewer( + child: _isLocalUrl(file.path) + ? Image.file(file) + : ImageLoader( + url: file.path, + boxFit: BoxFit.cover, + )) + .center, const ABackButton(), ], ),