getMessage method
Implementation
getMessage(BuildContext context) {
bool isOtherUser = messageModal.from!=chatController.currentUserId;
customPrint('The message is of ${messageModal.from}(Current: ${chatController.currentUserId} ) ${messageModal.message}');
switch (messageModal.messageType) {
case MessageType.image:
{
return Stack(
children: [
Padding(
padding: const EdgeInsets.symmetric(vertical: 5),
child: InkWell(
onTap: () {
if (messageModal.fromServer) {
/* CustomNavigation.push(
context: context,
screen: ZoomableImage(
imageProvider:
NetworkImage(messageModal.message)));*/
CustomNavigation.push(
context,
screen: ImageWidget(
image: [
messageModal.message,
// messageModal.message,
],
fileType: CustomFileType.network,
isDownloadIcon: true,
width: MediaQuery.of(context).size.width,
));
} else {
showSnackbar(context: context,'Please Wait for file to upload');
}
},
child: Stack(
alignment: Alignment.bottomRight,
children: [
CustomImage(
borderRadius: 20,
showLoader: true,
imageUrl: messageModal.message,
// staticBlurImage: MyImagesUrl.blurImage,
fileType: messageModal.fromServer
? CustomFileType.network
: CustomFileType.file,
image: messageModal.fromServer
? null
: File(messageModal.message),
width: customSize,
height: customSize,
),
Padding(
padding: const EdgeInsets.only(bottom: 7,right: 10),
child: CustomText.heading(
CustomTimeFunctions.formatTimeForChat(TimeOfDay.fromDateTime(messageModal.createdAt.toDate())),
fontWeight: FontWeight.w400,
color: TempColors.blackColor,
fontSize: 10,
),
)
],
),
),
),
if (messageModal.fromServer == false)
Positioned(
top: 0,
bottom: 0,
left: 0,
right: 0,
child: ValueListenableBuilder<int>(
valueListenable:
messageModal.progress ?? ValueNotifier(0),
builder: (context, value, child) {
// if (value == 0) {
// return Container(
// decoration: BoxDecoration(
// color: Colors.black.withOpacity(0.4),
// borderRadius: BorderRadius.circular(20),
// ),
// child: const Center(
// child: Padding(
// padding: EdgeInsets.only(top: 120),
// child: CustomText.bodyText1(text)("Uploading",
// color: TempColors.whiteColor,
// fontSize: 14,
// fontWeight: FontWeight.w600),
// ),
// ),
// );
// }
return Stack(
alignment: isOtherUser? Alignment.bottomLeft: Alignment.bottomRight,
children: [
Container(
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.4),
borderRadius: BorderRadius.circular(20),
),
child:
Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CustomLoader(
color: TempColors.whiteColor,
),
Padding(
padding: EdgeInsets.only(top: 10),
child: CustomText.bodyText1("Uploading ${value}% Complete",
color: TempColors.whiteColor,
fontSize: 14,
fontWeight: FontWeight.w600),
),
],
),
)
/*Center(
child: CircularProgressIndicator(
value: value / 100,
color: CustomStylesConfig.primaryColor,
),
),*/
),
Padding(
padding: const EdgeInsets.only(bottom: 7,right: 10),
child: CustomText.heading(
CustomTimeFunctions.formatTimeForChat(TimeOfDay.fromDateTime(messageModal.createdAt.toDate())),
fontWeight: FontWeight.w400,
color: TempColors.whiteColor,
fontSize: 10,
),
)
],
);
}),
),
if (messageModal.fromServer == false)
InkWell(
onTap: () {
// ChatDetailProvider ch =
// Provider.of<ChatDetailProvider>(context, listen: false);
Map<int, ChatModal> innerMap = chatController.tempChats[
chatController.chatId] ??
{};
innerMap.remove(int.parse(messageModal.id!));
chatController.reload();
},
child: SizedBox(
height: customSize,
width: customSize,
child: Padding(
padding: const EdgeInsets.only(right: 10, top: 10),
child: Align(
alignment: Alignment.topRight,
child: Container(
height: 40,
width: 40,
padding: const EdgeInsets.all(6),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: TempColors.whiteColor, width: 1)),
child: const Icon(Icons.close,
color: TempColors.whiteColor),
),
),
),
),
)
],
);
}
case MessageType.location:
{
List temp = messageModal.message.split(",");
double latitude = double.tryParse(temp[0])??0;
double longitude = double.tryParse(temp[0])??0;
return Padding(
padding: const EdgeInsets.symmetric(vertical: 5),
child: InkWell(
onTap: () {
// GoogleMapServices.launchGoogleMap(
// latLng: LatLng(latLng.latitude, latLng.longitude));
launchGoogleMap(latitude, longitude);
// Uri url = Uri.parse(
// 'https://www.google.cn/maps/dir/Current+Location/${latitude},${longitude}');
// launchUrl(url);
},
child: Stack(
alignment: isOtherUser? Alignment.centerLeft: Alignment.centerRight,
children: [
CustomImage(
borderRadius: 20,
showLoader: true,
// staticBlurImage: MyImagesUrl.blurImage,
border: Border.all(color: TempColors.greyColor, width: 1),
imageUrl: getStaticMapImageUrl(
latitude, longitude),
fit: BoxFit.cover,
// overlayColor: CustomStylesConfig.primaryColor.withOpacity(opacity),
height: customSize + 10,
width: customSize + 10,
// width: double.infinity,
),
SizedBox(
height: customSize + 10,
width: customSize + 10,
child: Align(
alignment: Alignment.center,
child: Image.asset(
MyImagesUrl.coins,
height: 20,
width: 20,
),
),
),
SizedBox(
height: customSize + 10,
width: customSize + 10,
child: Align(
alignment: Alignment.bottomRight,
child: Padding(
padding: const EdgeInsets.only(bottom: 7,right: 10),
child: CustomText.heading(
CustomTimeFunctions.formatTimeForChat(TimeOfDay.fromDateTime(messageModal.createdAt.toDate())),
fontWeight: FontWeight.w400,
color: TempColors.blackColor,
fontSize: 10,
),
),
),
)
],
),
// width: 240,
// height: 170,
),
);
}
case MessageType.video:
{
if (messageModal.fromServer) {
try {
HS.insertBodyBytes(messageModal.message, messageModal.id!);
} catch (e) {
print('Error in catch block $e');
}
}
return Padding(
padding: const EdgeInsets.symmetric(vertical: 5),
child: InkWell(
onTap: () async {
if (messageModal.fromServer) {
var bytes = HS.getFile(messageModal.id!);
if (bytes != null) {
final tempDir = await getTemporaryDirectory();
final file = File('${tempDir.path}/${messageModal.id}.mp4');
await file.writeAsBytes(bytes, flush: true);
CachedVideoPlayerPlusController controller =
CachedVideoPlayerPlusController.file(
file,
);
await controller.initialize();
// ignore: use_build_context_synchronously
CustomNavigation.push(
context,
screen: VideoPlayerPage(
videoUrl: messageModal.message,
controller: controller,
durationMax: messageModal.durationInSeconds!,
));
} else {
CustomNavigation.push(
context,
screen: VideoPlayerPage(
videoUrl: messageModal.message,
durationMax: messageModal.durationInSeconds!,
));
}
} else {
showSnackbar('Please Wait for file to upload', context: context);
}
},
child: Stack(
children: [
Stack(
alignment: Alignment.bottomRight,
children: [
CustomImage(
borderRadius: 20,
showLoader: true,
// staticBlurImage: MyImagesUrl.blurImage,
imageUrl: messageModal.thumbnail ?? '',
fileType: messageModal.fromServer
? CustomFileType.network
: CustomFileType.file,
image: messageModal.fromServer
? null
: File(messageModal.thumbnail!),
width: customSize,
height: customSize,
),
Padding(
padding: const EdgeInsets.only(bottom: 7,right: 10),
child: CustomText.heading(
CustomTimeFunctions.formatTimeForChat(TimeOfDay.fromDateTime(messageModal.createdAt.toDate())),
fontWeight: FontWeight.w400,
color: TempColors.blackColor,
fontSize: 10,
),
)
],
),
if (messageModal.fromServer == true)
Positioned(
top: 0,
bottom: 0,
left: 0,
right: 0,
child: Center(
child:
// messageModal.fromServer==false?CustomLoader():
Container(
padding: const EdgeInsets.all(5),
// height: 50,
// width: 50,
clipBehavior: Clip.hardEdge,
decoration: BoxDecoration(
color: Colors.red,
// color: Colors.black,
borderRadius: BorderRadius.circular(40)),
child: const Icon(
Icons.play_arrow,
size: 32,
// color: Colors.red,
color: Colors.white,
),
),
),
),
if (messageModal.fromServer == false)
Positioned(
top: 0,
bottom: 0,
left: 0,
right: 0,
child: ValueListenableBuilder<int>(
valueListenable:
messageModal.progress ?? ValueNotifier(0),
builder: (context, value, child) {
return Container(
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.4),
borderRadius: BorderRadius.circular(20),
),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CustomLoader(
color: TempColors.whiteColor,
),
Padding(
padding: EdgeInsets.only(top: 10),
child: CustomText.bodyText1("Uploadingd ${value}2",
color: TempColors.whiteColor,
fontSize: 14,
fontWeight: FontWeight.w600),
),
],
),
));
}),
),
if (messageModal.fromServer == false)
InkWell(
onTap: () {
// ChatDetailProvider ch = Provider.of<ChatDetailProvider>(
// context,
// listen: false);
Map<int, ChatModal> innerMap = chatController.tempChats[
chatController.chatId] ??
{};
innerMap.remove(int.parse(messageModal.id!));
chatController.reload();
},
child: SizedBox(
height: customSize,
width: customSize,
child: Padding(
padding: const EdgeInsets.only(right: 10, top: 10),
child: Align(
alignment: Alignment.topRight,
child: Container(
height: 40,
width: 40,
padding: const EdgeInsets.all(6),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: TempColors.whiteColor, width: 1)),
child: const Icon(Icons.close,
color: TempColors.whiteColor),
),
),
),
),
)
],
),
),
);
}
/// TODO IMP 2: uncomment this if needed
// case MessageType.verificationVideo:
// {
//
//
// // if(isNormalChatSavedLocally){
// // if (messageModal.fromServer) {
// // try {
// // HS.insertBodyBytes(messageModal.message, messageModal.id!);
// // } catch (e) {
// // print('Error in catch block $e');
// // }
// // }
// // }
// //
// // return Padding(
// // padding: const EdgeInsets.symmetric(vertical: 5),
// // child: InkWell(
// // onTap: () async {
// // print('sdfdsaf ${messageModal.fromServer}');
// // // return;
// // if (messageModal.fromServer) {
// // var bytes = HS.getFile(messageModal.id!);
// // if (bytes != null) {
// // final tempDir = await getTemporaryDirectory();
// // final file = File('${tempDir.path}/${messageModal.id}.mp4');
// // await file.writeAsBytes(bytes, flush: true);
// // CachedVideoPlayerPlusController controller =
// // CachedVideoPlayerPlusController.file(
// // file,
// // );
// // await controller.initialize();
// // // ignore: use_build_context_synchronously
// // CustomNavigation.push(
// // context,
// // screen: VideoPlayerPage(
// // videoUrl: messageModal.message,
// // controller: controller,
// // durationMax: messageModal.durationInSeconds!,
// // ));
// // } else {
// // CustomNavigation.push(
// // context,
// // screen: VideoPlayerPage(
// // videoUrl: messageModal.message,
// // durationMax: messageModal.durationInSeconds!,
// // ));
// // }
// // } else {
// // showSnackbar('Please Wait for file to upload', context: context);
// // }
// // },
// // child: Stack(
// // children: [
// // Stack(
// // alignment: Alignment.bottomRight,
// // children: [
// // CustomImage(
// // borderRadius: 20,
// // showLoader: true,
// // // staticBlurImage: MyImagesUrl.blurImage,
// // // imageUrl: '${FirebaseService.getImageUrl(messageModal.thumbnail??'')}' ?? '',
// // fileType:messageModal.thumbnail==null?CustomFileType.asset:
// // messageModal.fromServer
// // ? CustomFileType.network
// // :
// // CustomFileType.file,
// // image:
// // messageModal.thumbnail==null?null:
// // messageModal.fromServer
// // ? null
// // :
// // File(messageModal.thumbnail!),
// // imageUrl:
// // messageModal.thumbnail==null?MyImagesUrl.heartAnimated:
// // messageModal.thumbnail ?? '',
// // width: customSize,
// // height: customSize,
// // ),
// // Padding(
// // padding: const EdgeInsets.only(bottom: 7,right: 10),
// // child: CustomText.heading(
// // CustomTimeFunctions.formatTimeForChat(TimeOfDay.fromDateTime(messageModal.createdAt.toDate())),
// // fontWeight: FontWeight.w400,
// // color: TempColors.blackColor,
// // fontSize: 10,
// // ),
// // )
// // ],
// // ),
// // if (messageModal.fromServer == true)
// // Positioned(
// // top: 0,
// // bottom: 0,
// // left: 0,
// // right: 0,
// // child: Center(
// // child:
// // Container(
// // padding: const EdgeInsets.all(5),
// // clipBehavior: Clip.hardEdge,
// // decoration: BoxDecoration(
// // color: Colors.red,
// // // color: Colors.black,
// // borderRadius: BorderRadius.circular(40)),
// //
// // child: const Icon(
// // Icons.play_arrow,
// // size: 32,
// // // color: Colors.red,
// // color: Colors.white,
// // ),
// // ),
// // ),
// // ),
// // if (messageModal.fromServer == false)
// // Positioned(
// // top: 0,
// // bottom: 0,
// // left: 0,
// // right: 0,
// // child: ValueListenableBuilder<int>(
// // valueListenable:
// // messageModal.progress ?? ValueNotifier(0),
// // builder: (context, value, child) {
// // return Container(
// // decoration: BoxDecoration(
// // color: Colors.black.withOpacity(0.4),
// // borderRadius: BorderRadius.circular(20),
// // ),
// // child: Center(
// // child: Column(
// // mainAxisAlignment: MainAxisAlignment.center,
// // children: [
// // CustomLoader(
// // color: TempColors.whiteColor,
// // ),
// // Padding(
// // padding: EdgeInsets.only(top: 10),
// // child: CustomText.bodyText1("Uploading ${value}% complete",
// // color: TempColors.whiteColor,
// // fontSize: 14,
// // fontWeight: FontWeight.w600),
// // ),
// // ],
// // ),
// // ));
// // }),
// // ),
// // if (messageModal.fromServer == false)
// // InkWell(
// // onTap: () {
// // ChatDetailProvider ch = Provider.of<ChatDetailProvider>(
// // context,
// // listen: false);
// // Map<int, ChatModal> innerMap = ch.tempChats[
// // chatController.chatId] ??
// // {};
// // innerMap.remove(int.parse(messageModal.id!));
// // ch.notifyListeners();
// // },
// // child: SizedBox(
// // height: customSize,
// // width: customSize,
// // child: Padding(
// // padding: const EdgeInsets.only(right: 10, top: 10),
// // child: Align(
// // alignment: Alignment.topRight,
// // child: Container(
// // height: 40,
// // width: 40,
// // padding: const EdgeInsets.all(6),
// // decoration: BoxDecoration(
// // borderRadius: BorderRadius.circular(20),
// // border: Border.all(
// // color: TempColors.whiteColor, width: 1)),
// // child: const Icon(Icons.close,
// // color: TempColors.whiteColor),
// // ),
// // ),
// // ),
// // ),
// // )
// // ],
// // ),
// // ),
// // );
// }
case MessageType.voiceMessage:
{
/* if (messageModal.fromServer == true) {
return VoiceMessageView(
controller: messageModal.voiceController!,
);
} else {
return Stack(
children: [
Container(
width: MediaQuery.of(context).size.width / 1.3,
padding:
const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
margin: const EdgeInsets.symmetric(vertical: 5),
decoration: BoxDecoration(
color: isOtherUser
? TempColors.greyColor.withOpacity(0.15)
: TempColors.lightPinkColor.withOpacity(0.3),
borderRadius: BorderRadius.circular(20)),
child: const Row(
children: [
SizedBox(
height: 50,
)
],
),
),
if (messageModal.fromServer == false)
Positioned(
top: 0,
bottom: 0,
left: 0,
right: 0,
child: ValueListenableBuilder<int>(
valueListenable:
messageModal.progress ?? ValueNotifier(0),
builder: (context, value, child) {
return Container(
width: MediaQuery.of(context).size.width / 1.3,
padding: const EdgeInsets.symmetric(
horizontal: 10, vertical: 10),
margin: const EdgeInsets.symmetric(vertical: 5),
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.4),
borderRadius: BorderRadius.only(
topRight: const Radius.circular(20),
topLeft: const Radius.circular(20),
bottomRight:
isOtherUser
? const Radius.circular(20)
: const Radius.circular(0),
bottomLeft:
isOtherUser
? const Radius.circular(0)
: const Radius.circular(20),
)),
child: const Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CustomLoader(color: TempColors.whiteColor),
Padding(
padding: EdgeInsets.only(top: 10),
child: CustomText.bodyText1(text)("Uploading",
color: TempColors.whiteColor,
fontSize: 14,
fontWeight: FontWeight.w600),
),
],
),
)
);
}),
),
],
);
}*/
if (messageModal.fromServer) {
try {
HS.insertBodyBytes(messageModal.message, messageModal.id!);
} catch (e) {
print('Error in catch block $e');
}
}
return Consumer<ChatController>(builder: (context, p, child) {
print("datadtadtadta:::::::${p.isLoad}");
return ValueListenableBuilder(
valueListenable: p.isPlayed,
builder: (context, isPlayedValue, child) {
return ValueListenableBuilder(
valueListenable: p.messageID,
builder: (context, messageIdValue, child) {
return ValueListenableBuilder(
valueListenable: p.maxDuration,
builder: (context, maxDurationValue, child) {
return ValueListenableBuilder(
valueListenable: p.currentPos,
builder: (context, currentPosValue, child) {
return ValueListenableBuilder(
valueListenable: p.currentPositionLabel,
builder: (context, currentPosLabelValue,
child) {
return ValueListenableBuilder(
valueListenable: p.isPlaying,
builder: (context, isPlayingValue,
child) {
return Stack(
children: [
Container(
width:
MediaQuery.of(context)
.size
.width /
1.3,
margin: const EdgeInsets.symmetric(vertical: 5),
decoration: BoxDecoration(
color: isOtherUser
? TempColors
.greyColor
.withOpacity(
0.15)
: TempColors
.primaryColor
.withOpacity(
0.3),
borderRadius: BorderRadius.only(
topRight:
const Radius
.circular(
20),
topLeft:
const Radius
.circular(
20),
bottomRight: isOtherUser
? const Radius
.circular(
20)
: const Radius
.circular(
0),
bottomLeft: isOtherUser
? const Radius
.circular(0)
: const Radius
.circular(
20),
)),
child: Stack(
alignment: Alignment.bottomRight,
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
child: Row(
children: [
Stack(
alignment: Alignment.bottomRight,
children: [
CustomImage(
imageUrl: (isOtherUser
? userModal
.profileImage
: chatController.currentUserModal
.profileImage) ??
"",
// staticBlurImage:
// MyImagesUrl
// .dummyUserIcon,
height: 50,
width: 50,
),
],
),
hSizedBox,
Expanded(
child: Column(
crossAxisAlignment:
CrossAxisAlignment
.start,
children: [
if (messageIdValue ==
messageModal
.id)
SizedBox(
height: 20,
child:
SliderTheme(
data:
const SliderThemeData(
trackHeight:
4,
// Adjust track height as needed
thumbShape:
RoundSliderThumbShape(enabledThumbRadius: 7),
// Adjust thumb shape and size as needed
overlayShape:
RoundSliderOverlayShape(overlayRadius: 0),
// Adjust overlay shape and size as needed
trackShape:
RectangularSliderTrackShape(), // Use RectangularSliderTrackShape to remove padding
),
child:
Slider(
value: double
.parse(
currentPosValue
.toString(),
),
min: 0,
activeColor:
CustomStylesConfig.primaryColor,
inactiveColor: TempColors
.primaryColor
.withOpacity(0.5),
max: double.parse(
maxDurationValue.toString()),
onChanged:
(value) async {
int seekVal =
value.round();
await p
.playerController
?.seek(Duration(milliseconds: seekVal));
p.currentPos.value =
seekVal;
//load.value = false;
},
// onChanged: (double value) => onChangedSlider(value),
),
),
)
else
SizedBox(
height: 20,
child:
SliderTheme(
data:
const SliderThemeData(
trackHeight:
4,
// Adjust track height as needed
thumbShape:
RoundSliderThumbShape(enabledThumbRadius: 7),
// Adjust thumb shape and size as needed
overlayShape:
RoundSliderOverlayShape(overlayRadius: 0),
// Adjust overlay shape and size as needed
trackShape:
RectangularSliderTrackShape(), // Use RectangularSliderTrackShape to remove padding
),
child:
Slider(
value:
0.0,
min: 0,
activeColor:
CustomStylesConfig.primaryColor,
inactiveColor: TempColors
.primaryColor
.withOpacity(0.5),
max:
100,
onChanged:
(value) async {},
// onChanged: (double value) => onChangedSlider(value),
),
),
),
vSizedBox05,
CustomText.heading(
messageIdValue ==
messageModal
.id &&
(!isPlayedValue)
? currentPosLabelValue
: messageModal.durationInSeconds !=
null
? formatDuration(
messageModal.durationInSeconds!)
: "",
fontWeight:
FontWeight
.w400,
color: TempColors
.blackColor,
fontSize: 13,
),
],
),
),
CustomGestureDetector(
onTap: () async {
if (p.messageID
.value ==
messageModal
.id) {
if (p.isComplete
.value) {
//Cached Audio Player await p.playerController?.release();
//Cached Audio Player await p.playerController?.playerNetworkAudio(url: messageModal.message, position: const Duration(seconds: 0));
var bytes = HS
.getFile(
messageModal
.id!);
if (bytes !=
null) {
p.showAudioLoader();
print(
'playing from here source 1');
p.urlSource =
BytesSource(
bytes);
await p.playerController?.play(
p
.urlSource!,
position: const Duration(
seconds:
0),
mode: PlayerMode
.mediaPlayer);
p.hideLoader();
} else {
p.showAudioLoader();
p.urlSource =
UrlSource(
messageModal.message);
await p
.playerController
?.play(
p.urlSource!,
position: const Duration(seconds: 0));
p.hideLoader();
}
p.isPlaying
.value =
true;
p.isComplete
.value =
false;
} else {
if (p
.isPlaying
.value) {
await p
.playerController
?.pause();
p.isPlaying
.value =
false;
} else {
await p
.playerController
?.resume();
p.isPlaying
.value =
true;
}
}
} else {
await p
.unsetAll();
p.init(
audioPlayer:
messageModal
.audioPlayer);
p.messageID
.value =
messageModal
.id ??
"";
//Cached Audio Player await p.playerController?.playerNetworkAudio(url: messageModal.message,);
var bytes =
HS.getFile(
messageModal
.id!);
if (bytes !=
null) {
print(
'playing from here source 1');
p.showAudioLoader();
p.urlSource =
BytesSource(
bytes);
await p.playerController?.play(
p
.urlSource!,
position: const Duration(
seconds:
0),
mode: PlayerMode
.mediaPlayer);
p.hideLoader();
} else {
p.showAudioLoader();
p.urlSource =
UrlSource(
messageModal
.message);
await p.playerController?.play(
p
.urlSource!,
position: const Duration(
seconds:
0));
p.hideLoader();
}
p.isPlaying
.value =
true;
}
//showRecordingPopup(
// message: messageModal,
// onWillPop: () async {
// return false;
// },
// imagePath: isOtherUser
// ? userModal.profileImage
// : userData?.profileImage,
// heading: "Audio Message");
},
child: Container(
height: 35,
width: 35,
padding:
const EdgeInsets
.all(3),
decoration: BoxDecoration(
borderRadius:
BorderRadius
.circular(
17)),
child: messageIdValue ==
messageModal
.id
? p.isLoad
? const CustomLoader()
: isPlayingValue
? const Icon(Icons
.pause)
: const Icon(Icons
.play_arrow)
: const Icon(Icons
.play_arrow),
),
),
],
),
),
Padding(
padding: const EdgeInsets.only(bottom: 7,right: 10),
child: CustomText.heading(
CustomTimeFunctions.formatTimeForChat(TimeOfDay.fromDateTime(messageModal.createdAt.toDate())),
fontWeight: FontWeight.w400,
color: TempColors.blackColor,
fontSize: 10,
),
),
],
),
),
if (messageModal.fromServer == false)
Positioned(
top: 0,
bottom: 0,
left: 0,
right: 0,
child: ValueListenableBuilder<
int>(
valueListenable:
messageModal
.progress ??
ValueNotifier(
0),
builder: (context,
value, child) {
return Container(
width: MediaQuery.of(context)
.size
.width /
1.3,
padding: const EdgeInsets
.symmetric(
horizontal:
10,
vertical:
10),
margin: const EdgeInsets
.symmetric(
vertical:
5),
decoration:
BoxDecoration(
color: Colors.black.withOpacity(
0.4),
borderRadius: BorderRadius
.only(
topRight:
const Radius.circular(20),
topLeft:
const Radius.circular(20),
bottomRight: isOtherUser
? const Radius.circular(20)
: const Radius.circular(0),
bottomLeft: isOtherUser
? const Radius.circular(0)
: const Radius.circular(20),
)),
child:
Center(
child:
Column(
mainAxisAlignment:
MainAxisAlignment
.center,
children: [
CustomLoader(
color:
TempColors.whiteColor),
Padding(
padding:
EdgeInsets.only(top: 10),
child: CustomText.bodyText1(
"Uploading",
color: TempColors.whiteColor,
fontSize: 14,
fontWeight: FontWeight.w600),
),
],
),
) /*Center(
child: CircularProgressIndicator(
value: value / 100,
color: CustomStylesConfig.primaryColor,
),
),*/
);
}),
),
if (messageModal.fromServer == false)
InkWell(
onTap: () {
// ChatDetailProvider
// ch = Provider.of<
// ChatDetailProvider>(
// context,
// listen:
// false);
Map<int,
ChatModal> innerMap = chatController
.tempChats[
chatController.chatId] ??
{};
innerMap.remove(
int.parse(
messageModal
.id!));
chatController.reload();
},
child: SizedBox(
width: MediaQuery.of(
context)
.size
.width /
1.3,
child: Padding(
padding:
const EdgeInsets
.only(
right: 10,
top: 10),
child: Align(
alignment:
Alignment
.topRight,
child: Container(
height: 30,
width: 30,
padding:
const EdgeInsets
.all(2),
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(
20),
border: Border.all(
color: TempColors
.whiteColor,
width:
1)),
child: const Icon(
Icons.close,
size: 16,
color: TempColors
.whiteColor),
),
),
),
),
),
],
);
});
});
});
});
});
});
});
}
default: /// MessageType.text
{
return Consumer<ChatController>(
builder: (context, chatDetailProvider, child) {
return Container(
padding: const EdgeInsets.symmetric(vertical: 5),
margin: EdgeInsets.symmetric(horizontal: 8),
child: CustomGestureDetector(
borderRadius: BorderRadius.only(
topRight: const Radius.circular(20),
topLeft: const Radius.circular(20),
bottomRight: isOtherUser
? const Radius.circular(20)
: const Radius.circular(0),
bottomLeft: isOtherUser
? const Radius.circular(0)
: const Radius.circular(20),
),
splashColor: Colors.transparent,
onLongPress: () async {
FocusScope.of(context).requestFocus(FocusNode());
showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
vSizedBox,
CustomText.headingLarge('Options'),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20,vertical: 8),
child: Divider(),
),
ListTile(
leading: const Icon(Icons.copy),
title: const Text('Copy'),
onTap: () async {
Navigator.pop(context); // Close the popup
if (chatDetailProvider.selectedCopyText == null) {
chatDetailProvider.selectedCopyText = messageModal.id;
chatDetailProvider.reload();
copyToClipboard(text: messageModal.message);
await Future.delayed(const Duration(seconds: 1));
chatDetailProvider.selectedCopyText = null;
chatDetailProvider.reload();
}
},
),
// if(messageModal.from==chatController.currentUserId)
// Padding(
// padding: const EdgeInsets.symmetric(horizontal: 20),
// child: Divider(),
// ),
// if(messageModal.from==chatController.currentUserId)
// ListTile(
// leading: const Icon(Icons.delete),
// title: const Text('Delete'),
// onTap: () {
// Navigator.pop(context); // Close the popup
// onDelete();
// },
// ),
],
);
},
);
// if (chatDetailProvider.selectedCopyText == null) {
// chatDetailProvider.selectedCopyText = messageModal.id;
// chatDetailProvider.reload();
// copyToClipboard(text: messageModal.message);
// await Future.delayed(const Duration(seconds: 1));
// chatDetailProvider.selectedCopyText = null;
// chatDetailProvider.reload();
// }
},
child: Stack(
alignment: Alignment.bottomRight,
children: [
Container(
// width: MediaQuery.of(context).size.width / 1.3,
constraints: BoxConstraints(
maxWidth: MediaQuery.of(context).size.width / 1.3,
minWidth: 120
),
decoration: BoxDecoration(
color: isOtherUser
?
// widget.isGroupChat?TempColors.lightPinkColor:
CustomStylesConfig.primaryColor.withOpacity(0.1)
// TempColors.chatOtherUserBg
: CustomStylesConfig.primaryColor.withOpacity(0.9),
borderRadius: BorderRadius.only(
topRight: const Radius.circular(20),
topLeft: const Radius.circular(20),
bottomRight: isOtherUser
? const Radius.circular(20)
: const Radius.circular(0),
bottomLeft: isOtherUser
? const Radius.circular(0)
: const Radius.circular(20),
)),
child: Padding(
padding: const EdgeInsets.only(left: 10,right: 20, top: 10,bottom: 20),
child: CustomText.heading(
messageModal.message
// '${messageModal.fromServer?'':' temp from local'}'
,
// chatList[index]
// .data![i]
// .chat
// .toString(),
fontWeight: FontWeight.w400,
color: messageModal.from != chatController.currentUserId
? TempColors.blackColor
: TempColors.whiteColor,
fontSize: 16,
),
),
),
Padding(
padding: const EdgeInsets.only(bottom: 8,right: 12),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
CustomText.heading(
CustomTimeFunctions.formatTimeForChat(TimeOfDay.fromDateTime(messageModal.createdAt.toDate())),
fontWeight: FontWeight.w400,
color:messageModal.from != chatController.currentUserId?TempColors.blackColor.withOpacity(0.7): TempColors.whiteColor.withOpacity(0.7),
fontSize: 10,
),
hSizedBox02,
TickIcon( isOtherUser: isOtherUser),
],
),
)
],
),
),
);
// return AnimatedCrossFade(
// firstChild: Padding(
// padding: const EdgeInsets.symmetric(vertical: 5),
// child: CustomGestureDetector(
// borderRadius: BorderRadius.only(
// topRight: const Radius.circular(20),
// topLeft: const Radius.circular(20),
// bottomRight: isOtherUser
// ? const Radius.circular(20)
// : const Radius.circular(0),
// bottomLeft: isOtherUser
// ? const Radius.circular(0)
// : const Radius.circular(20),
// ),
// splashColor: Colors.transparent,
// onLongPress: () async {
// if (chatDetailProvider.selectedCopyText == null) {
// chatDetailProvider.selectedCopyText = messageModal.id;
// chatDetailProvider.reload();
// copyToClipboard(text: messageModal.message);
// await Future.delayed(const Duration(seconds: 1));
// chatDetailProvider.selectedCopyText = null;
// chatDetailProvider.reload();
// }
// },
// child: Stack(
// alignment: Alignment.bottomRight,
// children: [
// Container(
// // width: MediaQuery.of(context).size.width / 1.3,
// decoration: BoxDecoration(
// color: isOtherUser
// ?
// // widget.isGroupChat?TempColors.lightPinkColor:
// TempColors.whiteColor
// // TempColors.chatOtherUserBg
// : CustomStylesConfig.primaryColor.withOpacity(0.9),
// borderRadius: BorderRadius.only(
// topRight: const Radius.circular(20),
// topLeft: const Radius.circular(20),
// bottomRight: isOtherUser
// ? const Radius.circular(20)
// : const Radius.circular(0),
// bottomLeft: isOtherUser
// ? const Radius.circular(0)
// : const Radius.circular(20),
// )),
// child: Padding(
// padding: const EdgeInsets.only(left: 10,right: 20, top: 10,bottom: 20),
// child: CustomText.heading(
// messageModal.message
// // '${messageModal.fromServer?'':' temp from local'}'
// ,
// // chatList[index]
// // .data![i]
// // .chat
// // .toString(),
// fontWeight: FontWeight.w400,
// color: isOtherUser
// ? TempColors.blackColor
// : TempColors.whiteColor,
// fontSize: 16,
// ),
// ),
// ),
// Padding(
// padding: const EdgeInsets.only(bottom: 8,right: 12),
// child: CustomText.heading(
// CustomTimeFunctions.formatTimeForChat(TimeOfDay.fromDateTime(messageModal.createdAt.toDate())),
// fontWeight: FontWeight.w400,
// color: TempColors.whiteColor.withOpacity(0.7),
// fontSize: 10,
// ),
// )
// ],
// ),
// ),
// ),
// secondChild: Row(
// mainAxisAlignment: isOtherUser
// ? MainAxisAlignment.start
// : MainAxisAlignment.end,
// children: [
// Stack(
// alignment: Alignment.bottomRight,
// children: [
// Padding(
// padding: const EdgeInsets.symmetric(vertical: 5),
// child: Container(
// width: MediaQuery.of(context).size.width / 1.3,
// padding: const EdgeInsets.only(left: 10,right: 20, top: 10,bottom: 20),
// decoration: BoxDecoration(
// color: CustomStylesConfig.primaryColor,
// borderRadius: BorderRadius.only(
// topRight: const Radius.circular(20),
// topLeft: const Radius.circular(20),
// bottomRight: isOtherUser
// ? const Radius.circular(20)
// : const Radius.circular(0),
// bottomLeft: isOtherUser
// ? const Radius.circular(0)
// : const Radius.circular(20),
// )),
// child: CustomText.heading(
// messageModal.message,
// fontWeight: FontWeight.w400,
// color: isOtherUser
// ? TempColors.whiteColor
// : TempColors.whiteColor,
// fontSize: 16,
// ),
// ),
// ),
// Padding(
// padding: const EdgeInsets.only(bottom: 8,right: 12),
// child: CustomText.heading(
// CustomTimeFunctions.formatTimeForChat(TimeOfDay.fromDateTime(messageModal.createdAt.toDate())),
// fontWeight: FontWeight.w400,
// color: TempColors.whiteColor.withOpacity(0.7),
// fontSize: 10,
// ),
// )
// ],
// ),
// ],
// ),
// crossFadeState:
// chatDetailProvider.selectedCopyText == messageModal.id
// ? CrossFadeState.showSecond
// : CrossFadeState.showFirst,
// duration: const Duration(milliseconds: 700),
// );
});
}
}
}