You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
397 lines
21 KiB
Dart
397 lines
21 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:test_sa/controllers/providers/api/all_requests_provider.dart';
|
|
import 'package:test_sa/controllers/providers/api/comments_provider.dart';
|
|
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/extensions/context_extension.dart';
|
|
import 'package:test_sa/extensions/int_extensions.dart';
|
|
import 'package:test_sa/extensions/string_extensions.dart';
|
|
import 'package:test_sa/extensions/text_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/new_views/app_style/app_color.dart';
|
|
import 'package:test_sa/new_views/common_widgets/app_filled_button.dart';
|
|
import 'package:test_sa/new_views/common_widgets/default_app_bar.dart';
|
|
import 'package:test_sa/service_request_latest/views/components/bottom_sheets/service_request_bottomsheet.dart';
|
|
import 'package:test_sa/service_request_latest/views/components/verify_otp_view.dart';
|
|
import 'package:test_sa/views/pages/user/requests/comments_bottom_sheet.dart';
|
|
import 'package:test_sa/views/pages/user/requests/update_service_request_page.dart';
|
|
import 'package:test_sa/views/pages/user/requests/work_order/work_orders_list_page.dart';
|
|
import 'package:test_sa/views/widgets/images/files_list.dart';
|
|
import 'package:test_sa/views/widgets/loaders/app_loading.dart';
|
|
import 'package:test_sa/views/widgets/requests/request_status.dart';
|
|
import 'package:test_sa/views/widgets/sound/sound_player.dart';
|
|
|
|
class RequestDetailView extends StatefulWidget {
|
|
static const String id = "/call-details";
|
|
ServiceRequest serviceRequest;
|
|
bool fromTabView = false;
|
|
|
|
RequestDetailView({Key? key, required this.serviceRequest, this.fromTabView = false}) : super(key: key);
|
|
|
|
@override
|
|
State<RequestDetailView> createState() => _RequestDetailViewState();
|
|
}
|
|
|
|
class _RequestDetailViewState extends State<RequestDetailView> {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
getServiceRequest(requestId: widget.serviceRequest.id);
|
|
}
|
|
|
|
void getServiceRequest({required dynamic requestId}) {
|
|
// setState(() {});
|
|
WidgetsFlutterBinding.ensureInitialized().addPostFrameCallback((timeStamp) async {
|
|
Provider.of<CommentsProvider>(context, listen: false).reset();
|
|
ServiceRequestsProvider serviceRequestsProvider = Provider.of<ServiceRequestsProvider>(context, listen: false);
|
|
serviceRequestsProvider.currentSelectedRequest = await serviceRequestsProvider.getServiceRequestObjectById(requestId: requestId);
|
|
// setState(() {});
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
UserProvider userProvider = Provider.of<UserProvider>(context, listen: false);
|
|
return !widget.fromTabView
|
|
? Scaffold(
|
|
appBar: DefaultAppBar(title: context.translation.serviceDetails),
|
|
body: Padding(
|
|
padding: EdgeInsets.only(top: 12.toScreenHeight),
|
|
child: Consumer<ServiceRequestsProvider>(builder: (context, serviceRequestsProvider, child) {
|
|
return requestDetailCard(serviceRequestsProvider: serviceRequestsProvider, userProvider: userProvider);
|
|
}),
|
|
),
|
|
)
|
|
: Consumer<ServiceRequestsProvider>(builder: (context, serviceRequestsProvider, child) {
|
|
return requestDetailCard(serviceRequestsProvider: serviceRequestsProvider, userProvider: userProvider);
|
|
});
|
|
}
|
|
|
|
Widget requestDetailCard({required ServiceRequestsProvider serviceRequestsProvider, required UserProvider userProvider}) {
|
|
return SafeArea(
|
|
child: serviceRequestsProvider.isDetialLoading
|
|
? const ALoading().center
|
|
: serviceRequestsProvider.currentSelectedRequest == null
|
|
? Text(
|
|
context.translation.noDataFound,
|
|
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20),
|
|
).center
|
|
: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
SingleChildScrollView(
|
|
padding: EdgeInsets.symmetric(horizontal: 16.toScreenWidth),
|
|
child: informationCard(serviceRequestsProvider.currentSelectedRequest!, userProvider),
|
|
).expanded,
|
|
Center(
|
|
child: InkWell(
|
|
onTap: () async {
|
|
try {
|
|
//use a common list
|
|
AllRequestsProvider allRequestProvider = Provider.of<AllRequestsProvider>(context, listen: false);
|
|
int index = allRequestProvider.requestDetailList!.requestsDetails!.indexWhere((element) => element.id.toString() == serviceRequestsProvider.currentSelectedRequest?.id);
|
|
if (index != -1 && index != allRequestProvider.requestDetailList!.requestsDetails!.length) {
|
|
getServiceRequest(requestId: allRequestProvider.requestDetailList!.requestsDetails![index + 1].id.toString());
|
|
}
|
|
} catch (e) {
|
|
print(e);
|
|
}
|
|
},
|
|
child: Text(
|
|
context.translation.skipForLater,
|
|
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20, decoration: TextDecoration.underline, fontSize: 16),
|
|
),
|
|
),
|
|
),
|
|
20.height,
|
|
if (userProvider.user!.type == UsersTypes.engineer ||
|
|
(serviceRequestsProvider.currentSelectedRequest?.statusValue == 5 || serviceRequestsProvider.currentSelectedRequest?.statusValue == 3))
|
|
(serviceRequestsProvider.currentSelectedRequest?.firstAction == null
|
|
? Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
AppFilledButton(
|
|
label: context.translation.reject,
|
|
maxWidth: true,
|
|
buttonColor: Colors.white54,
|
|
textColor: AppColor.red50,
|
|
showBorder: true,
|
|
onPressed: () async {
|
|
ServiceRequestBottomSheet.rejectRequestBottomSheet(context: context);
|
|
// bool shouldReloadData = (await showModalBottomSheet(
|
|
// context: context,
|
|
// useSafeArea: true,
|
|
// isScrollControlled: true,
|
|
// backgroundColor: Colors.transparent,
|
|
// builder: (context) => RejectRequestBottomSheet(),
|
|
// )) as bool;
|
|
// if (shouldReloadData ?? false) {
|
|
// getServiceRequest();
|
|
// }
|
|
},
|
|
).expanded,
|
|
const SizedBox(
|
|
width: 20,
|
|
),
|
|
AppFilledButton(
|
|
label: context.translation.accept,
|
|
maxWidth: true,
|
|
buttonColor: AppColor.green70,
|
|
onPressed: () async {
|
|
// GeneralUtils.showFlushBar(context: context);
|
|
Navigator.of(context).push(MaterialPageRoute(builder: (_) => const VerifyOtpView()));
|
|
|
|
// ServiceRequestBottomSheet.fixRemotelyBottomSheet(context: context);
|
|
// bool shouldReloadData = (await showModalBottomSheet(
|
|
// context: context,
|
|
// useSafeArea: true,
|
|
// isScrollControlled: true,
|
|
// backgroundColor: Colors.transparent,
|
|
// builder: (context) => InitialVisitBottomSheet(),
|
|
// )) as bool;
|
|
// if (shouldReloadData ?? false) {
|
|
// getServiceRequest();
|
|
// }
|
|
},
|
|
).expanded,
|
|
],
|
|
)
|
|
// ? AppFilledButton(
|
|
// label: context.translation.firstAction,
|
|
// maxWidth: true,
|
|
// onPressed: () async {
|
|
// bool shouldReloadData = (await showModalBottomSheet(
|
|
// context: context,
|
|
// useSafeArea: true,
|
|
// isScrollControlled: true,
|
|
// backgroundColor: Colors.transparent,
|
|
// builder: (context) => FirstActionBottomSheet(request: serviceRequestsProvider.serviceRequest),
|
|
// )) as bool;
|
|
// if (shouldReloadData ?? false) {
|
|
// getServiceRequest();
|
|
// }
|
|
// },
|
|
// )
|
|
: AppFilledButton(
|
|
label: context.translation.viewWorkOrder,
|
|
maxWidth: true,
|
|
onPressed: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(builder: (context) => WorkOrderListPage(serviceRequest: serviceRequestsProvider.currentSelectedRequest!)),
|
|
);
|
|
// Navigator.of(context).pushNamed(WorkOrderListPage.id, arguments: serviceRequest);
|
|
},
|
|
))
|
|
.paddingOnly(start: 16, end: 16, bottom: 24),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget informationCard(ServiceRequest serviceRequest, UserProvider userProvider) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
StatusLabel(
|
|
label: serviceRequest.priority?.name,
|
|
id: serviceRequest.priority!.id!,
|
|
radius: 4,
|
|
textColor: AppColor.getPriorityStatusTextColor(context, serviceRequest.priority!.id!),
|
|
backgroundColor: AppColor.getPriorityStatusColor(context, serviceRequest.priority!.id!),
|
|
),
|
|
8.width,
|
|
StatusLabel(
|
|
radius: 4,
|
|
label: serviceRequest.statusLabel!,
|
|
textColor: AppColor.getRequestStatusTextColor(context, serviceRequest.statusValue!),
|
|
backgroundColor: AppColor.getRequestStatusColor(context, serviceRequest.statusValue!),
|
|
),
|
|
1.width.expanded,
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
children: [
|
|
if (userProvider.user!.type == UsersTypes.normal_user)
|
|
context.translation.code.toSvgAsset(width: 48).onPress(() {
|
|
Navigator.push(context, MaterialPageRoute(builder: (context) => UpdateServiceRequestPage(serviceRequest: serviceRequest)));
|
|
}),
|
|
if (userProvider.user!.type == UsersTypes.engineer) 16.height,
|
|
Text(
|
|
serviceRequest.date!.toServiceRequestCardFormat,
|
|
textAlign: TextAlign.end,
|
|
style: AppTextStyles.tinyFont.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral50),
|
|
),
|
|
],
|
|
)
|
|
],
|
|
),
|
|
Text(
|
|
context.translation.assetDetails,
|
|
style: AppTextStyles.heading4.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral50),
|
|
),
|
|
8.height,
|
|
'${context.translation.assetName}: ${serviceRequest.deviceEnName?.cleanupWhitespace.capitalizeFirstOfEach}'.bodyText(context),
|
|
// 8.height,
|
|
Text(
|
|
'${context.translation.assetNumber}: ${serviceRequest.device?.assetNumber}',
|
|
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20),
|
|
),
|
|
|
|
Text(
|
|
'${context.translation.equipmentStatus}: ${serviceRequest.defectType?.name}',
|
|
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20),
|
|
),
|
|
Text(
|
|
'${context.translation.manufacture}: ${serviceRequest.device!.modelDefinition?.manufacturerName?.cleanupWhitespace.capitalizeFirstOfEach}',
|
|
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20),
|
|
),
|
|
Text(
|
|
'${context.translation.model}: ${serviceRequest.device!.modelDefinition?.modelName?.cleanupWhitespace.capitalizeFirstOfEach}',
|
|
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20),
|
|
),
|
|
Text(
|
|
'${context.translation.site}: ${serviceRequest.device!.site?.custName?.cleanupWhitespace.capitalizeFirstOfEach}',
|
|
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20),
|
|
),
|
|
Text(
|
|
'${context.translation.building}: ${serviceRequest.device!.building?.name?.cleanupWhitespace.capitalizeFirstOfEach}',
|
|
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20),
|
|
),
|
|
Text(
|
|
'${context.translation.floor}: ${serviceRequest.device!.floor?.name?.cleanupWhitespace.capitalizeFirstOfEach ?? ""}',
|
|
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20),
|
|
),
|
|
Text(
|
|
'${context.translation.department}: ${serviceRequest.device!.department?.departmentName?.cleanupWhitespace.capitalizeFirstOfEach}',
|
|
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20),
|
|
),
|
|
Text(
|
|
'${context.translation.room}: ${(serviceRequest.device!.room?.name ?? "").cleanupWhitespace.capitalizeFirstOfEach}',
|
|
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20),
|
|
),
|
|
],
|
|
).expanded,
|
|
],
|
|
),
|
|
8.height,
|
|
const Divider().defaultStyle(context),
|
|
|
|
//... request details starts here....
|
|
Text(
|
|
context.translation.requestDetail,
|
|
style: AppTextStyles.heading4.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral50),
|
|
),
|
|
8.height,
|
|
Text(
|
|
'${context.translation.requestType}: ${serviceRequest.type!.name}',
|
|
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20),
|
|
),
|
|
Text(
|
|
'${context.translation.requestNo}: ${serviceRequest.requestCode}',
|
|
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20),
|
|
),
|
|
Text(
|
|
'${context.translation.requesterName}: ${serviceRequest.callCreatedBy?.name ?? "-"}',
|
|
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20),
|
|
),
|
|
|
|
8.height,
|
|
if ((serviceRequest.callComments ?? "").isNotEmpty) ...[
|
|
const Divider().defaultStyle(context),
|
|
8.height,
|
|
Text(
|
|
serviceRequest.callComments!,
|
|
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20),
|
|
),
|
|
],
|
|
if (serviceRequest.devicePhotos?.isNotEmpty ?? false) ...[
|
|
8.height,
|
|
const Divider().defaultStyle(context),
|
|
FilesList(images: serviceRequest.devicePhotos!),
|
|
],
|
|
if (serviceRequest.audio?.isNotEmpty ?? false) ...[
|
|
const Divider().defaultStyle(context),
|
|
16.height,
|
|
ASoundPlayer(audio: serviceRequest.audio!),
|
|
8.height,
|
|
],
|
|
],
|
|
).paddingOnly(start: 16, end: 16, top: 16, bottom: 8),
|
|
(userProvider.user!.type == UsersTypes.normal_user
|
|
? Container(
|
|
height: 50,
|
|
padding: const EdgeInsets.only(left: 16, right: 16),
|
|
alignment: Alignment.center,
|
|
width: double.infinity,
|
|
decoration: ShapeDecoration(
|
|
color: context.isDark ? AppColor.neutral50 : AppColor.neutral30,
|
|
shape: const RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.only(
|
|
bottomLeft: Radius.circular(20),
|
|
bottomRight: Radius.circular(20),
|
|
),
|
|
),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Text(
|
|
'${context.translation.commentHere}...',
|
|
style: AppTextStyles.heading6.copyWith(
|
|
color: (context.isDark ? AppColor.neutral30 : AppColor.neutral50).withOpacity(.6),
|
|
),
|
|
).expanded,
|
|
"comment_send".toSvgAsset(width: 24, color: context.isDark ? AppColor.primary50 : AppColor.primary70),
|
|
],
|
|
),
|
|
)
|
|
: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const Divider().defaultStyle(context),
|
|
16.height,
|
|
Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Text(
|
|
context.translation.viewComments,
|
|
style: AppTextStyles.bodyText.copyWith(color: AppColor.blueStatus(context)),
|
|
),
|
|
4.width,
|
|
Icon(Icons.arrow_forward, color: AppColor.blueStatus(context), size: 14)
|
|
],
|
|
),
|
|
],
|
|
).paddingOnly(bottom: 16, start: 16, end: 16))
|
|
.onPress(() {
|
|
showModalBottomSheet(
|
|
context: context,
|
|
useSafeArea: true,
|
|
isScrollControlled: true,
|
|
useRootNavigator: true,
|
|
backgroundColor: Colors.transparent,
|
|
builder: (context) => CommentsBottomSheet(requestId: serviceRequest.id!),
|
|
);
|
|
}),
|
|
],
|
|
).toShadowContainer(context, padding: 0);
|
|
}
|
|
}
|