@ -6,6 +6,7 @@ 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/generated/locale_keys.g.dart ' ;
import ' package:mc_common_app/models/chat_models/chat_message_model.dart ' ;
import ' package:mc_common_app/models/requests_models/request_model.dart ' ;
import ' package:mc_common_app/theme/colors.dart ' ;
@ -19,6 +20,7 @@ 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 ' ;
import ' package:easy_localization/easy_localization.dart ' as lcl ;
class ChatView extends StatelessWidget {
final ChatViewArguments chatViewArguments ;
@ -32,11 +34,15 @@ class ChatView extends StatelessWidget {
isScrollControlled: true ,
enableDrag: true ,
builder: ( BuildContext context ) {
return Consumer ( builder: ( BuildContext context , RequestsVM requestsVM , Widget ? child ) {
return Consumer ( builder:
( BuildContext context , RequestsVM requestsVM , Widget ? child ) {
return InfoBottomSheet (
title: " Make an offer " . toText ( fontSize: 28 , isBold: true , letterSpacing: - 1.44 ) ,
title: LocaleKeys . makeAnOffer
. tr ( )
. toText ( fontSize: 28 , isBold: true , letterSpacing: - 1.44 ) ,
description: Padding (
padding: EdgeInsets . only ( bottom: MediaQuery . of ( context ) . viewInsets . bottom ) ,
padding: EdgeInsets . only (
bottom: MediaQuery . of ( context ) . viewInsets . bottom ) ,
child: Column (
crossAxisAlignment: CrossAxisAlignment . start ,
children: [
@ -48,7 +54,7 @@ class ChatView extends StatelessWidget {
value: requestsVM . offerPrice ,
errorValue: requestsVM . offerPriceError ,
keyboardType: TextInputType . number ,
hint: " Enter amount " ,
hint: LocaleKeys . enterAmount . tr ( ) ,
onChanged: ( v ) = > requestsVM . updateOfferPrice ( v ) ,
) ,
12. height ,
@ -57,14 +63,15 @@ class ChatView extends StatelessWidget {
value: requestsVM . offerDescription ,
errorValue: requestsVM . offerDescriptionError ,
keyboardType: TextInputType . text ,
hint: " Description " ,
onChanged: ( v ) = > requestsVM . updateOfferDescription ( v ) ,
hint: LocaleKeys . description . tr ( ) ,
onChanged: ( v ) = >
requestsVM . updateOfferDescription ( v ) ,
) ,
] ,
) ,
25. height ,
ShowFillButton (
title: " Submit " ,
title: LocaleKeys . submit . tr ( ) ,
onPressed: ( ) {
requestsVM . onSendOfferPressed (
context: context ,
@ -91,22 +98,30 @@ class ChatView extends StatelessWidget {
@ override
Widget build ( BuildContext context ) {
return Scaffold (
appBar: const CustomAppBar ( title: " Chat " ) ,
body: Consumer2 < ChatVM , RequestsVM > ( builder: ( BuildContext context , ChatVM chatVM , RequestsVM requestVM , Widget ? child ) {
appBar: CustomAppBar ( title: LocaleKeys . chat . tr ( ) ) ,
body: Consumer2 < ChatVM , RequestsVM > ( builder: ( BuildContext context ,
ChatVM chatVM , RequestsVM requestVM , Widget ? child ) {
final chatMessages = AppState ( ) . currentAppType = = AppType . customer
? chatVM . serviceProviderOffersList [ chatViewArguments . providerIndex ] . chatMessages
: requestVM . myFilteredRequests [ chatViewArguments . requestIndex ] . chatMessages ;
? chatVM . serviceProviderOffersList [ chatViewArguments . providerIndex ]
. chatMessages
: requestVM . myFilteredRequests [ chatViewArguments . requestIndex ]
. chatMessages ;
return chatMessages = = null
? Center ( child: " No Requests to show. " . toText ( fontSize: 16 , color: MyColors . lightTextColor ) )
? Center (
child: LocaleKeys . noRequestsShow
. tr ( )
. toText ( fontSize: 16 , color: MyColors . lightTextColor ) )
: Column (
children: [
Expanded (
child: ListView . separated (
itemCount: chatMessages . length ,
separatorBuilder: ( BuildContext context , int index ) = > 20. height ,
separatorBuilder: ( BuildContext context , int index ) = >
20. height ,
itemBuilder: ( BuildContext context , int index ) {
ChatMessageModel chatMessageModel = chatMessages [ index ] ;
return ChatMessageCustomWidget ( chatMessageModel: chatMessageModel ) ;
return ChatMessageCustomWidget (
chatMessageModel: chatMessageModel ) ;
} ,
) . horPaddingMain ( ) ,
) ,
@ -132,7 +147,7 @@ class ChatView extends StatelessWidget {
flex: 8 ,
child: TxtField (
value: chatVM . chatMessageText ,
hint: " Type your message here.. " ,
hint: LocaleKeys . typeMessageHere . tr ( ) ,
keyboardType: TextInputType . text ,
isNeedBorder: false ,
onChanged: ( v ) = > chatVM . updateChatMessageText ( v ) ,
@ -178,7 +193,8 @@ class ChatMessageCustomWidget extends StatefulWidget {
const ChatMessageCustomWidget ( { super . key , required this . chatMessageModel } ) ;
@ override
State < ChatMessageCustomWidget > createState ( ) = > _ChatMessageCustomWidgetState ( ) ;
State < ChatMessageCustomWidget > createState ( ) = >
_ChatMessageCustomWidgetState ( ) ;
}
class _ChatMessageCustomWidgetState extends State < ChatMessageCustomWidget > {
@ -188,11 +204,15 @@ class _ChatMessageCustomWidgetState extends State<ChatMessageCustomWidget> {
isScrollControlled: true ,
enableDrag: true ,
builder: ( BuildContext context ) {
return Consumer ( builder: ( BuildContext context , ChatVM chatVM , Widget ? child ) {
return Consumer (
builder: ( BuildContext context , ChatVM chatVM , Widget ? child ) {
return InfoBottomSheet (
title: " Make an offer " . toText ( fontSize: 28 , isBold: true , letterSpacing: - 1.44 ) ,
title: LocaleKeys . makeAnOffer
. tr ( )
. toText ( fontSize: 28 , isBold: true , letterSpacing: - 1.44 ) ,
description: Padding (
padding: EdgeInsets . only ( bottom: MediaQuery . of ( context ) . viewInsets . bottom ) ,
padding: EdgeInsets . only (
bottom: MediaQuery . of ( context ) . viewInsets . bottom ) ,
child: Column (
crossAxisAlignment: CrossAxisAlignment . start ,
children: [
@ -203,14 +223,18 @@ class _ChatMessageCustomWidgetState extends State<ChatMessageCustomWidget> {
ListView . separated (
shrinkWrap: true ,
itemCount: chatVM . offerRejectModelList . length ,
separatorBuilder: ( BuildContext context , int index ) = > const Divider ( thickness: 0.5 ) ,
separatorBuilder: ( BuildContext context , int index ) = >
const Divider ( thickness: 0.5 ) ,
itemBuilder: ( BuildContext context , int index ) {
OfferRequestCommentModel offerRequestCommentModel = chatVM . offerRejectModelList [ index ] ;
OfferRequestCommentModel offerRequestCommentModel =
chatVM . offerRejectModelList [ index ] ;
return CircleCheckBoxWithTitle (
isChecked: offerRequestCommentModel . isSelected ? ? false ,
isChecked:
offerRequestCommentModel . isSelected ? ? false ,
title: ' ${ offerRequestCommentModel . title } ' ,
onSelected: ( ) {
chatVM . updateSelectionInOfferRejectModelList ( index ) ;
chatVM . updateSelectionInOfferRejectModelList (
index ) ;
} ,
selectedColor: MyColors . darkPrimaryColor ,
) ;
@ -222,14 +246,15 @@ class _ChatMessageCustomWidgetState extends State<ChatMessageCustomWidget> {
value: chatVM . rejectOfferDescription ,
errorValue: chatVM . rejectOfferDescriptionError ,
keyboardType: TextInputType . text ,
hint: " Description " ,
onChanged: ( v ) = > chatVM . updateRejectOfferDescription ( v ) ,
hint: LocaleKeys . description . tr ( ) ,
onChanged: ( v ) = >
chatVM . updateRejectOfferDescription ( v ) ,
) ,
] ,
) ,
25. height ,
ShowFillButton (
title: " Submit " ,
title: LocaleKeys . submit . tr ( ) ,
onPressed: ( ) { } ,
maxWidth: double . infinity ,
) ,
@ -242,8 +267,12 @@ class _ChatMessageCustomWidgetState extends State<ChatMessageCustomWidget> {
) ;
}
Widget buildOfferDetailsInChatMessage ( { required ChatMessageModel chatMessageModel , required BuildContext context } ) {
final requestOfferStatusEnum = chatMessageModel . reqOffer ! . requestOfferStatusEnum ? ? RequestOfferStatusEnum . offer ;
Widget buildOfferDetailsInChatMessage (
{ required ChatMessageModel chatMessageModel ,
required BuildContext context } ) {
final requestOfferStatusEnum =
chatMessageModel . reqOffer ! . requestOfferStatusEnum ? ?
RequestOfferStatusEnum . offer ;
switch ( requestOfferStatusEnum ) {
case RequestOfferStatusEnum . offer:
@ -253,9 +282,18 @@ class _ChatMessageCustomWidgetState extends State<ChatMessageCustomWidget> {
Row (
crossAxisAlignment: CrossAxisAlignment . end ,
children: [
" ${ chatMessageModel . reqOffer ! . price } " . toText ( fontSize: 19 , isBold: true , color: AppState ( ) . currentAppType = = AppType . provider ? MyColors . white : MyColors . darkTextColor ) ,
" ${ chatMessageModel . reqOffer ! . price } " . toText (
fontSize: 19 ,
isBold: true ,
color: AppState ( ) . currentAppType = = AppType . provider
? MyColors . white
: MyColors . darkTextColor ) ,
5. width ,
" SAR " . toText ( color: MyColors . lightTextColor , height: 2.2 , fontSize: 10 , isBold: true ) ,
LocaleKeys . sar . tr ( ) . toText (
color: MyColors . lightTextColor ,
height: 2.2 ,
fontSize: 10 ,
isBold: true ) ,
] ,
) ,
if ( widget . chatMessageModel . isMyMessage = = false ) . . . [
@ -265,21 +303,24 @@ class _ChatMessageCustomWidgetState extends State<ChatMessageCustomWidget> {
Expanded (
child: ShowFillButton (
maxHeight: 27 ,
title: " Accept " ,
title: LocaleKeys . accept . tr ( ) ,
fontSize: 9 ,
borderColor: MyColors . greenColor ,
isFilled: false ,
onPressed: ( ) async {
int status = await context . read < ChatVM > ( ) . onActionOfferTapped (
context: context ,
requestOfferStatusEnum: RequestOfferStatusEnum . accepted ,
reqOfferId: chatMessageModel . reqOfferID ? ? - 1 ,
) ;
int status =
await context . read < ChatVM > ( ) . onActionOfferTapped (
context: context ,
requestOfferStatusEnum:
RequestOfferStatusEnum . accepted ,
reqOfferId: chatMessageModel . reqOfferID ? ? - 1 ,
) ;
if ( status ! = - 1 ) {
log ( " accepted: $ status " ) ;
if ( chatMessageModel . reqOfferID = = status ) {
chatMessageModel . reqOffer ! . requestOfferStatusEnum = RequestOfferStatusEnum . accepted ;
chatMessageModel . reqOffer ! . requestOfferStatusEnum =
RequestOfferStatusEnum . accepted ;
setState ( ( ) { } ) ;
}
}
@ -292,7 +333,7 @@ class _ChatMessageCustomWidgetState extends State<ChatMessageCustomWidget> {
Expanded (
child: ShowFillButton (
maxHeight: 27 ,
title: " Reject " ,
title: LocaleKeys . reject . tr ( ) ,
borderColor: MyColors . redColor ,
isFilled: false ,
backgroundColor: MyColors . white ,
@ -312,48 +353,64 @@ class _ChatMessageCustomWidgetState extends State<ChatMessageCustomWidget> {
return Column (
children: [
Center (
child: " New Offer Required. " . toText (
color: MyColors . adPendingStatusColor ,
fontSize: 12 ,
isItalic: true ,
) ,
) . toContainer ( borderRadius: 40 , width: double . infinity , backgroundColor: MyColors . adPendingStatusColor . withOpacity ( 0.16 ) ) ,
child: LocaleKeys . newOfferRequired . tr ( ) . toText (
color: MyColors . adPendingStatusColor ,
fontSize: 12 ,
isItalic: true ,
) ,
) . toContainer (
borderRadius: 40 ,
width: double . infinity ,
backgroundColor:
MyColors . adPendingStatusColor . withOpacity ( 0.16 ) ) ,
] ,
) ;
case RequestOfferStatusEnum . accepted:
return Column (
children: [
Center (
child: " Offer has been accepted. " . toText (
color: MyColors . adPendingStatusColor ,
fontSize: 12 ,
isItalic: true ,
) ,
) . toContainer ( borderRadius: 40 , width: double . infinity , backgroundColor: MyColors . adPendingStatusColor . withOpacity ( 0.16 ) ) ,
child: LocaleKeys . offerHasBeenAccepted . tr ( ) . toText (
color: MyColors . adPendingStatusColor ,
fontSize: 12 ,
isItalic: true ,
) ,
) . toContainer (
borderRadius: 40 ,
width: double . infinity ,
backgroundColor:
MyColors . adPendingStatusColor . withOpacity ( 0.16 ) ) ,
] ,
) ;
case RequestOfferStatusEnum . rejected:
return Column (
children: [
Center (
child: " Offer has been rejected. " . toText (
color: MyColors . adPendingStatusColor ,
fontSize: 12 ,
isItalic: true ,
) ,
) . toContainer ( borderRadius: 40 , width: double . infinity , backgroundColor: MyColors . adPendingStatusColor . withOpacity ( 0.16 ) ) ,
child: LocaleKeys . offerHasBeenRejected . tr ( ) . toText (
color: MyColors . adPendingStatusColor ,
fontSize: 12 ,
isItalic: true ,
) ,
) . toContainer (
borderRadius: 40 ,
width: double . infinity ,
backgroundColor:
MyColors . adPendingStatusColor . withOpacity ( 0.16 ) ) ,
] ,
) ;
case RequestOfferStatusEnum . cancel:
return Column (
children: [
Center (
child: " Offer has been cancelled. " . toText (
color: MyColors . adPendingStatusColor ,
fontSize: 12 ,
isItalic: true ,
) ,
) . toContainer ( borderRadius: 40 , width: double . infinity , backgroundColor: MyColors . adPendingStatusColor . withOpacity ( 0.16 ) ) ,
child: LocaleKeys . offerHasBeenCancelled . tr ( ) . toText (
color: MyColors . adPendingStatusColor ,
fontSize: 12 ,
isItalic: true ,
) ,
) . toContainer (
borderRadius: 40 ,
width: double . infinity ,
backgroundColor:
MyColors . adPendingStatusColor . withOpacity ( 0.16 ) ) ,
] ,
) ;
}
@ -362,7 +419,9 @@ class _ChatMessageCustomWidgetState extends State<ChatMessageCustomWidget> {
@ override
Widget build ( BuildContext context ) {
return Directionality (
textDirection: ( widget . chatMessageModel . isMyMessage ? ? false ) ? TextDirection . rtl : TextDirection . ltr ,
textDirection: ( widget . chatMessageModel . isMyMessage ? ? false )
? TextDirection . rtl
: TextDirection . ltr ,
child: Row (
crossAxisAlignment: CrossAxisAlignment . start ,
children: [
@ -384,7 +443,10 @@ class _ChatMessageCustomWidgetState extends State<ChatMessageCustomWidget> {
mainAxisAlignment: MainAxisAlignment . spaceBetween ,
crossAxisAlignment: CrossAxisAlignment . start ,
children: [
( ( widget . chatMessageModel . isMyMessage ? ? false ) ? " You " : widget . chatMessageModel . senderName ? ? " " ) . toText ( fontSize: 16 , isBold: true ) ,
( ( widget . chatMessageModel . isMyMessage ? ? false )
? " You "
: widget . chatMessageModel . senderName ? ? " " )
. toText ( fontSize: 16 , isBold: true ) ,
] ,
) ,
5. height ,
@ -396,8 +458,12 @@ class _ChatMessageCustomWidgetState extends State<ChatMessageCustomWidget> {
Expanded (
child: Directionality (
textDirection: TextDirection . ltr ,
child: ( widget . chatMessageModel . chatText ? ? " " ) . toText (
color: ( widget . chatMessageModel . isMyMessage ? ? false ) ? MyColors . white : MyColors . lightTextColor ,
child:
( widget . chatMessageModel . chatText ? ? " " ) . toText (
color:
( widget . chatMessageModel . isMyMessage ? ? false )
? MyColors . white
: MyColors . lightTextColor ,
fontSize: 12 ,
/ / isBold: true ,
@ -406,15 +472,26 @@ class _ChatMessageCustomWidgetState extends State<ChatMessageCustomWidget> {
) ,
] ,
) ,
if ( widget . chatMessageModel . chatMessageTypeEnum = = ChatMessageTypeEnum . offer ) . . . [
buildOfferDetailsInChatMessage ( chatMessageModel: widget . chatMessageModel , context: context ) ,
if ( widget . chatMessageModel . chatMessageTypeEnum = =
ChatMessageTypeEnum . offer ) . . . [
buildOfferDetailsInChatMessage (
chatMessageModel: widget . chatMessageModel ,
context: context ) ,
] ,
] ,
) . toContainer (
isShadowEnabled: ! ( widget . chatMessageModel . isMyMessage ? ? false ) ,
backgroundColor: ( widget . chatMessageModel . isMyMessage ? ? false ) ? MyColors . darkIconColor : MyColors . white ,
isShadowEnabled:
! ( widget . chatMessageModel . isMyMessage ? ? false ) ,
backgroundColor:
( widget . chatMessageModel . isMyMessage ? ? false )
? MyColors . darkIconColor
: MyColors . white ,
borderRadius: 0 ,
margin: EdgeInsets . fromLTRB ( ( widget . chatMessageModel . isMyMessage ? ? false ) ? 25 : 0 , 0 , ! ( widget . chatMessageModel . isMyMessage ? ? false ) ? 25 : 0 , 0 ) ,
margin: EdgeInsets . fromLTRB (
( widget . chatMessageModel . isMyMessage ? ? false ) ? 25 : 0 ,
0 ,
! ( widget . chatMessageModel . isMyMessage ? ? false ) ? 25 : 0 ,
0 ) ,
) ,
] ,
) ,