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:url_launcher_web/url_launcher_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';
@ -32,6 +32,6 @@ void registerPlugins(Registrar registrar) {
SharedPreferencesPlugin.registerWith(registrar);
UrlLauncherPlugin.registerWith(registrar);
VideoPlayerPlugin.registerWith(registrar);
WakelockWeb.registerWith(registrar);
// WakelockWeb.registerWith(registrar);
registrar.registerMessageHandler();
}

@ -970,15 +970,15 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
//////// Audio Recoding Work ////////////////////
Future<void> initAudio() async {
Future<void> initAudio({required int receiverId}) async {
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()
..androidEncoder = AndroidEncoder.aac
..androidOutputFormat = AndroidOutputFormat.mpeg4
..iosEncoder = IosEncoder.kAudioFormatMPEG4AAC
..sampleRate = 8000
..bitRate = 32000;
..sampleRate = 6000
..bitRate = 18000;
playerController = PlayerController();
}
@ -992,7 +992,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
void startRecoding() async {
PermissionStatus status = await Permission.microphone.request();
print(status);
if (status.isDenied == true) {
startRecoding();
} 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 {
isPause = true;
isPlaying = true;
@ -1025,6 +1033,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
await playerController.preparePlayer(file.path, 1.0);
var tempDuration = _recodeDuration;
_recodeDuration = tempDuration;
_pauseTimer();
_timer?.cancel();
notifyListeners();
}
@ -1077,11 +1086,41 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
void playRecoding() async {
isPlaying = true;
await playerController.startPlayer(finishMode: FinishMode.stop);
await playerController.startPlayer(finishMode: FinishMode.pause);
}
void playOrPause() async {
playerController.playerState == PlayerState.playing ? await playerController.pausePlayer() : playRecoding();
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,
padding: EdgeInsets.zero,
margin: EdgeInsets.zero,
enableSeekGesture: true,
density: 2,
playerWaveStyle: const PlayerWaveStyle(
fixedWaveColor: Colors.white,
liveWaveColor:MyColors.lightGreenColor,
liveWaveColor:MyColors.greenColor,
showTop: true,
showBottom: true,
waveCap: StrokeCap.round,
seekLineThickness: 3,
visualizerHeight: 6,
backgroundColor: Colors.transparent
seekLineThickness: 2,
visualizerHeight: 5,
backgroundColor: Colors.transparent,
),
),
],

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

Loading…
Cancel
Save