merge-requests/131/head
Sikander Saleem 3 years ago
parent 05ff1fcf3f
commit 088fd6f318

@ -1295,15 +1295,23 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
return numberStr; return numberStr;
} }
Future<String> downChatVoice(Uint8List bytes, String ext, SingleUserChatModel data) async { Future<File> downChatVoice(Uint8List bytes, String ext, SingleUserChatModel data) async {
String dirPath = '${(await getApplicationDocumentsDirectory()).path}/chat_audios'; File file;
if (!await Directory(dirPath).exists()) { try {
await Directory(dirPath).create(); String dirPath = '${(await getApplicationDocumentsDirectory()).path}/chat_audios';
await File('$dirPath/.nomedia').create(); if (!await Directory(dirPath).exists()) {
await Directory(dirPath).create();
await File('$dirPath/.nomedia').create();
}
file = File("$dirPath/${data.currentUserId}-${data.targetUserId}-${DateTime.now().microsecondsSinceEpoch}" + ext);
await file.writeAsBytes(bytes);
} catch (e) {
if (kDebugMode) {
print(e);
}
file = File("");
} }
File file = File("$dirPath/${data.currentUserId}-${data.targetUserId}-${DateTime.now().microsecondsSinceEpoch}." + ext); return file;
await file.writeAsBytes(bytes);
return file.path;
} }
void scrollToMsg(SingleUserChatModel data) { void scrollToMsg(SingleUserChatModel data) {

@ -56,47 +56,64 @@ class ChatBubble extends StatelessWidget {
userName = AppState().chatDetails!.response!.userName == cItem.currentUserName.toString() ? "You" : cItem.currentUserName.toString(); userName = AppState().chatDetails!.response!.userName == cItem.currentUserName.toString() ? "You" : cItem.currentUserName.toString();
} }
Future<String> getCurrentUrl(String url)async{
if(Platform.isIOS){
String a = url.substring(url.indexOf("Documents/") + 10, url.length) ;
Directory dir = await getApplicationDocumentsDirectory();
a = "${dir.path}/$a";
return a;
}
else{
return url;
}
}
void playVoice( void playVoice(
BuildContext context, { BuildContext context, {
required SingleUserChatModel data, required SingleUserChatModel data,
}) async { }) async {
if (data.voice != null && data.voice!.existsSync()) { if (data.voice != null && data.voice!.existsSync()) {
await data.voiceController!.setLoopMode(LoopMode.off);
if (Platform.isIOS) { if (Platform.isIOS) {
Duration? duration = await data.voiceController!.setAudioSource(MyCustomStream(data.voice!.readAsBytesSync())); Duration? duration = await data.voiceController!.setAudioSource(MyCustomStream(data.voice!.readAsBytesSync()));
await data.voiceController!.seek(duration); await data.voiceController!.seek(duration);
await data.voiceController!.setLoopMode(LoopMode.off);
await data.voiceController!.setVolume(1.0);
await data.voiceController!.load();
data.voiceController!.play(); data.voiceController!.play();
} else { } else {
await data.voiceController!.setFilePath(data!.voice!.path); await data.voiceController!.setFilePath(data!.voice!.path);
Duration? duration = await data.voiceController!.load(); Duration? duration = await data.voiceController!.load();
await data.voiceController!.seek(duration); await data.voiceController!.seek(duration);
await data.voiceController!.setLoopMode(LoopMode.off);
await data.voiceController!.play(); await data.voiceController!.play();
} }
} else { } else {
Utils.showLoading(context); Utils.showLoading(context);
Uint8List encodedString = await ChatApiClient().downloadURL(fileName: data.contant!, fileTypeDescription: provider.getFileTypeDescription(data.fileTypeResponse!.fileTypeName ?? "")); Uint8List encodedString = await ChatApiClient().downloadURL(fileName: data.contant!, fileTypeDescription: provider.getFileTypeDescription(data.fileTypeResponse!.fileTypeName ?? ""));
try { // try {
String path = await provider.downChatVoice(encodedString, data.fileTypeResponse!.fileTypeName ?? "", data); File sFile = await provider.downChatVoice(encodedString, data.fileTypeResponse!.fileTypeName ?? "", data);
File file = File(path!); data.voice = sFile;
await file.readAsBytes();
data.voice = file;
if (Platform.isIOS) { if (Platform.isIOS) {
Duration? duration = await data.voiceController!.setAudioSource(MyCustomStream(encodedString)); Duration? duration = await data.voiceController!.setAudioSource(MyCustomStream(data.voice!.readAsBytesSync()));
await data.voiceController!.seek(duration); await data.voiceController!.seek(duration);
await data.voiceController!.setLoopMode(LoopMode.off);
await data.voiceController!.setVolume(1.0);
await data.voiceController!.load();
Utils.hideLoading(context);
data.voiceController!.play(); data.voiceController!.play();
} else { } else {
Duration? duration = await data.voiceController!.setFilePath(file.path); Duration? duration = await data.voiceController!.setFilePath(sFile.path);
await data.voiceController!.setLoopMode(LoopMode.off); await data.voiceController!.setLoopMode(LoopMode.off);
await data.voiceController!.seek(duration); await data.voiceController!.seek(duration);
await data.voiceController!.setVolume(1.0);
await data.voiceController!.load();
Utils.hideLoading(context); Utils.hideLoading(context);
await data.voiceController!.play(); await data.voiceController!.play();
} }
} catch (e) {
Utils.hideLoading(context); // } catch (e) {
Utils.showToast(e.toString()); // Utils.hideLoading(context);
} // Utils.showToast(e.toString());
// }
} }
} }
@ -126,7 +143,7 @@ class ChatBubble extends StatelessWidget {
Widget currentUser(BuildContext context) { Widget currentUser(BuildContext context) {
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: [
if (isReplied) if (isReplied)
ClipRRect( ClipRRect(
borderRadius: BorderRadius.circular(5.0), borderRadius: BorderRadius.circular(5.0),
@ -212,7 +229,7 @@ class ChatBubble extends StatelessWidget {
), ),
), ),
], ],
).paddingOnly(top: 11, left: 13, right: 13, bottom: 5).objectContainerView(disablePadding: true, radius: 10).paddingOnly(left: MediaQuery.of(context).size.width * 0.3); ).paddingOnly(top: 11, left: 13, right: 13, bottom: 5).objectContainerView(disablePadding: true).paddingOnly(left: MediaQuery.of(context).size.width * 0.3);
} }
Widget receiptUser(BuildContext context) { Widget receiptUser(BuildContext context) {
@ -352,7 +369,6 @@ class ChatBubble extends StatelessWidget {
Widget currentWaveBubble(BuildContext context, SingleUserChatModel data) { Widget currentWaveBubble(BuildContext context, SingleUserChatModel data) {
return Container( return Container(
margin: const EdgeInsets.all(0), margin: const EdgeInsets.all(0),
constraints: const BoxConstraints(),
decoration: BoxDecoration( decoration: BoxDecoration(
border: Border( border: Border(
left: BorderSide(width: 6, color: isCurrentUser ? MyColors.gradiantStartColor : MyColors.white), left: BorderSide(width: 6, color: isCurrentUser ? MyColors.gradiantStartColor : MyColors.white),
@ -424,7 +440,7 @@ class ChatBubble extends StatelessWidget {
child: const CircularProgressIndicator(), child: const CircularProgressIndicator(),
); );
} else if (playing != true) { } else if (playing != true) {
return const Icon( return Icon(
Icons.play_arrow, Icons.play_arrow,
size: 30, size: 30,
color: MyColors.lightGreenColor, color: MyColors.lightGreenColor,
@ -432,7 +448,7 @@ class ChatBubble extends StatelessWidget {
playVoice(context, data: modelData); playVoice(context, data: modelData);
}); });
} else if (processingState != ProcessingState.completed) { } else if (processingState != ProcessingState.completed) {
return const Icon( return Icon(
Icons.pause, Icons.pause,
size: 30, size: 30,
color: MyColors.lightGreenColor, color: MyColors.lightGreenColor,
@ -440,7 +456,7 @@ class ChatBubble extends StatelessWidget {
pausePlaying(context, data: modelData); pausePlaying(context, data: modelData);
}); });
} else { } else {
return const Icon( return Icon(
Icons.replay, Icons.replay,
size: 30, size: 30,
color: MyColors.lightGreenColor, color: MyColors.lightGreenColor,

Loading…
Cancel
Save