Chat Error Handling

merge-requests/116/head
Aamir Muhammad 3 years ago
parent e40cd2c5c8
commit 4021eccd9f

@ -16,7 +16,7 @@ import 'package:image_picker_for_web/image_picker_for_web.dart';
import 'package:shared_preferences_web/shared_preferences_web.dart'; import 'package:shared_preferences_web/shared_preferences_web.dart';
import 'package:url_launcher_web/url_launcher_web.dart'; import 'package:url_launcher_web/url_launcher_web.dart';
import 'package:video_player_web/video_player_web.dart'; import 'package:video_player_web/video_player_web.dart';
import 'package:wakelock_web/wakelock_web.dart'; //import 'package:wakelock_web/wakelock_web.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart'; import 'package:flutter_web_plugins/flutter_web_plugins.dart';
@ -32,6 +32,6 @@ void registerPlugins(Registrar registrar) {
SharedPreferencesPlugin.registerWith(registrar); SharedPreferencesPlugin.registerWith(registrar);
UrlLauncherPlugin.registerWith(registrar); UrlLauncherPlugin.registerWith(registrar);
VideoPlayerPlugin.registerWith(registrar); VideoPlayerPlugin.registerWith(registrar);
WakelockWeb.registerWith(registrar); // WakelockWeb.registerWith(registrar);
registrar.registerMessageHandler(); registrar.registerMessageHandler();
} }

@ -970,15 +970,15 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
//////// Audio Recoding Work //////////////////// //////// Audio Recoding Work ////////////////////
Future<void> initAudio() async { Future<void> initAudio({required int receiverId}) async {
appDirectory = await getApplicationDocumentsDirectory(); appDirectory = await getApplicationDocumentsDirectory();
path = "${appDirectory.path}/${AppState().chatDetails!.response!.id}-${DateTime.now().microsecondsSinceEpoch}.aac"; path = "${appDirectory.path}/${AppState().chatDetails!.response!.id}-$receiverID-${DateTime.now().microsecondsSinceEpoch}.aac";
recorderController = RecorderController() recorderController = RecorderController()
..androidEncoder = AndroidEncoder.aac ..androidEncoder = AndroidEncoder.aac
..androidOutputFormat = AndroidOutputFormat.mpeg4 ..androidOutputFormat = AndroidOutputFormat.mpeg4
..iosEncoder = IosEncoder.kAudioFormatMPEG4AAC ..iosEncoder = IosEncoder.kAudioFormatMPEG4AAC
..sampleRate = 8000 ..sampleRate = 6000
..bitRate = 32000; ..bitRate = 18000;
playerController = PlayerController(); playerController = PlayerController();
} }
@ -992,7 +992,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
void startRecoding() async { void startRecoding() async {
PermissionStatus status = await Permission.microphone.request(); PermissionStatus status = await Permission.microphone.request();
print(status);
if (status.isDenied == true) { if (status.isDenied == true) {
startRecoding(); startRecoding();
} else { } else {
@ -1014,6 +1013,15 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
}); });
} }
void _pauseTimer() {
_timer?.cancel();
_timer = Timer.periodic(const Duration(seconds: 1), (Timer t) {
_recodeDuration++;
// buildTimer();
notifyListeners();
});
}
Future<void> pauseRecoding() async { Future<void> pauseRecoding() async {
isPause = true; isPause = true;
isPlaying = true; isPlaying = true;
@ -1025,6 +1033,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
await playerController.preparePlayer(file.path, 1.0); await playerController.preparePlayer(file.path, 1.0);
var tempDuration = _recodeDuration; var tempDuration = _recodeDuration;
_recodeDuration = tempDuration; _recodeDuration = tempDuration;
_pauseTimer();
_timer?.cancel(); _timer?.cancel();
notifyListeners(); notifyListeners();
} }
@ -1077,11 +1086,41 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
void playRecoding() async { void playRecoding() async {
isPlaying = true; isPlaying = true;
await playerController.startPlayer(finishMode: FinishMode.stop); await playerController.startPlayer(finishMode: FinishMode.pause);
} }
void playOrPause() async { void playOrPause() async {
playerController.playerState == PlayerState.playing ? await playerController.pausePlayer() : playRecoding(); playerController.playerState == PlayerState.playing ? await playerController.pausePlayer() : playRecoding();
notifyListeners(); notifyListeners();
} }
void sendVoiceMessage(BuildContext context, {required int targetUserId, required int userStatus, required String userEmail, required String targetUserName}) async {
recorderController.pause();
path = await recorderController.stop(false);
print(path);
File voiceFile = File(path!);
voiceFile.readAsBytesSync();
_pauseTimer();
_timer?.cancel();
isPause = false;
isPlaying = false;
isRecoding = false;
Utils.showLoading(context);
dynamic value = await uploadAttachments(AppState().chatDetails!.response!.id.toString(), voiceFile);
logger.d(value);
String? ext = getFileExtension(voiceFile.path);
Utils.hideLoading(context);
sendChatToServer(
chatEventId: 2,
fileTypeId: getFileType(ext.toString()),
targetUserId: targetUserId,
targetUserName: targetUserName,
isAttachment: true,
chatReplyId: null,
isReply: false,
isImageLoaded: true,
image: voiceFile.readAsBytesSync());
notifyListeners();
}
} }

@ -328,15 +328,17 @@ class WaveBubble extends StatelessWidget {
playerController: playerController, playerController: playerController,
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
margin: EdgeInsets.zero, margin: EdgeInsets.zero,
enableSeekGesture: true,
density: 2,
playerWaveStyle: const PlayerWaveStyle( playerWaveStyle: const PlayerWaveStyle(
fixedWaveColor: Colors.white, fixedWaveColor: Colors.white,
liveWaveColor:MyColors.lightGreenColor, liveWaveColor:MyColors.greenColor,
showTop: true, showTop: true,
showBottom: true, showBottom: true,
waveCap: StrokeCap.round, waveCap: StrokeCap.round,
seekLineThickness: 3, seekLineThickness: 2,
visualizerHeight: 6, visualizerHeight: 5,
backgroundColor: Colors.transparent backgroundColor: Colors.transparent,
), ),
), ),
], ],

@ -80,7 +80,7 @@ class _ChatDetailScreenState extends State<ChatDetailScreen> {
loadMore: false, loadMore: false,
isNewChat: params!.isNewChat!, isNewChat: params!.isNewChat!,
); );
data.initAudio(); data.initAudio(receiverId: params!.chatUser!.id!);
} }
return Scaffold( return Scaffold(
@ -252,7 +252,7 @@ class _ChatDetailScreenState extends State<ChatDetailScreen> {
}), }),
SvgPicture.asset("assets/icons/chat/chat_send_icon.svg", height: 26, width: 26) SvgPicture.asset("assets/icons/chat/chat_send_icon.svg", height: 26, width: 26)
.onPress( .onPress(
() => m.sendChatMessage(context, () => m.sendVoiceMessage(context,
targetUserId: params!.chatUser!.id!, targetUserId: params!.chatUser!.id!,
userStatus: params!.chatUser!.userStatus ?? 0, userStatus: params!.chatUser!.userStatus ?? 0,
userEmail: params!.chatUser!.email!, userEmail: params!.chatUser!.email!,

Loading…
Cancel
Save