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.
269 lines
13 KiB
Dart
269 lines
13 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
import 'package:provider/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/views/app_style/colors.dart';
|
|
import 'package:test_sa/views/app_style/sizing.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';
|
|
|
|
import 'first_action_bottom_sheet.dart';
|
|
|
|
class ServiceRequestDetailsPage extends StatefulWidget {
|
|
static const String id = "/call-details";
|
|
ServiceRequest serviceRequest;
|
|
|
|
ServiceRequestDetailsPage({Key key, this.serviceRequest}) : super(key: key);
|
|
|
|
@override
|
|
State<ServiceRequestDetailsPage> createState() => _ServiceRequestDetailsPageState();
|
|
}
|
|
|
|
class _ServiceRequestDetailsPageState extends State<ServiceRequestDetailsPage> {
|
|
@override
|
|
void didChangeDependencies() {
|
|
Provider.of<CommentsProvider>(context, listen: false).reset();
|
|
super.didChangeDependencies();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
UserProvider _userProvider = Provider.of<UserProvider>(context);
|
|
ServiceRequestsProvider _serviceRequestsProvider = Provider.of<ServiceRequestsProvider>(context);
|
|
// _serviceRequestsProvider.getServiceRequestObjectById(requestId: serviceRequest.id);
|
|
|
|
Widget informationCard() {
|
|
return Container(
|
|
decoration: ShapeDecoration(
|
|
color: Colors.white,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(20),
|
|
),
|
|
shadows: const [BoxShadow(color: Color(0x07000000), blurRadius: 14, offset: Offset(0, 0), spreadRadius: 0)],
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
StatusLabel(
|
|
label: widget.serviceRequest.priority.name,
|
|
id: widget.serviceRequest.priority.id,
|
|
textColor: AColors.getPriorityStatusTextColor(widget.serviceRequest.priority.id),
|
|
backgroundColor: AColors.getPriorityStatusColor(widget.serviceRequest.priority.id)),
|
|
8.width,
|
|
StatusLabel(
|
|
label: widget.serviceRequest.statusLabel,
|
|
textColor: AColors.getRequestStatusTextColor(widget.serviceRequest.statusValue),
|
|
backgroundColor: AColors.getRequestStatusColor(widget.serviceRequest.statusValue)),
|
|
1.width.expanded,
|
|
],
|
|
),
|
|
8.height,
|
|
Text(widget.serviceRequest.deviceEnName, style: AppTextStyles.heading5.copyWith(color: const Color(0xFF3B3D4A))),
|
|
8.height,
|
|
Text(
|
|
'${context.translation.assetNumber}: ${widget.serviceRequest.device.assetNumber}',
|
|
style: AppTextStyles.bodyText.copyWith(color: Color(0xFF757575)),
|
|
),
|
|
Text(
|
|
'${context.translation.requestType}: ${widget.serviceRequest.type.name}',
|
|
style: AppTextStyles.bodyText.copyWith(color: Color(0xFF757575)),
|
|
),
|
|
Text(
|
|
'${context.translation.requestNo}: ${widget.serviceRequest.requestCode}',
|
|
style: AppTextStyles.bodyText.copyWith(color: Color(0xFF757575)),
|
|
),
|
|
],
|
|
).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: widget.serviceRequest)));
|
|
}),
|
|
if (_userProvider.user.type == UsersTypes.engineer) 16.height,
|
|
Text(widget.serviceRequest.date.toServiceRequestCardFormat, textAlign: TextAlign.end, style: AppTextStyles.tinyFont.copyWith(color: const Color(0xFF3B3D4A))),
|
|
],
|
|
)
|
|
],
|
|
),
|
|
8.height,
|
|
const Divider(color: Color(0xFFEAF1F4), height: 1, thickness: 1),
|
|
8.height,
|
|
Text(
|
|
'${context.translation.manufacture}: ${widget.serviceRequest.device.modelDefinition.manufacturerName}',
|
|
style: AppTextStyles.bodyText.copyWith(color: Color(0xFF757575)),
|
|
),
|
|
Text(
|
|
'${context.translation.model}: ${widget.serviceRequest.device.modelDefinition.modelName}',
|
|
style: AppTextStyles.bodyText.copyWith(color: Color(0xFF757575)),
|
|
),
|
|
8.height,
|
|
if ((widget.serviceRequest.callComments ?? "").isNotEmpty) ...[
|
|
const Divider(color: Color(0xFFEAF1F4), height: 1, thickness: 1),
|
|
8.height,
|
|
Text(
|
|
widget.serviceRequest.callComments,
|
|
style: AppTextStyles.bodyText.copyWith(color: Color(0xFF757575)),
|
|
),
|
|
],
|
|
if (widget.serviceRequest.devicePhotos.isNotEmpty) ...[
|
|
8.height,
|
|
const Divider(color: Color(0xFFEAF1F4), height: 1, thickness: 1),
|
|
FilesList(images: widget.serviceRequest.devicePhotos),
|
|
],
|
|
if (widget.serviceRequest.audio?.isNotEmpty ?? false) ...[
|
|
const Divider(color: Color(0xFFEAF1F4), height: 1, thickness: 1),
|
|
16.height,
|
|
ASoundPlayer(audio: widget.serviceRequest.audio),
|
|
],
|
|
],
|
|
).paddingAll(16),
|
|
(_userProvider.user.type == UsersTypes.normal_user
|
|
? Container(
|
|
height: 50,
|
|
padding: const EdgeInsets.only(left: 16, right: 16),
|
|
alignment: Alignment.center,
|
|
width: double.infinity,
|
|
decoration: const ShapeDecoration(
|
|
color: Color(0xFFEAF1F4),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.only(
|
|
bottomLeft: Radius.circular(20),
|
|
bottomRight: Radius.circular(20),
|
|
),
|
|
),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Text(
|
|
'${context.translation.viewComments}...',
|
|
style: AppTextStyles.heading6.copyWith(
|
|
color: AppColor.neutral50.withOpacity(.6),
|
|
),
|
|
).expanded,
|
|
SvgPicture.asset("assets/images/comment_send.svg", width: 24 * AppStyle.getScaleFactor(context), height: 24 * AppStyle.getScaleFactor(context), color: AppColor.primary70),
|
|
],
|
|
),
|
|
)
|
|
: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const Divider(color: Color(0xFFEAF1F4), height: 1, thickness: 1),
|
|
16.height,
|
|
Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Text(
|
|
context.translation.viewComments,
|
|
style: AppTextStyles.bodyText.copyWith(color: const Color(0xFF4A8DB7)),
|
|
),
|
|
4.width,
|
|
const Icon(
|
|
Icons.arrow_forward,
|
|
color: Color(0xFF4A8DB7),
|
|
size: 14,
|
|
)
|
|
],
|
|
),
|
|
],
|
|
).paddingOnly(bottom: 16, start: 16, end: 16))
|
|
.onPress(() async {
|
|
await showModalBottomSheet(
|
|
context: context,
|
|
useSafeArea: true,
|
|
isScrollControlled: true,
|
|
backgroundColor: Colors.transparent,
|
|
builder: (context) => CommentsBottomSheet(requestId: widget.serviceRequest.id),
|
|
);
|
|
}),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
return Scaffold(
|
|
appBar: DefaultAppBar(title: context.translation.serviceDetails),
|
|
backgroundColor: const Color(0xfff8f9fb),
|
|
body: SafeArea(
|
|
child: FutureBuilder(
|
|
future: _serviceRequestsProvider.getServiceRequestObjectById(requestId: widget.serviceRequest.id),
|
|
builder: (context, snap) {
|
|
if (snap.connectionState == ConnectionState.waiting) {
|
|
return const ALoading();
|
|
} else if (snap.hasData) {
|
|
final serviceRequest = snap.data;
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
SingleChildScrollView(
|
|
padding: const EdgeInsets.all(16),
|
|
child: informationCard(),
|
|
).expanded,
|
|
if (_userProvider.user.type == UsersTypes.engineer || (serviceRequest.statusValue == 5 || serviceRequest.statusValue == 3))
|
|
(serviceRequest.firstAction == null
|
|
? AppFilledButton(
|
|
label: context.translation.firstAction,
|
|
maxWidth: true,
|
|
onPressed: () async {
|
|
// Navigator.of(context).push(
|
|
// MaterialPageRoute(builder: (_) => CreateServiceRequestPage(serviceRequest: serviceRequest)),
|
|
// );
|
|
await showModalBottomSheet(
|
|
context: context,
|
|
useSafeArea: true,
|
|
isScrollControlled: true,
|
|
backgroundColor: Colors.transparent,
|
|
builder: (context) => FirstActionBottomSheet(request: serviceRequest),
|
|
);
|
|
},
|
|
)
|
|
: AppFilledButton(
|
|
label: context.translation.viewWorkOrder,
|
|
maxWidth: true,
|
|
onPressed: () {
|
|
Navigator.of(context).pushNamed(WorkOrderListPage.id, arguments: serviceRequest);
|
|
},
|
|
))
|
|
.paddingOnly(start: 16, end: 16, bottom: 24),
|
|
],
|
|
);
|
|
}
|
|
return const SizedBox();
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|