import 'package:flutter/material.dart'; import 'package:mc_common_app/classes/consts.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/widgets/button/show_fill_button.dart'; import 'package:mc_common_app/widgets/common_widgets/app_bar.dart'; import 'package:mc_common_app/widgets/extensions/extensions_widget.dart'; import 'package:mc_common_app/widgets/txt_field.dart'; class ChatView extends StatelessWidget { const ChatView({super.key}); @override Widget build(BuildContext context) { return Scaffold( appBar: const CustomAppBar(title: "Chat"), body: Column( children: [ Expanded( child: ListView.separated( itemCount: 15, separatorBuilder: (BuildContext context, int index) => 20.height, itemBuilder: (BuildContext context, int index) { return ChatMessageCustomWidget( isSent: index.isOdd, profileUrl: MyAssets.bnCar, messageText: "Hi, How Are you? I can help you out with the desired request.", messageTypeEnum: index == 10 ? (MessageTypeEnum.newOfferRequired) : index == 12 ? (MessageTypeEnum.offerProvided) : (MessageTypeEnum.text), senderName: "Al Abdullah Cars", ); }).horPaddingMain(), ), 10.width, Row( crossAxisAlignment: CrossAxisAlignment.center, children: [ Expanded( flex: 7, child: TxtField( // value: adVM.vehicleDemandAmount, // errorValue: adVM.demandAmountError, hint: "Type your message here..", keyboardType: TextInputType.text, isNeedBorder: false, onChanged: (v) => null, ), ), Expanded( flex: 1, child: const Icon( Icons.send_rounded, color: MyColors.darkPrimaryColor, size: 30, ).onPress(() {})) ], ).toContainer(isShadowEnabled: true), ], ), // body: ); } } class ChatMessageCustomWidget extends StatelessWidget { final String profileUrl; final String senderName; final String messageText; final MessageTypeEnum messageTypeEnum; final bool isSent; const ChatMessageCustomWidget({ super.key, required this.profileUrl, required this.senderName, required this.messageText, required this.messageTypeEnum, required this.isSent, }); @override Widget build(BuildContext context) { return Directionality( textDirection: isSent ? TextDirection.rtl : TextDirection.ltr, child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Expanded( flex: 1, child: Image.asset( profileUrl, width: 34, height: 34, fit: BoxFit.fill, ).toCircle(borderRadius: 100), ), 10.width, Expanded( flex: 10, child: Column( children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.start, children: [ (isSent ? "You" : senderName).toText(fontSize: 16, isBold: true), ], ), 5.height, Column( children: [ Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Expanded( child: messageText.toText( color: isSent ? MyColors.white : MyColors.lightTextColor, fontSize: 12, // isBold: true, ), ), ], ), if (messageTypeEnum == MessageTypeEnum.offerProvided || messageTypeEnum == MessageTypeEnum.newOfferRequired) ...[ 5.height, Row( crossAxisAlignment: CrossAxisAlignment.end, children: [ "40000".toText(fontSize: 19, isBold: true), 2.width, "SAR".toText(color: MyColors.lightTextColor, height: 2.2, fontSize: 10, isBold: true), ], ), 10.height, if (messageTypeEnum == MessageTypeEnum.newOfferRequired) ...[ Center( child: "You asked for the new offer.".toText( color: MyColors.adPendingStatusColor, fontSize: 12, isItalic: true, ), ).toContainer(borderRadius: 40, width: double.infinity, backgroundColor: MyColors.adPendingStatusColor.withOpacity(0.16)), ] else ...[ Row( children: [ Expanded( child: ShowFillButton( maxHeight: 27, title: "Accept", fontSize: 9, borderColor: MyColors.greenColor, isFilled: false, onPressed: () {}, backgroundColor: MyColors.white, txtColor: MyColors.greenColor, ), ), 20.width, Expanded( child: ShowFillButton( maxHeight: 27, title: "Reject", borderColor: MyColors.redColor, isFilled: false, onPressed: () {}, backgroundColor: MyColors.white, txtColor: MyColors.redColor, fontSize: 9, ), ) ], ), ], ], ], ).toContainer( isShadowEnabled: !isSent, backgroundColor: isSent ? MyColors.darkIconColor : MyColors.white, borderRadius: 0, margin: EdgeInsets.fromLTRB(isSent ? 25 : 0, 0, !isSent ? 25 : 0, 0), ), ], ), ) ], ), ); } } enum MessageTypeEnum { text, picture, offerProvided, recording, video, newOfferRequired }