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.
285 lines
11 KiB
Dart
285 lines
11 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:mc_common_app/classes/app_state.dart';
|
|
import 'package:mc_common_app/classes/consts.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/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/button/show_fill_button.dart';
|
|
import 'package:mc_common_app/widgets/common_widgets/app_bar.dart';
|
|
import 'package:mc_common_app/widgets/common_widgets/info_bottom_sheet.dart';
|
|
import 'package:mc_common_app/widgets/extensions/extensions_widget.dart';
|
|
import 'package:mc_common_app/widgets/txt_field.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
class RequestDetailPage extends StatelessWidget {
|
|
final RequestDetailPageArguments requestDetailPageArguments;
|
|
|
|
const RequestDetailPage({Key? key, required this.requestDetailPageArguments}) : super(key: key);
|
|
|
|
Future buildSendOfferBottomSheet(BuildContext context) {
|
|
final requestDetail = requestDetailPageArguments.requestModel;
|
|
return showModalBottomSheet(
|
|
context: context,
|
|
isScrollControlled: true,
|
|
enableDrag: true,
|
|
builder: (BuildContext context) {
|
|
return Consumer(builder: (BuildContext context, RequestsVM requestsVM, Widget? child) {
|
|
return InfoBottomSheet(
|
|
title: "Make an offer".toText(fontSize: 28, isBold: true, letterSpacing: -1.44),
|
|
description: Padding(
|
|
padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
12.height,
|
|
TxtField(
|
|
value: requestsVM.offerPrice,
|
|
errorValue: requestsVM.offerPriceError,
|
|
keyboardType: TextInputType.number,
|
|
hint: "Enter amount",
|
|
onChanged: (v) => requestsVM.updateOfferPrice(v),
|
|
),
|
|
12.height,
|
|
TxtField(
|
|
maxLines: 5,
|
|
value: requestsVM.offerDescription,
|
|
errorValue: requestsVM.offerDescriptionError,
|
|
keyboardType: TextInputType.text,
|
|
hint: "Description",
|
|
onChanged: (v) => requestsVM.updateOfferDescription(v),
|
|
),
|
|
],
|
|
),
|
|
25.height,
|
|
ShowFillButton(
|
|
title: "Submit",
|
|
onPressed: () {
|
|
requestsVM.onSendOfferPressed(
|
|
context: context,
|
|
receiverId: requestDetail.customerID,
|
|
message: requestsVM.offerDescription,
|
|
requestId: requestDetail.id,
|
|
offerPrice: requestsVM.offerPrice,
|
|
requestModel: requestDetail,
|
|
requestIndex: requestDetailPageArguments.requestIndex,
|
|
isFromChatScreen: false,
|
|
);
|
|
},
|
|
maxWidth: double.infinity,
|
|
),
|
|
19.height,
|
|
],
|
|
),
|
|
));
|
|
});
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget buildBottomButton({required RequestStatus requestStatus, required String statusText, required BuildContext context, required Function() onViewChatTapped}) {
|
|
switch (requestStatus) {
|
|
case RequestStatus.submitted:
|
|
case RequestStatus.inProgress:
|
|
case RequestStatus.paid:
|
|
case RequestStatus.shipping:
|
|
return ShowFillButton(
|
|
maxWidth: double.infinity,
|
|
margin: const EdgeInsets.all(15),
|
|
maxHeight: 55,
|
|
title: "View Chat",
|
|
isBold: false,
|
|
onPressed: onViewChatTapped,
|
|
);
|
|
case RequestStatus.completed:
|
|
case RequestStatus.cancelled:
|
|
case RequestStatus.expired:
|
|
case RequestStatus.pending:
|
|
return buildDisabledButton(statusText);
|
|
}
|
|
}
|
|
|
|
Widget buildDisabledButton(String text) {
|
|
return ShowFillButton(
|
|
backgroundColor: MyColors.grey98Color.withOpacity(0.3),
|
|
txtColor: MyColors.lightTextColor,
|
|
maxWidth: double.infinity,
|
|
margin: const EdgeInsets.all(15),
|
|
maxHeight: 55,
|
|
title: text,
|
|
isBold: false,
|
|
onPressed: () {},
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: const CustomAppBar(
|
|
title: "Request Detail",
|
|
),
|
|
body: SizedBox(
|
|
width: double.infinity,
|
|
height: double.infinity,
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Column(
|
|
children: [
|
|
Image.asset(MyAssets.bnCar),
|
|
24.height,
|
|
buildRequestContainer(context),
|
|
],
|
|
).toWhiteContainer(
|
|
width: double.infinity,
|
|
allPading: 12,
|
|
margin: const EdgeInsets.only(
|
|
top: 21,
|
|
right: 21,
|
|
left: 21,
|
|
),
|
|
),
|
|
if (!requestDetailPageArguments.requestModel.isChatted) ...[
|
|
ShowFillButton(
|
|
maxWidth: double.infinity,
|
|
margin: const EdgeInsets.all(15),
|
|
maxHeight: 55,
|
|
title: "Send Offer",
|
|
isBold: false,
|
|
fontSize: 18,
|
|
onPressed: () => buildSendOfferBottomSheet(context),
|
|
),
|
|
] else ...[
|
|
buildBottomButton(
|
|
requestStatus: requestDetailPageArguments.requestModel.requestStatus,
|
|
statusText: "Offer ${requestDetailPageArguments.requestModel.requestStatusName}",
|
|
context: context,
|
|
onViewChatTapped: () async {
|
|
ChatViewArguments chatViewArguments = ChatViewArguments(
|
|
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
|
|
);
|
|
|
|
final chatVM = context.read<ChatVM>();
|
|
await chatVM
|
|
.getUsersChatMessagesForProvider(
|
|
customerId: requestDetailPageArguments.requestModel.customerId,
|
|
context: context,
|
|
requestOfferId: 0,
|
|
requestId: requestDetailPageArguments.requestModel.id,
|
|
customerRequestIndex: requestDetailPageArguments.requestIndex,
|
|
)
|
|
.whenComplete(
|
|
() => navigateWithName(
|
|
context,
|
|
AppRoutes.chatView,
|
|
arguments: chatViewArguments,
|
|
),
|
|
);
|
|
},
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget buildRequestContainer(BuildContext context) {
|
|
final requestDetail = requestDetailPageArguments.requestModel;
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: [
|
|
requestDetail.vehicleTypeName.toText(fontSize: 16, isBold: true),
|
|
showItem("Manufacturer:", requestDetail.brand),
|
|
showItem("Model:", "${requestDetail.year}"),
|
|
],
|
|
),
|
|
),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: [
|
|
"${requestDetail.city ?? ""} ${requestDetail.countryName}".toText(
|
|
color: MyColors.lightTextColor,
|
|
),
|
|
requestDetail.createdOn.getTimeAgo().toText(color: MyColors.lightTextColor),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
showItem("Customer Name", requestDetail.customerName),
|
|
showItem("Description", requestDetail.description),
|
|
showItem("Price Range:", ""),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
children: [
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
children: [
|
|
"${requestDetail.price.toInt()}".toText(fontSize: 25, isBold: true),
|
|
2.width,
|
|
"SAR".toText(color: MyColors.lightTextColor, fontSize: 16, height: 2.3),
|
|
],
|
|
),
|
|
Row(
|
|
children: [
|
|
Utils.statusContainerChip(
|
|
text: "Offer ${requestDetail.requestStatusName}",
|
|
chipColor: MyColors.grey98Color.withOpacity(0.3),
|
|
textColor: MyColors.lightTextColor,
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
// const Icon(Icons.arrow_forward)
|
|
],
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget showItem(String title, String value) {
|
|
return Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
if (title.isNotEmpty)
|
|
title.toText(
|
|
color: MyColors.lightTextColor,
|
|
),
|
|
if (title.isNotEmpty) 2.width,
|
|
if (value.isNotEmpty) Expanded(child: value.toText(isBold: true)),
|
|
],
|
|
);
|
|
}
|
|
}
|