Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
27 kB
1
Indexable
Never
import 'dart:developer';

import 'package:biller_q/src/application/bloc/complaint_bloc.dart';
import 'package:biller_q/src/application/bloc/complaint_state.dart';

import 'package:biller_q/src/application/core/status.dart';
import 'package:biller_q/src/domain/core/models/pm_models/pm_complaint_model/pm_complaint_model.dart';
import 'package:biller_q/src/domain/core/models/response_models/complaint_model/datum.dart';
import 'package:biller_q/src/presentaion/global_widgets/custom_appbar.dart';
import 'package:biller_q/src/presentaion/global_widgets/custom_container.dart';
import 'package:biller_q/src/presentaion/global_widgets/custom_dropdown.dart';
import 'package:biller_q/src/presentaion/global_widgets/custom_message.dart';
import 'package:biller_q/src/presentaion/styles/colors/constant_colors.dart';
import 'package:biller_q/src/presentaion/styles/fonts/constant_font.dart';
import 'package:biller_q/src/presentaion/view/login/custom_widget/custom_message.dart';
import 'package:biller_q/src/presentaion/view/subscription/custom_widget/payment_field.dart';

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:intl/intl.dart';
import 'package:skeletonizer/skeletonizer.dart';

class ComplaintDetaileScreen extends StatefulWidget {
  final IndividualComplaintData individualData;
  const ComplaintDetaileScreen({
    super.key,
    required this.individualData,
  });

  @override
  State<ComplaintDetaileScreen> createState() => _ComplaintDetaileScreenState();
}

class _ComplaintDetaileScreenState extends State<ComplaintDetaileScreen> {
  String selectedStatus = '';
  Color getStatusColor(String status) {
    switch (status) {
      case "open":
        return const Color(0xffFFAF86);
      case "In process":
        return const Color(0xffFAF57E);

      case "closed":
        return const Color(0xff8AEF81);
      default:
        return Colors.transparent;
    }
  }

  String formatDate(String dateStr) {
    DateTime dateTime = DateTime.parse(dateStr);

    String formattedDate =
        DateFormat('d MMM yyyy hh:mm a').format(dateTime.toLocal());

    return formattedDate;
  }

  TextEditingController commentController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return PopScope(
      onPopInvoked: (isInvoked) {
        context.read<ComplaintBloc>().add(const GetComplaintEvent());
      },
      child: Scaffold(
        backgroundColor: AppColors.lightBlueColor,
        body: SizedBox(
          height: ScreenUtil().screenHeight,
          width: ScreenUtil().screenWidth,
          child: Stack(
            children: [
              const CustomAppbar(
                enableAdd: true,
                txt: '    Complaints',
                enableMenu: false,
                enableScanner: false,
                enableSearch: false,
              ),
              Positioned(
                top: 175.h,
                left: 0,
                right: 0,
                child: Container(
                  margin: EdgeInsets.only(
                    left: 16.w,
                    right: 16.w,
                  ),
                  height: 900.h,
                  width: 358.w,
                  decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(12.r),
                      color: AppColors.whiteColor),
                  child: SingleChildScrollView(
                    child: Column(
                      children: [
                        SizedBox(
                          height: 16.h,
                        ),
                        //name

                        Padding(
                          padding: EdgeInsets.symmetric(horizontal: 16.w),
                          child: Column(
                            children: [
                              Row(
                                children: [
                                  Container(
                                    height: 56.h,
                                    width: 56.w,
                                    decoration: ShapeDecoration(
                                        shape: const OvalBorder(),
                                        color: AppColors.greenColor),
                                    child: Center(
                                      child: Kstyles().defaultTextStyle(
                                        text: widget
                                            .individualData.customerName![0],
                                        fontWeight: FontWeight.w500,
                                        size: 24.w,
                                        textColor: AppColors.whiteColor,
                                      ),
                                    ),
                                  ),
                                  SizedBox(
                                    width: 7.w,
                                  ),
                                  Kstyles().defaultTextStyle(
                                      text: widget.individualData.customerName
                                          .toString(),
                                      fontWeight: FontWeight.w700,
                                      size: 16.w)
                                ],
                              ),
                              SizedBox(
                                height: 16.h,
                              ),
                              //date
                              Row(
                                children: [
                                  CustomContainer(
                                    height: 28.h,
                                    width: 90.w,
                                    containerClr: getStatusColor(widget
                                        .individualData.status
                                        .toString()),
                                    borderRadius: BorderRadius.circular(28.r),
                                    isBorder: false,
                                    txt: widget.individualData.status,
                                  ),
                                  SizedBox(
                                    width: 90.w,
                                  ),
                                  Kstyles().defaultTextStyle(
                                      text: formatDate(widget
                                          .individualData.createdAt
                                          .toString()),
                                      fontWeight: FontWeight.w400,
                                      size: 12.h),
                                ],
                              ),
                              SizedBox(
                                height: 16.h,
                              ),
                              //detailes
                              SizedBox(
                                height: 12.h,
                              ),
                              //  PaymentField(
                              //   txt: 'LCO number',
                              //   payment: widget.individualData.,
                              //   txtButton: false,
                              // ),
                              SizedBox(
                                height: 12.h,
                              ),
                              PaymentField(
                                txt: 'Complaint ID',
                                payment: widget.individualData.id.toString(),
                                txtButton: false,
                              ),
                              SizedBox(
                                height: 12.h,
                              ),
                              PaymentField(
                                txt: 'Problem type ',
                                payment: widget.individualData.problemType
                                    .toString(),
                                txtButton: false,
                              ),
                              SizedBox(
                                height: 12.h,
                              ),
                              PaymentField(
                                txt: 'Connection number ',
                                payment:
                                    widget.individualData.companyId.toString(),
                                txtButton: false,
                              ),
                              SizedBox(
                                height: 12.h,
                              ),
                              PaymentField(
                                txt: 'Mobile number ',
                                payment: widget.individualData.phone.toString(),
                                txtButton: false,
                              ),
                              SizedBox(
                                height: 12.h,
                              ),
                              PaymentField(
                                txt: 'Area',
                                payment:
                                    widget.individualData.areaName.toString(),
                                txtButton: false,
                              ),
                              SizedBox(
                                height: 12.h,
                              ),
                              PaymentField(
                                txt: 'Address',
                                payment: widget.individualData.customerAddress
                                    .toString(),
                                txtButton: false,
                              ),
                            ],
                          ),
                        ),
                        SizedBox(
                          height: 16.h,
                        ),
                        const Divider(),

                        ...widget.individualData.complaintForum!
                            .map((complaint) => CustomMessage(
                                  time: complaint.createdAt.toString(),
                                  text: complaint.comments!,
                                )),

                        SizedBox(
                          height: 36.h,
                        ),
                        InkWell(
                          onTap: () {
                            showDialog(
                                context: context,
                                builder: (context) {
                                  return BlocListener<ComplaintBloc,
                                      ComplaintState>(
                                    listenWhen: (previous, current) =>
                                        previous.complaintUpdateStatus !=
                                        current.complaintUpdateStatus,
                                    listener: (context, state) {
                                      if (state.complaintUpdateStatus
                                          is StatusSuccess) {
                                        Navigator.pop(context);
                                        Navigator.pop(context);
                                        MessageCustom(
                                                context: context,
                                                message: "Complaint Updated!",
                                                style: MessageStyle.success)
                                            .show();
                                      } else if (state.complaintUpdateStatus
                                          is StatusFailure) {
                                        final status =
                                            state.complaintUpdateStatus
                                                as StatusFailure;
                                        MessageCustom(
                                                context: context,
                                                message: status.errorMessage,
                                                style: MessageStyle.error)
                                            .show();
                                      }
                                    },
                                    child: AlertDialog(
                                        surfaceTintColor: AppColors.whiteColor,
                                        insetPadding: EdgeInsets.zero,
                                        // contentPadding: EdgeInsets.zero,
                                        content: SizedBox(
                                          height: 294.h,
                                          width: 370.w,
                                          child: Padding(
                                            padding: EdgeInsets.only(
                                                top: 5.h, left: 5.w),
                                            child: Column(
                                              children: [
                                                //add comment

                                                Column(
                                                  crossAxisAlignment:
                                                      CrossAxisAlignment.start,
                                                  children: [
                                                    Kstyles().defaultTextStyle(
                                                        text: 'Add comment',
                                                        fontWeight:
                                                            FontWeight.w400,
                                                        size: 14.w),
                                                    TextFormField(
                                                      // onFieldSubmitted: (String
                                                      //     commentController) {
                                                      //   updateComplaint();
                                                      // },
                                                      controller:
                                                          commentController,
                                                      textAlign: TextAlign.left,
                                                      decoration: InputDecoration(
                                                          border:
                                                              InputBorder.none,
                                                          contentPadding:
                                                              EdgeInsets.only(
                                                                  left: 16.w),
                                                          hintText:
                                                              'Add comment',
                                                          hintStyle: TextStyle(
                                                              fontWeight:
                                                                  FontWeight
                                                                      .w400,
                                                              fontSize: 14.w)),
                                                    ),
                                                  ],
                                                ),

                                                CustomDropDown(
                                                    itemSelected:
                                                        (index, value) {
                                                      setState(() {
                                                        selectedStatus = value;
                                                      });
                                                    },
                                                    title: 'Status',
                                                    valueList: const [
                                                      'Open',
                                                      'In process',
                                                      'Closed'
                                                    ],
                                                    errorMessage: '',
                                                    hintText: 'Select status',
                                                    isBorder: true),
                                                SizedBox(
                                                  height: 36.h,
                                                ),

                                                InkWell(
                                                  onTap: () {
                                                    log("annasj");
                                                    // updateComplaint();
                                                    // commentController.clear();
                                                    // Navigator.pop(
                                                    //   context,
                                                    // );

                                                    if (selectedStatus
                                                        .isEmpty) {
                                                      // error message
                                                      Navigator.pop(context);
                                                      MessageCustom(
                                                              context: context,
                                                              message:
                                                                  "Please select a Status",
                                                              style:
                                                                  MessageStyle
                                                                      .error)
                                                          .show();
                                                    } else if (commentController
                                                        .text.isEmpty) {
                                                      Navigator.pop(context);
                                                      MessageCustom(
                                                              context: context,
                                                              message:
                                                                  "Please Enter a Message",
                                                              style:
                                                                  MessageStyle
                                                                      .error)
                                                          .show();
                                                    } else {
                                                      final PmComplaintModel
                                                          pmComplaintModel =
                                                          PmComplaintModel(
                                                              status: selectedStatus
                                                                  .toString()
                                                                  .toLowerCase(),
                                                              lcoNo: widget
                                                                  .individualData
                                                                  .lcoNo,
                                                              comments:
                                                                  commentController
                                                                      .text
                                                                      .trim(),
                                                              complaintId: widget
                                                                  .individualData
                                                                  .id
                                                                  .toString());
                                                      BlocProvider.of<
                                                                  ComplaintBloc>(
                                                              context)
                                                          .add(ComplaintUpdateEvent(
                                                              pmComplaintModel));
                                                      setState(() {
                                                        selectedStatus = '';
                                                      });
                                                    }
                                                  },
                                                  child: CustomContainer(
                                                    height: 40.h,
                                                    width: 119.w,
                                                    containerClr:
                                                        AppColors.blueColor,
                                                    borderRadius:
                                                        BorderRadius.circular(
                                                            12.r),
                                                    isBorder: false,
                                                    txt: 'Submit',
                                                    txtclr:
                                                        AppColors.whiteColor,
                                                  ),
                                                ),
                                              ],
                                            ),
                                          ),
                                        )),
                                  );
                                });
                          },
                          child: CustomContainer(
                            height: 40.h,
                            width: 135.w,
                            containerClr: AppColors.blueColor,
                            borderRadius: BorderRadius.circular(12.r),
                            isBorder: false,
                            txt: 'Update',
                            txtclr: AppColors.whiteColor,
                          ),
                        ),
                        SizedBox(
                          height: 300.h,
                        ),
                      ],
                    ),
                  ),
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}

class CustomTextfield extends StatelessWidget {
  String? title;
  final bool isShowTxtfield;

  CustomTextfield({
    super.key,
    this.title,
    required this.isShowTxtfield,
  });

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: 325.w,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          title != null
              ? Kstyles().defaultTextStyle(
                  text: title ?? '', fontWeight: FontWeight.w400, size: 14.w)
              : const SizedBox.shrink(),
          SizedBox(
            height: 10.h,
          ),
          // add comment conainer
          isShowTxtfield
              ? Container(
                  height: 56.h,
                  width: 358.w,
                  decoration: BoxDecoration(
                    color: const Color(0xffF7F7F7),
                    borderRadius: BorderRadius.circular(12.r),
                  ),
                  child: TextField(
                    textAlign: TextAlign.left,
                    decoration: InputDecoration(
                        border: InputBorder.none,
                        contentPadding: EdgeInsets.only(left: 16.w),
                        hintText: 'Add comment',
                        hintStyle: TextStyle(
                            fontWeight: FontWeight.w400, fontSize: 14.w)),
                  ),
                )
              : const CustomDropDown(
                  title: 'Status',
                  valueList: ['Open', 'In process', 'Closed'],
                  errorMessage: '',
                  hintText: 'Select status',
                  isBorder: true)
        ],
      ),
    );
  }
}

class CustomMessage extends StatelessWidget {
  final String? text;
  final String? time;
  final bool isRecieved;

  const CustomMessage({
    this.time,
    this.text,
    super.key,
    this.isRecieved = false,
  });

  @override
  Widget build(BuildContext context) {
    String formatDate(String dateStr) {
      DateTime dateTime = DateTime.parse(dateStr);

      String formattedDate =
          DateFormat('d MMM yyyy hh:mm a').format(dateTime.toLocal());

      return formattedDate;
    }

    return Container(
      margin: EdgeInsets.only(bottom: 10.h, top: 10.h),
      padding:
          isRecieved ? EdgeInsets.only(left: 10) : EdgeInsets.only(right: 10),
      child: Column(
        crossAxisAlignment:
            isRecieved ? CrossAxisAlignment.start : CrossAxisAlignment.end,
        children: [
          Container(
            constraints:
                BoxConstraints(maxWidth: 267), // Maximum width constraint
            decoration: BoxDecoration(
              borderRadius: BorderRadius.only(
                topLeft: Radius.circular(12),
                topRight: Radius.circular(12),
                bottomRight: Radius.circular(isRecieved ? 12 : 0),
                bottomLeft: Radius.circular(isRecieved ? 0 : 12),
              ),
              color: isRecieved
                  ? const Color(0xffF7F7F7)
                  : const Color(0xff227DE8),
            ),
            child: Padding(
              padding: const EdgeInsets.all(8),
              child: Text(
                text ?? '',
                style: TextStyle(
                  fontSize: 14,
                  fontWeight: FontWeight.w400,
                  color: isRecieved ? Colors.black : Colors.white,
                ),
                maxLines: null, // Allows the text to wrap and grow
                softWrap: true, // Enables soft wrapping
              ),
            ),
          ),
          Row(
            mainAxisAlignment:
                isRecieved ? MainAxisAlignment.start : MainAxisAlignment.end,
            children: [
              Text(
                formatDate(time!),
                style: TextStyle(
                  fontWeight: FontWeight.w400,
                  fontSize: 12,
                ),
              ),
              SizedBox(
                width: 5,
              ),
            ],
          ),
        ],
      ),
    );
  }
}
Leave a Comment