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.
		
		
		
		
		
			
		
			
				
	
	
		
			259 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			Dart
		
	
			
		
		
	
	
			259 lines
		
	
	
		
			12 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/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/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 StatelessWidget {
 | 
						|
  static const String id = "/call-details";
 | 
						|
  ServiceRequest serviceRequest;
 | 
						|
 | 
						|
  ServiceRequestDetailsPage({Key key, this.serviceRequest}) : super(key: key);
 | 
						|
 | 
						|
  @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: serviceRequest.priority.name,
 | 
						|
                                id: serviceRequest.priority.id,
 | 
						|
                                textColor: AColors.getPriorityStatusTextColor(serviceRequest.priority.id),
 | 
						|
                                backgroundColor: AColors.getPriorityStatusColor(serviceRequest.priority.id)),
 | 
						|
                            8.width,
 | 
						|
                            StatusLabel(
 | 
						|
                                label: serviceRequest.statusLabel,
 | 
						|
                                textColor: AColors.getRequestStatusTextColor(serviceRequest.statusValue),
 | 
						|
                                backgroundColor: AColors.getRequestStatusColor(serviceRequest.statusValue)),
 | 
						|
                            1.width.expanded,
 | 
						|
                          ],
 | 
						|
                        ),
 | 
						|
                        8.height,
 | 
						|
                        Text(serviceRequest.deviceEnName, style: AppTextStyles.heading5.copyWith(color: const Color(0xFF3B3D4A))),
 | 
						|
                        8.height,
 | 
						|
                        Text(
 | 
						|
                          '${context.translation.assetNumber}:  ${serviceRequest.device.assetNumber}',
 | 
						|
                          style: AppTextStyles.bodyText.copyWith(color: Color(0xFF757575)),
 | 
						|
                        ),
 | 
						|
                        Text(
 | 
						|
                          'Request Type: ${serviceRequest.type.name}',
 | 
						|
                          style: AppTextStyles.bodyText.copyWith(color: Color(0xFF757575)),
 | 
						|
                        ),
 | 
						|
                        Text(
 | 
						|
                          'Request No: ${serviceRequest.requestCode}',
 | 
						|
                          style: AppTextStyles.bodyText.copyWith(color: Color(0xFF757575)),
 | 
						|
                        ),
 | 
						|
                      ],
 | 
						|
                    ).expanded,
 | 
						|
                    Column(
 | 
						|
                      crossAxisAlignment: CrossAxisAlignment.end,
 | 
						|
                      children: [
 | 
						|
                        if (_userProvider.user.type == UsersTypes.normal_user)
 | 
						|
                          "edit".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: const Color(0xFF3B3D4A))),
 | 
						|
                      ],
 | 
						|
                    )
 | 
						|
                  ],
 | 
						|
                ),
 | 
						|
                8.height,
 | 
						|
                const Divider(color: Color(0xFFEAF1F4), height: 1, thickness: 1),
 | 
						|
                8.height,
 | 
						|
                Text(
 | 
						|
                  'Manufacture: ${serviceRequest.device.modelDefinition.manufacturerName}',
 | 
						|
                  style: AppTextStyles.bodyText.copyWith(color: Color(0xFF757575)),
 | 
						|
                ),
 | 
						|
                Text(
 | 
						|
                  'Model: ${serviceRequest.device.modelDefinition.modelName}',
 | 
						|
                  style: AppTextStyles.bodyText.copyWith(color: Color(0xFF757575)),
 | 
						|
                ),
 | 
						|
                8.height,
 | 
						|
                if ((serviceRequest.callComments ?? "").isNotEmpty) ...[
 | 
						|
                  const Divider(color: Color(0xFFEAF1F4), height: 1, thickness: 1),
 | 
						|
                  8.height,
 | 
						|
                  Text(
 | 
						|
                    serviceRequest.callComments,
 | 
						|
                    style: AppTextStyles.bodyText.copyWith(color: Color(0xFF757575)),
 | 
						|
                  ),
 | 
						|
                ],
 | 
						|
                if (serviceRequest.devicePhotos.isNotEmpty) ...[
 | 
						|
                  8.height,
 | 
						|
                  const Divider(color: Color(0xFFEAF1F4), height: 1, thickness: 1),
 | 
						|
                  FilesList(images: serviceRequest.devicePhotos),
 | 
						|
                ],
 | 
						|
                if (serviceRequest.audio?.isNotEmpty ?? false) ...[
 | 
						|
                  const Divider(color: Color(0xFFEAF1F4), height: 1, thickness: 1),
 | 
						|
                  16.height,
 | 
						|
                  ASoundPlayer(audio: 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(
 | 
						|
                              'Comment here...',
 | 
						|
                              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(
 | 
						|
                                'View Comments',
 | 
						|
                                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 {
 | 
						|
              // todo 'sikander' add comment bottom sheet
 | 
						|
              // await showModalBottomSheet(
 | 
						|
              //   context: context,
 | 
						|
              //   useSafeArea: true,
 | 
						|
              //   isScrollControlled: true,
 | 
						|
              //   backgroundColor: Colors.transparent,
 | 
						|
              //   builder: (context) => FirstActionBottomSheet(
 | 
						|
              //     onPressed: () {},
 | 
						|
              //   ),
 | 
						|
              // );
 | 
						|
            }),
 | 
						|
          ],
 | 
						|
        ),
 | 
						|
      );
 | 
						|
    }
 | 
						|
 | 
						|
    return Scaffold(
 | 
						|
      appBar: DefaultAppBar(title: context.translation.serviceDetails),
 | 
						|
      backgroundColor: const Color(0xfff8f9fb),
 | 
						|
      body: SafeArea(
 | 
						|
        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(
 | 
						|
                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();
 | 
						|
          },
 | 
						|
        ),
 | 
						|
      ),
 | 
						|
    );
 | 
						|
  }
 | 
						|
}
 |