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.
		
		
		
		
		
			
		
			
				
	
	
		
			250 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			Dart
		
	
			
		
		
	
	
			250 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			Dart
		
	
import 'package:flutter/material.dart';
 | 
						|
import 'package:intl/intl.dart';
 | 
						|
import 'package:provider/provider.dart';
 | 
						|
 | 
						|
import '../../../../api/user_api_client.dart';
 | 
						|
import '../../../../controllers/localization/localization.dart';
 | 
						|
import '../../../../controllers/providers/api/service_requests_provider.dart';
 | 
						|
import '../../../../models/enums/user_types.dart';
 | 
						|
import '../../../../models/service_request/service_request.dart';
 | 
						|
import '../../../app_style/colors.dart';
 | 
						|
import '../../../app_style/sizing.dart';
 | 
						|
import '../../../widgets/buttons/app_back_button.dart';
 | 
						|
import '../../../widgets/buttons/app_button.dart';
 | 
						|
import '../../../widgets/buttons/app_icon_button.dart';
 | 
						|
import '../../../widgets/images/images_list.dart';
 | 
						|
import '../../../widgets/loaders/image_loader.dart';
 | 
						|
import '../../../widgets/requests/info_row.dart';
 | 
						|
import '../../../widgets/requests/request_status.dart';
 | 
						|
import '../../../widgets/requests/service_request_update_dialog.dart';
 | 
						|
import '../../../widgets/sound/sound_player.dart';
 | 
						|
import '../../../widgets/titles/app_sub_title.dart';
 | 
						|
import '../report_issues_page.dart';
 | 
						|
import 'report/create_service_report.dart';
 | 
						|
import 'report/future_service_report.dart';
 | 
						|
 | 
						|
class RequestDetailsPage extends StatelessWidget {
 | 
						|
  static const String id = "/call-details";
 | 
						|
  final ServiceRequest serviceRequest;
 | 
						|
 | 
						|
  const RequestDetailsPage({Key? key, required this.serviceRequest}) : super(key: key);
 | 
						|
 | 
						|
  @override
 | 
						|
  Widget build(BuildContext context) {
 | 
						|
    final subtitle = AppLocalization.of(context)?.subtitle;
 | 
						|
    ServiceRequestsProvider serviceRequestsProvider = Provider.of<ServiceRequestsProvider>(context);
 | 
						|
    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: [
 | 
						|
                    const ABackButton(),
 | 
						|
                    Expanded(
 | 
						|
                      child: Center(
 | 
						|
                        child: Text(
 | 
						|
                          subtitle?.details ?? '',
 | 
						|
                          style: Theme.of(context).textTheme.titleLarge?.copyWith(color: AColors.white, fontStyle: FontStyle.italic),
 | 
						|
                        ),
 | 
						|
                      ),
 | 
						|
                    ),
 | 
						|
                    Visibility(
 | 
						|
                      visible: UserApiClient().user?.roles == UsersTypes.normal_user.name,
 | 
						|
                      replacement: AIconButton(
 | 
						|
                        iconData: Icons.edit,
 | 
						|
                        color: AColors.white,
 | 
						|
                        buttonSize: 42,
 | 
						|
                        backgroundColor: AColors.green,
 | 
						|
                        onPressed: () async {
 | 
						|
                          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<void>(
 | 
						|
                          //   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),
 | 
						|
                          // );
 | 
						|
                        },
 | 
						|
                      ),
 | 
						|
                      child: 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: 16)
 | 
						|
                  ],
 | 
						|
                ),
 | 
						|
              ),
 | 
						|
              (serviceRequest.devicePhotos?.isEmpty ?? false)
 | 
						|
                  ? const SizedBox.shrink()
 | 
						|
                  : Column(
 | 
						|
                      children: [
 | 
						|
                        const 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),
 | 
						|
                          ),
 | 
						|
                        ),
 | 
						|
                        const 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),
 | 
						|
                ],
 | 
						|
              ),
 | 
						|
              const SizedBox(height: 8),
 | 
						|
              Expanded(
 | 
						|
                child: TabBarView(
 | 
						|
                  children: [
 | 
						|
                    ListView(
 | 
						|
                      padding: const EdgeInsets.symmetric(horizontal: 16),
 | 
						|
                      children: [
 | 
						|
                        RequestInfoRow(title: subtitle?.code, info: serviceRequest.requestCode),
 | 
						|
                        RequestInfoRow(title: "Asset Number", info: serviceRequest.deviceNumber),
 | 
						|
                        RequestInfoRow(title: subtitle?.deviceSN, info: serviceRequest.deviceSerialNumber),
 | 
						|
                        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
 | 
						|
                            ? const 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.titleMedium,
 | 
						|
                                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?.deviceEnName, content: serviceRequest.deviceEnName),
 | 
						|
                        RequestInfoRow(title: subtitle?.maintenanceIssue, content: serviceRequest.maintenanceIssue),
 | 
						|
                        if (serviceRequest.audio?.isNotEmpty == true) ASoundPlayer(audio: serviceRequest.audio),
 | 
						|
                        Center(
 | 
						|
                          child: Padding(
 | 
						|
                            padding: const EdgeInsets.all(32),
 | 
						|
                            child: AButton(
 | 
						|
                              text: subtitle?.duplicateRequest ?? '',
 | 
						|
                              onPressed: () async {
 | 
						|
                                await serviceRequestsProvider.createDuplicatedReport(context, request: serviceRequest);
 | 
						|
                              },
 | 
						|
                            ),
 | 
						|
                          ),
 | 
						|
                        )
 | 
						|
                      ],
 | 
						|
                    ),
 | 
						|
                    serviceRequest.viewReport ?? false
 | 
						|
                        ? ListView(
 | 
						|
                            padding: const EdgeInsets.symmetric(horizontal: 16),
 | 
						|
                            children: [
 | 
						|
                              RequestInfoRow(title: subtitle?.faultDescription, content: serviceRequest.faultDescription),
 | 
						|
                              RequestInfoRow(title: subtitle?.workPerformed, content: serviceRequest.workPerformed),
 | 
						|
                              RequestInfoRow(title: subtitle?.visitDate, info: serviceRequest.visitDate),
 | 
						|
                              RequestInfoRow(title: subtitle?.jobSheetNumber, info: serviceRequest.jobSheetNumber),
 | 
						|
                              UserApiClient().user?.roles == UsersTypes.engineer.name
 | 
						|
                                  ? Padding(
 | 
						|
                                      padding: const EdgeInsets.all(32),
 | 
						|
                                      child: AButton(
 | 
						|
                                        text: subtitle?.editServiceReport ?? '',
 | 
						|
                                        onPressed: () {
 | 
						|
                                          Navigator.of(context).push(
 | 
						|
                                            MaterialPageRoute(builder: (_) => FutureServiceReport(request: serviceRequest)),
 | 
						|
                                          );
 | 
						|
                                        },
 | 
						|
                                      ),
 | 
						|
                                    )
 | 
						|
                                  : const SizedBox.shrink(),
 | 
						|
                            ],
 | 
						|
                          )
 | 
						|
                        : UserApiClient().user?.roles == UsersTypes.engineer.name
 | 
						|
                            ? Center(
 | 
						|
                                child: Padding(
 | 
						|
                                  padding: const EdgeInsets.all(32),
 | 
						|
                                  child: AButton(
 | 
						|
                                    text: "Create Report",
 | 
						|
                                    onPressed: () {
 | 
						|
                                      Navigator.of(context).push(
 | 
						|
                                        MaterialPageRoute(builder: (_) => CreateServiceReport(request: serviceRequest)),
 | 
						|
                                      );
 | 
						|
                                    },
 | 
						|
                                  ),
 | 
						|
                                ),
 | 
						|
                              )
 | 
						|
                            : Center(child: ASubTitle(subtitle?.noDateFound ?? '')),
 | 
						|
                  ],
 | 
						|
                ),
 | 
						|
              ),
 | 
						|
            ],
 | 
						|
          ),
 | 
						|
        ),
 | 
						|
      ),
 | 
						|
    );
 | 
						|
  }
 | 
						|
}
 |