messageSendView method
dynamic
messageSendView()
Implementation
messageSendView() {
return Container(
padding: const EdgeInsets.only(top: 6, bottom: 6),
decoration: BoxDecoration(color: widget.theme!.palette.getAccent200()),
child: Column(
children: [
Obx(() => isReplied.value
? Container(
margin: const EdgeInsets.only(left: 20, right: 20, bottom: 8),
decoration: BoxDecoration(
color: widget.theme!.palette.getAccent100(),
borderRadius: BorderRadius.circular(8),
),
child: IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: 4.0,
decoration: BoxDecoration(
color: widget.theme!.palette.getAccent800(),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(8.0),
bottomLeft: Radius.circular(8.0),
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.only(
top: 12, bottom: 12, left: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Obx(() => Text(
repliedMessage.value.sentBy ==
AppStorages.myUserId
? AppStorages.languageKey!["you"]!
: repliedMessage.value.senderName!,
style: CustomTextStyles.medium(
fontSize: 14.0,
fontColor: widget.theme!.palette.getAccent800()),
overflow: TextOverflow.ellipsis,
)),
const SizedBox(height: 4),
Obx(() => Text(
repliedMessage.value.type == "text"
? repliedMessage.value.message!
: repliedMessage.value.fileName!,
style: CustomTextStyles.normal(
fontSize: 12.0,
fontColor: widget.theme!.palette.getAccent600()),
overflow: TextOverflow.ellipsis,
))
],
),
)),
repliedMessage.value.type != "text"
? Stack(
alignment: Alignment.topRight,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(4.0),
child: repliedMessage.value.type ==
"document"
? Padding(
padding: const EdgeInsets.all(8.0),
child: Center(
child: Container(
height: 35,
width: 35,
decoration: BoxDecoration(
color: widget.theme!.palette.getAccent800(),
borderRadius:
BorderRadius.circular(40),
),
child: const Icon(
Icons.attach_file,
color: Colors.white,
size: 20,
),
),
),
)
:repliedMessage.value.type =="audio"?Padding(
padding: const EdgeInsets.all(8.0),
child: Center(
child: Container(
height: 35,
width: 35,
decoration: BoxDecoration(
color: widget.theme!.palette.getAccent800(),
borderRadius:
BorderRadius.circular(40),
),
child: const Icon(
Icons.audiotrack,
color: Colors.white,
size: 20,
),
),
),
) :repliedMessage.value.filePath!.isURL
? Hero(
tag: 'htg_0',
child: CachedNetworkImage(
fadeInDuration:
const Duration(
milliseconds: 250),
height: 60,
width: 52,
imageUrl: repliedMessage
.value.type ==
"video"
? repliedMessage.value
.thumbnailPath!
: repliedMessage
.value.filePath!,
errorWidget:
(context, url, error) =>
Opacity(
opacity: 0.9,
child: ClipRRect(
borderRadius:
BorderRadius
.circular(30.0),
child: Image.asset(
ImageResource
.groupPlaceHolder,
package: "aplus_chat",
),
),
),
fit: BoxFit.cover,
placeholder: ((context,
String s) =>
Image.asset(
ImageResource
.groupPlaceHolder,
height: 40,
width: 40,
package: "aplus_chat",
)),
))
: Image.file(
File(
repliedMessage.value.type ==
"video"
? repliedMessage.value
.thumbnailPath!
: repliedMessage
.value.filePath!,
),
height: 60,
width: 52,
)),
InkWell(
onTap: () {
isReplied.value = false;
},
child: Container(
margin: const EdgeInsets.only(
top: 2, right: 4),
padding: EdgeInsets.all(1.0),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: widget.theme!.palette.getAccent800()),
child: const Icon(
Icons.clear,color: Colors.white,
size: 12,
),
),
),
],
)
: IconButton(
onPressed: () {
isReplied.value = false;
},
icon: const Icon(Icons.clear),
),
],
),
),
)
: const SizedBox.shrink()),
Row(
children: [
IconButton(
onPressed: () {
showAttachDialog();
},
icon: Icon(Icons.attach_file,color: widget.theme!.palette.getAccent800(),)),
Expanded(
child: TextField(
// readOnly: true,
controller: messageSendController,
onChanged: (text) async {
if (!isTyping.value) {
startType = true;
isTyping.value = true;
typingSocket(
groupId: groupId,
userId: AppStorages.myUserId,
secKey: AppStorages.secKey,
name: groupData!.userName,
isTyping: "true");
Future.delayed(const Duration(seconds: 2)).whenComplete(() {
startType = false;
isTyping.value = false;
typingSocket(
groupId: groupId,
userId: AppStorages.myUserId,
secKey: AppStorages.secKey,
name: groupData!.userName,
isTyping: "false");
});
}
if (text.isEmpty) {
sendButtonEnable.value = false;
} else {
sendButtonEnable.value = true;
}
},
maxLines: 7,
minLines: 1,
style: const TextStyle(
// fontFamily: Styles.FontNameRegular,
color: Colors.black,
),
focusNode: focusNode,
textInputAction: TextInputAction.newline,
decoration: InputDecoration(
fillColor: Colors.white,
filled: true,
contentPadding: const EdgeInsets.only(left: 10, right: 10),
hintText: AppStorages.languageKey == null ?"Type a message":AppStorages.languageKey!["type_a_message"]!,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(6),
borderSide: BorderSide.none,
),
),
)),
hasSendMessagePermission
? Obx(
() => IconButton(
onPressed: sendButtonEnable.value
? () {
if(messageSendController.text.trim().isNotEmpty){
var sendMsgParam = {
"messageObj": {
"message": messageSendController.text,
"type": "text",
"sentBy": AppStorages.myUserId,
"senderName": groupData!.userName,
"replyUser": isReplied.value
? repliedMessage.value.senderName
: "",
"replyMsg": isReplied.value
? repliedMessage.value.type == "text"
? repliedMessage.value.message
: repliedMessage.value.type ==
"video"
? repliedMessage
.value.thumbnailPath
: repliedMessage.value.type ==
"image"
? repliedMessage
.value.filePath
: repliedMessage.value.fileName
: "",
"replyMsgId": isReplied.value
? repliedMessage.value.msgId
: "",
"replyUserId": isReplied.value
? repliedMessage.value.sentBy
: "",
"replyMsgType": isReplied.value
? repliedMessage.value.type
: ""
},
"groupId": groupId,"fileName": repliedMessage.value.fileName,
"secretKey": AppStorages.secKey,
"userId": AppStorages.myUserId
};
DateTime now = DateTime.now();
int timestamp = now.millisecondsSinceEpoch;
conversationList.insert(
0,
Message(
time: timestamp ~/ 1000,
timeMilliSeconds: TimeMilliSeconds(
seconds: timestamp ~/ 1000,
nanoseconds: timestamp ~/ 1000),
sentBy: AppStorages.myUserId,
senderName: groupData!.userName,
type: "text",
msgId: isReplied.value
? repliedMessage.value.msgId
: "",
message: messageSendController.text,
contentType: "",
replyUser: isReplied.value
? repliedMessage.value.senderName
: "",
replyMsg: isReplied.value
? repliedMessage.value.type == "text"
? repliedMessage.value.message
: repliedMessage.value.type ==
"video"
? repliedMessage
.value.thumbnailPath
: repliedMessage.value.type ==
"image"
? repliedMessage
.value.filePath
: repliedMessage
.value.name
: "",
replyMsgId: isReplied.value
? repliedMessage.value.msgId
: "",
replyUserId: isReplied.value
? repliedMessage.value.sentBy
: "",
replyMsgType: isReplied.value
? repliedMessage.value.type
: "",
fileName: repliedMessage.value.fileName,
filePath: "",
name: "",
));
sendMessage(sendMsgParam);
autoScrollController.animateTo(
autoScrollController.position.minScrollExtent,
duration: const Duration(milliseconds: 1600),
curve: Curves.easeOut,
);
isReplied.value = false;
messageSendController.clear();
sendButtonEnable.value = false;}
}
: null,
icon: Icon(
Icons.send_sharp,
color: sendButtonEnable.value
?widget.theme!.palette.getAccent800()
: widget.theme!.palette.getAccent400(),
),
),
)
: const SizedBox.shrink()
],
),
],
),
);
}