Changes
parent
75c46e5194
commit
021618fa6b
@ -0,0 +1,158 @@
|
|||||||
|
import 'package:mc_common_app/extensions/string_extensions.dart';
|
||||||
|
import 'package:mc_common_app/utils/enums.dart';
|
||||||
|
|
||||||
|
class ProviderOffersChatsModel {
|
||||||
|
int? id;
|
||||||
|
int? requestID;
|
||||||
|
int? serviceProviderID;
|
||||||
|
ServiceProviderModel? serviceProvider;
|
||||||
|
int? offerStatus;
|
||||||
|
RequestOfferStatusEnum? requestOfferStatusEnum;
|
||||||
|
String? offerStatusText;
|
||||||
|
String? comment;
|
||||||
|
String? customerName;
|
||||||
|
double? price;
|
||||||
|
String? serviceItem;
|
||||||
|
String? offeredItemCreatedBy;
|
||||||
|
String? offeredItemCreatedByName;
|
||||||
|
String? offeredItemCreatedOn;
|
||||||
|
String? reqOfferImages;
|
||||||
|
bool? isDeliveryAvailable;
|
||||||
|
String? createdOn;
|
||||||
|
|
||||||
|
ProviderOffersChatsModel({
|
||||||
|
this.id,
|
||||||
|
this.requestID,
|
||||||
|
this.serviceProviderID,
|
||||||
|
this.serviceProvider,
|
||||||
|
this.offerStatus,
|
||||||
|
this.requestOfferStatusEnum,
|
||||||
|
this.offerStatusText,
|
||||||
|
this.comment,
|
||||||
|
this.customerName,
|
||||||
|
this.price,
|
||||||
|
this.serviceItem,
|
||||||
|
this.offeredItemCreatedBy,
|
||||||
|
this.offeredItemCreatedByName,
|
||||||
|
this.offeredItemCreatedOn,
|
||||||
|
this.reqOfferImages,
|
||||||
|
this.isDeliveryAvailable,
|
||||||
|
this.createdOn,
|
||||||
|
});
|
||||||
|
|
||||||
|
ProviderOffersChatsModel.fromJson(Map<String, dynamic> json) {
|
||||||
|
id = json['id'];
|
||||||
|
requestID = json['requestID'];
|
||||||
|
serviceProviderID = json['serviceProviderID'];
|
||||||
|
serviceProvider = json['serviceProvider'] != null ? ServiceProviderModel.fromJson(json['serviceProvider']) : null;
|
||||||
|
offerStatus = json['offerStatus'];
|
||||||
|
requestOfferStatusEnum = ((json['offerStatus']) as int).toRequestOfferStatusEnum();
|
||||||
|
offerStatusText = json['offerStatusText'];
|
||||||
|
comment = json['comment'];
|
||||||
|
customerName = json['customerName'];
|
||||||
|
price = json['price'];
|
||||||
|
serviceItem = json['serviceItem'];
|
||||||
|
offeredItemCreatedBy = json['offeredItemCreatedBy'];
|
||||||
|
offeredItemCreatedByName = json['offeredItemCreatedByName'];
|
||||||
|
offeredItemCreatedOn = json['offeredItemCreatedOn'];
|
||||||
|
reqOfferImages = json['reqOfferImages'];
|
||||||
|
isDeliveryAvailable = json['isDeliveryAvailable'];
|
||||||
|
createdOn = json['createdOn'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ServiceProviderModel {
|
||||||
|
int? providerId;
|
||||||
|
String? providerGUID;
|
||||||
|
String? firstName;
|
||||||
|
String? lastName;
|
||||||
|
String? name;
|
||||||
|
int? gender;
|
||||||
|
String? genderName;
|
||||||
|
String? mobileNo;
|
||||||
|
String? email;
|
||||||
|
bool? isEmailVerified;
|
||||||
|
bool? isCompleted;
|
||||||
|
int? city;
|
||||||
|
String? cityName;
|
||||||
|
int? country;
|
||||||
|
String? countryName;
|
||||||
|
int? accountStatus;
|
||||||
|
String? accountStatusText;
|
||||||
|
int? activityStatus;
|
||||||
|
String? activityStatusText;
|
||||||
|
String? bankName;
|
||||||
|
String? iBanNo;
|
||||||
|
bool? isActive;
|
||||||
|
String? subscriptionDate;
|
||||||
|
String? createdOn;
|
||||||
|
String? companyName;
|
||||||
|
String? currency;
|
||||||
|
String? branch;
|
||||||
|
bool? isChatted;
|
||||||
|
bool? isDealership;
|
||||||
|
|
||||||
|
ServiceProviderModel({
|
||||||
|
this.providerId,
|
||||||
|
this.providerGUID,
|
||||||
|
this.firstName,
|
||||||
|
this.lastName,
|
||||||
|
this.name,
|
||||||
|
this.gender,
|
||||||
|
this.genderName,
|
||||||
|
this.mobileNo,
|
||||||
|
this.email,
|
||||||
|
this.isEmailVerified,
|
||||||
|
this.isCompleted,
|
||||||
|
this.city,
|
||||||
|
this.cityName,
|
||||||
|
this.country,
|
||||||
|
this.countryName,
|
||||||
|
this.accountStatus,
|
||||||
|
this.accountStatusText,
|
||||||
|
this.activityStatus,
|
||||||
|
this.activityStatusText,
|
||||||
|
this.bankName,
|
||||||
|
this.iBanNo,
|
||||||
|
this.isActive,
|
||||||
|
this.subscriptionDate,
|
||||||
|
this.createdOn,
|
||||||
|
this.companyName,
|
||||||
|
this.currency,
|
||||||
|
this.branch,
|
||||||
|
this.isChatted,
|
||||||
|
this.isDealership,
|
||||||
|
});
|
||||||
|
|
||||||
|
ServiceProviderModel.fromJson(Map<String, dynamic> json) {
|
||||||
|
providerId = json['providerId'];
|
||||||
|
providerGUID = json['providerGUID'];
|
||||||
|
firstName = json['firstName'];
|
||||||
|
lastName = json['lastName'];
|
||||||
|
name = json['name'];
|
||||||
|
gender = json['gender'];
|
||||||
|
genderName = json['genderName'];
|
||||||
|
mobileNo = json['mobileNo'];
|
||||||
|
email = json['email'];
|
||||||
|
isEmailVerified = json['isEmailVerfied'];
|
||||||
|
isCompleted = json['isCompleted'];
|
||||||
|
city = json['city'];
|
||||||
|
cityName = json['cityName'];
|
||||||
|
country = json['country'];
|
||||||
|
countryName = json['countryName'];
|
||||||
|
accountStatus = json['accountStatus'];
|
||||||
|
accountStatusText = json['accountStatusText'];
|
||||||
|
activityStatus = json['activityStatus'];
|
||||||
|
activityStatusText = json['activityStatusText'];
|
||||||
|
bankName = json['bankName'];
|
||||||
|
iBanNo = json['iBanNo'];
|
||||||
|
isActive = json['isActive'];
|
||||||
|
subscriptionDate = json['subscriptionDate'];
|
||||||
|
createdOn = json['createdOn'];
|
||||||
|
companyName = json['companyName'];
|
||||||
|
currency = json['currency'];
|
||||||
|
branch = json['branch'];
|
||||||
|
isChatted = json['isChatted'];
|
||||||
|
isDealership = json['isDealership'];
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,180 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'dart:developer';
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:mc_common_app/classes/app_state.dart';
|
||||||
|
import 'package:mc_common_app/config/routes.dart';
|
||||||
|
import 'package:mc_common_app/extensions/int_extensions.dart';
|
||||||
|
import 'package:mc_common_app/extensions/string_extensions.dart';
|
||||||
|
import 'package:mc_common_app/generated/locale_keys.g.dart';
|
||||||
|
import 'package:mc_common_app/models/requests_models/offers_model.dart';
|
||||||
|
import 'package:mc_common_app/models/requests_models/provider_offers_model.dart';
|
||||||
|
import 'package:mc_common_app/models/requests_models/providers_offers_chat_model.dart';
|
||||||
|
import 'package:mc_common_app/models/requests_models/request_model.dart';
|
||||||
|
import 'package:mc_common_app/theme/colors.dart';
|
||||||
|
import 'package:mc_common_app/utils/enums.dart';
|
||||||
|
import 'package:mc_common_app/utils/navigator.dart';
|
||||||
|
import 'package:mc_common_app/utils/utils.dart';
|
||||||
|
import 'package:mc_common_app/view_models/chat_view_model.dart';
|
||||||
|
import 'package:mc_common_app/view_models/requests_view_model.dart';
|
||||||
|
import 'package:mc_common_app/widgets/common_widgets/app_bar.dart';
|
||||||
|
import 'package:mc_common_app/widgets/extensions/extensions_widget.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
|
|
||||||
|
class ProvidersChatListPage extends StatefulWidget {
|
||||||
|
const ProvidersChatListPage({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<ProvidersChatListPage> createState() => _ProvidersChatListPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ProvidersChatListPageState extends State<ProvidersChatListPage> {
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
_onRefresh();
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
_onRefresh() async {
|
||||||
|
scheduleMicrotask(() async {
|
||||||
|
RequestsVM requestsVM = context.read<RequestsVM>();
|
||||||
|
await requestsVM.getProviderOffersChatsList(serviceProviderId: AppState().getUser.data!.userInfo!.providerId ?? 0, context: context);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> onChatTapped({required BuildContext context, required int requestID}) async {
|
||||||
|
final requestsVM = context.read<RequestsVM>();
|
||||||
|
final chatVM = context.read<ChatVM>();
|
||||||
|
|
||||||
|
int requestIndex = requestsVM.myFilteredRequests.indexWhere((request) => request.id == requestID);
|
||||||
|
log("requestIndex1: $requestIndex");
|
||||||
|
|
||||||
|
if (requestIndex == -1) {
|
||||||
|
RequestsTypeEnum requestTypeEnum = requestsVM.requestsTypeFilterOptions.firstWhere((element) => element.isSelected).id.toRequestTypeEnum();
|
||||||
|
if (requestTypeEnum == RequestsTypeEnum.specialCarRequest) {
|
||||||
|
requestTypeEnum = RequestsTypeEnum.serviceRequest;
|
||||||
|
} else {
|
||||||
|
requestTypeEnum = RequestsTypeEnum.specialCarRequest;
|
||||||
|
}
|
||||||
|
await requestsVM.applyFilterOnRequestsVM(requestsTypeEnum: requestTypeEnum);
|
||||||
|
|
||||||
|
requestIndex = requestsVM.myFilteredRequests.indexWhere((request) => request.id == requestID);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (requestIndex != -1) {
|
||||||
|
RequestModel request = requestsVM.myFilteredRequests[requestIndex];
|
||||||
|
requestsVM.updateCurrentSelectedRequest(request);
|
||||||
|
// if (request.requestStatus == RequestStatusEnum.pending || request.requestStatus == RequestStatusEnum.cancelled || request.requestStatus == RequestStatusEnum.expired) {
|
||||||
|
// Utils.showToast("${LocaleKeys.requests.tr()} ${request.requestStatusName}");
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
RequestDetailPageArguments requestDetailPageArguments = RequestDetailPageArguments(requestIndex: requestIndex, requestModel: request);
|
||||||
|
ChatViewArgumentsForRequest chatViewArgumentsForRequest = ChatViewArgumentsForRequest(
|
||||||
|
chatTypeEnum: ChatTypeEnum.requestOffer,
|
||||||
|
receiverId: requestDetailPageArguments.requestModel.customerID,
|
||||||
|
senderId: AppState().getUser.data!.userInfo!.userId.toString(),
|
||||||
|
requestId: requestDetailPageArguments.requestModel.id,
|
||||||
|
providerIndex: -1,
|
||||||
|
// This will be only sent in case of customer
|
||||||
|
requestModel: requestDetailPageArguments.requestModel,
|
||||||
|
requestIndex: requestDetailPageArguments.requestIndex, // This will be only sent in case of provider
|
||||||
|
);
|
||||||
|
ChatViewArguments chatViewArguments = ChatViewArguments(
|
||||||
|
chatTypeEnum: ChatTypeEnum.requestOffer,
|
||||||
|
chatViewArgumentsForRequest: chatViewArgumentsForRequest,
|
||||||
|
);
|
||||||
|
|
||||||
|
log("requestIndex2: $requestIndex");
|
||||||
|
|
||||||
|
await chatVM
|
||||||
|
.getRequestsChatMessagesForProvider(
|
||||||
|
customerId: requestDetailPageArguments.requestModel.customerId,
|
||||||
|
context: navigatorKey.currentState!.overlay!.context,
|
||||||
|
requestOfferId: 0,
|
||||||
|
requestId: requestDetailPageArguments.requestModel.id,
|
||||||
|
customerRequestIndex: requestDetailPageArguments.requestIndex,
|
||||||
|
)
|
||||||
|
.whenComplete(() => navigateWithName(navigatorKey.currentState!.overlay!.context, AppRoutes.chatView, arguments: chatViewArguments));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Consumer<RequestsVM>(builder: (context, RequestsVM requestsVM, Widget? child) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: CustomAppBar(title: LocaleKeys.specialRequestChat.tr()),
|
||||||
|
body: RefreshIndicator(
|
||||||
|
onRefresh: () async {
|
||||||
|
_onRefresh();
|
||||||
|
},
|
||||||
|
child: requestsVM.state == ViewState.busy
|
||||||
|
? const Center(child: CircularProgressIndicator())
|
||||||
|
: requestsVM.providerOffersChatsList.isEmpty
|
||||||
|
? Center(
|
||||||
|
child: LocaleKeys.noOffersShow.tr().toText(
|
||||||
|
fontSize: 16,
|
||||||
|
color: MyColors.lightTextColor,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: ListView.separated(
|
||||||
|
itemCount: requestsVM.providerOffersChatsList.length,
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
ProviderOffersChatsModel providerOffersChatsModel = requestsVM.providerOffersChatsList[index];
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Utils.statusContainerChip(
|
||||||
|
text: Utils.getNameByRequestOfferStatusEnum(providerOffersChatsModel.requestOfferStatusEnum!),
|
||||||
|
chipColor: Utils.getChipColorByRequestOfferStatusEnum(providerOffersChatsModel.requestOfferStatusEnum!),
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
(providerOffersChatsModel.customerName ?? "").toText(
|
||||||
|
fontSize: 16,
|
||||||
|
isBold: true,
|
||||||
|
),
|
||||||
|
if (providerOffersChatsModel.createdOn != null && providerOffersChatsModel.createdOn!.isNotEmpty) ...[
|
||||||
|
DateTime.parse(providerOffersChatsModel.createdOn!).getTimeAgo().toText(color: MyColors.lightTextColor, fontSize: 14),
|
||||||
|
],
|
||||||
|
// if (providerOffersChatsModel. != null && offersModel.offerCount! > 0) ...[
|
||||||
|
// Center(
|
||||||
|
// child: "${providerOffersChatsModel.offerCount}".toText(
|
||||||
|
// color: Colors.white,
|
||||||
|
// isBold: true,
|
||||||
|
// fontSize: 10,
|
||||||
|
// ),
|
||||||
|
// ).toContainer(
|
||||||
|
// backgroundColor: MyColors.cancelledColor,
|
||||||
|
// borderRadius: 100,
|
||||||
|
// paddingAll: 1,
|
||||||
|
// width: 22,
|
||||||
|
// height: 22,
|
||||||
|
// ),
|
||||||
|
// ],
|
||||||
|
],
|
||||||
|
),
|
||||||
|
4.height,
|
||||||
|
Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: "${providerOffersChatsModel.comment}".toText(color: MyColors.lightTextColor, fontSize: 14),
|
||||||
|
),
|
||||||
|
const Icon(Icons.arrow_forward, color: MyColors.darkIconColor, size: 18),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
).onPress(() async => await onChatTapped(context: context, requestID: providerOffersChatsModel.requestID ?? 0)).toContainer(isShadowEnabled: true);
|
||||||
|
},
|
||||||
|
separatorBuilder: (context, index) => 16.height,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue