From 9dcbdee156710173ba7f231e1af5e385535a1a59 Mon Sep 17 00:00:00 2001 From: Aamir-iMac Date: Wed, 24 May 2023 16:09:58 +0300 Subject: [PATCH] Changes On iOS --- lib/classes/chat_call_kit.dart | 5 +- lib/config/routes.dart | 2 +- lib/provider/chat_call_provider.dart | 148 ++-- .../chat/call/chat_incoming_call_screen.dart | 724 +++++++++++++----- .../chat/call/chat_outgoing_call_screen.dart | 313 +++----- lib/ui/chat/call/start_call_screen.dart | 593 -------------- 6 files changed, 739 insertions(+), 1046 deletions(-) delete mode 100644 lib/ui/chat/call/start_call_screen.dart diff --git a/lib/classes/chat_call_kit.dart b/lib/classes/chat_call_kit.dart index 68c1d18..2059eec 100644 --- a/lib/classes/chat_call_kit.dart +++ b/lib/classes/chat_call_kit.dart @@ -149,10 +149,11 @@ class ChatVoipCall { } break; case Event.ACTION_CALL_DECLINE: - cProv.isIncomingCall = true; + // cProv.isIncomingCall = true; Utils.saveStringFromPrefs("isIncomingCall", "false"); Utils.saveStringFromPrefs("inComingCallData", "null"); - cProv.endCall(); + + // cProv.endCall(isUserOnline: true); FlutterCallkitIncoming.endAllCalls(); break; case Event.ACTION_CALL_ENDED: diff --git a/lib/config/routes.dart b/lib/config/routes.dart index d057be3..2667494 100644 --- a/lib/config/routes.dart +++ b/lib/config/routes.dart @@ -4,7 +4,7 @@ import 'package:mohem_flutter_app/ui/attendance/add_vacation_rule_screen.dart'; import 'package:mohem_flutter_app/ui/attendance/monthly_attendance_screen.dart'; import 'package:mohem_flutter_app/ui/attendance/vacation_rule_screen.dart'; import 'package:mohem_flutter_app/ui/bottom_sheets/attendence_details_bottom_sheet.dart'; -import 'package:mohem_flutter_app/ui/chat/call/start_call_screen.dart'; +import 'package:mohem_flutter_app/ui/chat/call/chat_incoming_call_screen.dart'; import 'package:mohem_flutter_app/ui/chat/chat_detailed_screen.dart'; import 'package:mohem_flutter_app/ui/chat/chat_home.dart'; import 'package:mohem_flutter_app/ui/chat/favorite_users_screen.dart'; diff --git a/lib/provider/chat_call_provider.dart b/lib/provider/chat_call_provider.dart index 6b98d7b..604604e 100644 --- a/lib/provider/chat_call_provider.dart +++ b/lib/provider/chat_call_provider.dart @@ -13,7 +13,7 @@ import 'package:mohem_flutter_app/models/chat/call.dart'; import 'package:mohem_flutter_app/models/chat/get_single_user_chat_list_model.dart'; import 'package:mohem_flutter_app/models/chat/webrtc_payloads.dart'; import 'package:mohem_flutter_app/provider/chat_provider_model.dart'; -import 'package:mohem_flutter_app/ui/chat/call/start_call_screen.dart'; +import 'package:mohem_flutter_app/ui/chat/call/chat_incoming_call_screen.dart'; import 'package:mohem_flutter_app/ui/landing/dashboard_screen.dart'; import 'package:signalr_netcore/hub_connection.dart'; @@ -25,7 +25,7 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin { RTCVideoRenderer localVideoRenderer = RTCVideoRenderer(); RTCVideoRenderer remoteRenderer = RTCVideoRenderer(); final AudioPlayer player = AudioPlayer(); - late MediaStream localStream; + MediaStream? _localStream; late CallDataModel outGoingCallData; bool isMicOff = false; bool isLoudSpeaker = false; @@ -101,10 +101,7 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin { isCallEnded = false; chatProvModel = chatProvmodel; outGoingCallData = callData; - await localVideoRenderer.initialize(); - localStream = await navigator.mediaDevices.getUserMedia(isVideoCall ? videoConstraints : audioConstraints); - localVideoRenderer.srcObject = localStream; - await remoteRenderer.initialize(); + await initStreams(); await startCall(callType: isVideoCall ? "Video" : "Audio", context: context); _pc = await creatOfferWithCon(); notifyListeners(); @@ -157,7 +154,10 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin { await _pc.addCandidate(RTCIceCandidate(data.candidate!.candidate, data.candidate!.sdpMid, data.candidate!.sdpMLineIndex)); if (!isCallStarted) { isCallStarted = true; + notifyListeners(); if (isCallStarted) { + isIncomingCallLoader = false; + isOutGoingCall = true; Navigator.push( providerContext, MaterialPageRoute( @@ -194,17 +194,12 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin { //////////////////////////// OutGoing Call End /////////////////////////////////////// - Future endCall() async { + Future endCall({required bool isUserOnline}) async { if (isIncomingCall) { logger.i("-----------------------Endeddddd By Me---------------------------"); if (chatHubConnection.state == HubConnectionState.Connected) { - await invoke(invokeMethod: "UpdateUserStatusAsync", currentUserID: AppState().chatDetails!.response!.id!, targetUserID: incomingCallData.targetUserId!, userStatus: 0); await invoke(invokeMethod: "HangUpAsync", currentUserID: AppState().chatDetails!.response!.id!, targetUserID: incomingCallData.targetUserId!, userStatus: 0); - } - if (_pc.connectionState == RTCPeerConnectionState.RTCPeerConnectionStateConnected) { - print("------------------ PC Stopped ----------------------------"); - _pc.close(); - // _pc.dispose(); + await invoke(invokeMethod: "UpdateUserStatusAsync", currentUserID: AppState().chatDetails!.response!.id!, targetUserID: incomingCallData.targetUserId!, userStatus: 1); } isCallStarted = false; isVideoCall = false; @@ -215,72 +210,77 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin { remoteRenderer.srcObject = null; isIncomingCall = false; isOutGoingCall = false; - if (chatHubConnection != null) { + if (_pc.connectionState == RTCPeerConnectionState.RTCPeerConnectionStateConnected) { + print("------------------ PC Stopped ----------------------------"); + _pc.close(); + remoteRenderer.dispose(); + localVideoRenderer.dispose(); + if (_localStream != null) { + _localStream!.dispose(); + _localStream = null; + } + _pc.dispose(); + } + if (chatHubConnection != null && !isUserOnline) { chatHubConnection.stop(); - // await localVideoRenderer.dispose(); - // localStream.dispose(); - // remoteRenderer.dispose(); } await FlutterCallkitIncoming.endAllCalls(); return true; } else { if (isOutGoingCall) { + print("Endded Outgoing"); await invoke(invokeMethod: "HangUpAsync", currentUserID: outGoingCallData.callerId!, targetUserID: outGoingCallData.receiverId!, userStatus: 1); - await invoke(invokeMethod: "UpdateUserStatusAsync", currentUserID: outGoingCallData.callerId!, targetUserID: outGoingCallData.receiverId!, userStatus: 0); + await invoke(invokeMethod: "UpdateUserStatusAsync", currentUserID: outGoingCallData.callerId!, targetUserID: outGoingCallData.receiverId!, userStatus: 1); } else if (isIncomingCall) { await invoke(invokeMethod: "UpdateUserStatusAsync", currentUserID: AppState().chatDetails!.response!.id!, targetUserID: incomingCallData.targetUserId!, userStatus: 1); } - if (_pc.connectionState == RTCPeerConnectionState.RTCPeerConnectionStateConnected) { - _pc.close(); - // _pc.dispose(); - // localStream.dispose(); - // remoteRenderer.dispose(); - } + isCallStarted = false; isVideoCall = false; isCamOff = false; isMicOff = false; isLoudSpeaker = false; localVideoRenderer.srcObject = null; - // await localVideoRenderer.dispose(); remoteRenderer.srcObject = null; + if (_pc.connectionState == RTCPeerConnectionState.RTCPeerConnectionStateConnected) { + _pc.close(); + remoteRenderer.dispose(); + localVideoRenderer.dispose(); + if (_localStream != null) { + _localStream!.dispose(); + _localStream = null; + } + _pc.dispose(); + } isOutGoingCall = false; isIncomingCall = false; + // await initStreams().whenComplete(() => notifyListeners()); return true; } } - Future reInit() async { - await localVideoRenderer.initialize(); - localStream = await navigator.mediaDevices.getUserMedia(isVideoCall ? videoConstraints : audioConstraints); - // localVideoRenderer.srcObject = localStream; - await remoteRenderer.initialize(); - } - // Incoming Listeners void onAnswerOffer(List? payload) async { - if (isIncomingCall) { - // print("--------------------- On Answer Offer Async ---------------------------------------"); - //await invoke(invokeMethod: "InvokeMobile", currentUserID: AppState().getchatUserDetails!.response!.id!, targetUserID: incomingCallData.targetUserId!, debugData: {"On Answer Offer Async"}); - } else { - var items = payload!.toList(); - if (kDebugMode) { - logger.i("res: " + items.toString()); - } - CallSessionPayLoad data = CallSessionPayLoad.fromJson(jsonDecode(items.first.toString())); - RTCSessionDescription description = RTCSessionDescription(data.sdp!.sdp, 'answer'); - _pc.setRemoteDescription(description); + // if (isIncomingCall) { + // // print("--------------------- On Answer Offer Async ---------------------------------------"); + // //await invoke(invokeMethod: "InvokeMobile", currentUserID: AppState().getchatUserDetails!.response!.id!, targetUserID: incomingCallData.targetUserId!, debugData: {"On Answer Offer Async"}); + // } else { + var items = payload!.toList(); + if (kDebugMode) { + logger.i("res: " + items.toString()); } + CallSessionPayLoad data = CallSessionPayLoad.fromJson(jsonDecode(items.first.toString())); + RTCSessionDescription description = RTCSessionDescription(data.sdp!.sdp, 'answer'); + _pc.setRemoteDescription(description); + // } } void onHangUpAsync(List? params) { print("--------------------- onHangUp ---------------------------------------"); isOutGoingCall = false; - // isEndedByCaller = true; - endCall().then((bool value) { + endCall(isUserOnline: false).then((bool value) { Navigator.of(AppRoutes.navigatorKey.currentContext!).pop(); - // notifyListeners(); isCallEnded = true; }); } @@ -425,7 +425,7 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin { }; RTCPeerConnection pc = await createPeerConnection(configuration, offerSdpConstraints); - await pc!.addStream(localStream); + await pc!.addStream(_localStream!); pc?.onConnectionState = (RTCPeerConnectionState state) {}; pc?.onAddStream = (MediaStream stream) { remoteRenderer.srcObject = stream; @@ -435,14 +435,12 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin { if (isIncomingCall) { if (e.candidate != null) { var payload = {"target": incomingCallData.targetUserId, "candidate": e.toMap()}; - logger.i("Candidate:" + e.toMap().toString()); invoke(invokeMethod: "IceCandidateAsync", currentUserID: AppState().chatDetails!.response!.id!, targetUserID: incomingCallData.targetUserId!, data: jsonEncode(payload)); notifyListeners(); } } else { if (e.candidate != null) { var payload = {"target": outGoingCallData.callerId, "candidate": e.toMap()}; - logger.i("Candidate:" + e.toMap().toString()); invoke(invokeMethod: "IceCandidateAsync", currentUserID: outGoingCallData.callerId!, targetUserID: outGoingCallData.receiverId!, data: jsonEncode(payload)); } } @@ -482,23 +480,23 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin { return pc; } - void _onRenegotiate() async { - try { - print('onRenegotiationNeeded start'); - // makingOffer = true; - await _pc.setLocalDescription(await _pc.createOffer(videoConstraints)); - print('onRenegotiationNeeded state after setLocalDescription: ' + _pc.signalingState.toString()); - // send offer via callManager - var localDesc = await _pc.getLocalDescription(); - // callManager.sendCallMessage(MsgType.rtc_offer, RtcOfferAnswer(localDesc.sdp, localDesc.type)); - print('onRenegotiationNeeded; offer sent'); - } catch (e) { - print("onRenegotiationNeeded error: " + e.toString()); - } finally { - // makingOffer = false; - print('onRenegotiationNeeded done'); - } - } + // void _onRenegotiate() async { + // try { + // print('onRenegotiationNeeded start'); + // // makingOffer = true; + // await _pc.setLocalDescription(await _pc.createOffer(videoConstraints)); + // print('onRenegotiationNeeded state after setLocalDescription: ' + _pc.signalingState.toString()); + // // send offer via callManager + // var localDesc = await _pc.getLocalDescription(); + // // callManager.sendCallMessage(MsgType.rtc_offer, RtcOfferAnswer(localDesc.sdp, localDesc.type)); + // print('onRenegotiationNeeded; offer sent'); + // } catch (e) { + // print("onRenegotiationNeeded error: " + e.toString()); + // } finally { + // // makingOffer = false; + // print('onRenegotiationNeeded done'); + // } + // } Future _createOffer() async { RTCSessionDescription description = await _pc!.createOffer(); @@ -518,7 +516,7 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin { void micOff() { isMicOff = !isMicOff; - localStream.getAudioTracks().forEach((track) { + _localStream!.getAudioTracks().forEach((track) { track.enabled = !track.enabled; }); notifyListeners(); @@ -526,7 +524,7 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin { void camOff() { isCamOff = !isCamOff; - localStream.getVideoTracks().forEach((track) { + _localStream!.getVideoTracks().forEach((track) { track.enabled = !track.enabled; }); // if (isCamOff) { @@ -551,18 +549,22 @@ class ChatCallProvider with ChangeNotifier, DiagnosticableTreeMixin { void switchCamera() { isFrontCamera = !isFrontCamera; - Helper.switchCamera(localStream.getVideoTracks()[0]); + Helper.switchCamera(_localStream!.getVideoTracks()[0]); notifyListeners(); } - /////////////////// End Call Page Buttons ///////////////////// - ///////////////// Incoming Call /////////////////////////////// Future initStreams() async { await localVideoRenderer.initialize(); - localStream = await navigator.mediaDevices.getUserMedia(isVideoCall ? videoConstraints : audioConstraints); - localVideoRenderer.srcObject = localStream; + if (_localStream == null) { + MediaStream? m; + _localStream = m; + _localStream = await navigator.mediaDevices.getUserMedia(isVideoCall ? videoConstraints : audioConstraints); + } else { + _localStream = await navigator.mediaDevices.getUserMedia(isVideoCall ? videoConstraints : audioConstraints); + } + localVideoRenderer.srcObject = _localStream; await remoteRenderer.initialize(); } diff --git a/lib/ui/chat/call/chat_incoming_call_screen.dart b/lib/ui/chat/call/chat_incoming_call_screen.dart index df7293e..f72ff84 100644 --- a/lib/ui/chat/call/chat_incoming_call_screen.dart +++ b/lib/ui/chat/call/chat_incoming_call_screen.dart @@ -1,233 +1,589 @@ import 'dart:convert'; +import 'dart:core'; import 'dart:ui'; - -import 'package:flutter/cupertino.dart'; +import 'package:draggable_widget/draggable_widget.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_callkit_incoming/flutter_callkit_incoming.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_webrtc/flutter_webrtc.dart'; +import 'package:mohem_flutter_app/app_state/app_state.dart'; import 'package:mohem_flutter_app/classes/colors.dart'; -import 'package:mohem_flutter_app/classes/utils.dart'; import 'package:mohem_flutter_app/extensions/int_extensions.dart'; import 'package:mohem_flutter_app/main.dart'; import 'package:mohem_flutter_app/models/chat/call.dart'; +import 'package:mohem_flutter_app/models/chat/get_user_login_token_model.dart'; +import 'package:mohem_flutter_app/models/chat/incoming_call_model.dart'; import 'package:mohem_flutter_app/provider/chat_call_provider.dart'; import 'package:mohem_flutter_app/provider/chat_provider_model.dart'; import 'package:provider/provider.dart'; -class IncomingCall extends StatefulWidget { - CallDataModel outGoingCallData; - bool isVideoCall; - - IncomingCall({Key? key, required this.outGoingCallData, required this.isVideoCall}) : super(key: key); - +class StartCallPage extends StatefulWidget { @override - _IncomingCallState createState() => _IncomingCallState(); + _StartCallPageState createState() => _StartCallPageState(); } -class _IncomingCallState extends State with SingleTickerProviderStateMixin { - late ChatCallProvider callProvider; - late ChatProviderModel chatProvider; +class _StartCallPageState extends State { + DragController dragController = DragController(); + bool isOutGoingCall = false; + bool isIncomingCall = false; + late ChatCallProvider cProv; + late ChatProviderModel provider; @override void initState() { - chatProvider = Provider.of(context, listen: false); - callProvider = Provider.of(context, listen: false); - init(); + cProv = Provider.of(context, listen: false); + provider = Provider.of(context, listen: false); super.initState(); + startCall(); } - void init() { - widget.isVideoCall ? callProvider.isVideoCall = true : callProvider.isVideoCall = false; - callProvider.initLocalCamera(chatProvmodel: chatProvider, callData: widget.outGoingCallData, context: context, isIncomingCall: true); - callProvider.init(); + @override + void dispose() { + super.dispose(); } + void startCall() async { + IncomingCallModel? sessionData; + dynamic calls = await FlutterCallkitIncoming.activeCalls(); + if (calls.isNotEmpty) { + sessionData = IncomingCallModel.fromRawJson(jsonEncode(calls[0])); + isIncomingCall = sessionData.extra!.isIncomingCall!; + } + if (isIncomingCall) { + if (provider.isUserOnline) { + if (kDebugMode) { + print("====== Processing Incoming Call in Online State ========="); + } + await cProv.startIncomingCallViaKit(inCallData: sessionData!.extra!.callerDetails!.toJson()); + cProv.init(); + } else { + if (kDebugMode) { + print("====== Processing Incoming Call ========="); + } + await cProv.startIncomingCallViaKit(inCallData: sessionData!.extra!.callerDetails!.toJson()); + try { + AppState().setchatUserDetails = UserAutoLoginModel(response: Response.fromJson(sessionData.extra!.loginDetails!.toJson()), errorResponses: null); + await provider.buildHubConnection(context: context, ccProvider: cProv).whenComplete(() { + cProv.init(); + }); + } catch (e) { + logger.w(e); + } + if (kDebugMode) { + print('========== END =============='); + } + } + } + // else if (isOutGoingCall) { + // if (kDebugMode) { + // print("====== Processing Outgoing Call ========="); + // } + // + // } + else { + if (kDebugMode) { + print("====== Something Wrong With Call ========="); + } + } + } + + // void connection({required data, required bool isUserOnline}) async { + // if (isUserOnline) { + // cProv.isUserOnline = isUserOnline; + // cProv.startIncomingCallViaKit(inCallData: data); + // } else { + // dynamic callData = await jsonDecode(data); + // AppState().setchatUserDetails = UserAutoLoginModel( + // response: Response.fromJson(callData[0]["loginDetails"]), + // errorResponses: null, + // ); + // Utils.saveStringFromPrefs( + // "userLoginChatDetails", + // UserAutoLoginModel( + // response: Response.fromJson(callData[0]["loginDetails"]), + // errorResponses: null, + // ).toJson().toString()); + // cProv.startIncomingCallViaKit(inCallData: data); + // try { + // await prov.buildHubConnection(context: AppRoutes.navigatorKey.currentContext!, ccProvider: cProv).whenComplete(() { + // cProv.init(); + // }); + // } catch (e) { + // logger.w(e); + // } + // } + // } + @override Widget build(BuildContext context) { return Scaffold( - body: Consumer(builder: (BuildContext context, ChatCallProvider chatcp, Widget? child) { - if (chatcp.isCallEnded) Navigator.pop(context); - return Stack( - alignment: FractionalOffset.center, - children: [ - if (widget.isVideoCall) - Positioned.fill( - child: RTCVideoView( - callProvider.localVideoRenderer, - objectFit: RTCVideoViewObjectFit.RTCVideoViewObjectFitCover, - ), - ), - Positioned.fill( - child: ClipRect( - child: BackdropFilter( - filter: ImageFilter.blur(sigmaX: 5.0, sigmaY: 5.0), - child: Container( - decoration: BoxDecoration( - color: MyColors.grey57Color.withOpacity( - 0.3, - ), - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.max, - children: [ - 40.height, - Row( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Container( - margin: const EdgeInsets.all(21.0), - child: Container( - margin: const EdgeInsets.only( - left: 10.0, - right: 10.0, + extendBody: true, + body: Consumer2( + builder: (BuildContext context, ChatCallProvider provider, ChatProviderModel cpm, Widget? child) { + return provider.isIncomingCallLoader + ? const SizedBox( + width: double.infinity, + height: double.infinity, + child: Center(child: CircularProgressIndicator()), + ) + : provider.isIncomingCall + ? SizedBox( + width: double.infinity, + height: double.infinity, + child: Stack( + alignment: FractionalOffset.center, + children: [ + if (!provider.isAudioCall && provider.isVideoCall) + Positioned.fill( + child: RTCVideoView( + provider.remoteRenderer, + objectFit: RTCVideoViewObjectFit.RTCVideoViewObjectFitCover, + key: const Key('remote'), + ), + ), + if (provider.isVideoCall) + DraggableWidget( + bottomMargin: 20, + topMargin: 40, + intialVisibility: true, + horizontalSpace: 20, + shadowBorderRadius: 50, + initialPosition: AnchoringPosition.topLeft, + dragController: dragController, + normalShadow: const BoxShadow(spreadRadius: 0.0, blurRadius: 0.0), + draggingShadow: const BoxShadow(spreadRadius: 0.0, blurRadius: 0.0), + child: SizedBox( + height: 200, + width: 140, + child: RTCVideoView( + provider.localVideoRenderer, + mirror: true, + objectFit: RTCVideoViewObjectFit.RTCVideoViewObjectFitCover, ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ - SvgPicture.asset( - "assets/images/user.svg", - height: 70, - width: 70, - fit: BoxFit.cover, - ), - 10.height, - Text( - widget.outGoingCallData.receiverName.toString().replaceAll(".", " "), - style: const TextStyle( - fontSize: 21, - fontWeight: FontWeight.bold, - color: MyColors.white, - letterSpacing: -1.26, - height: 23 / 12, + ), + ), + if (!provider.isVideoCall) + Positioned.fill( + child: ClipRect( + child: BackdropFilter( + filter: ImageFilter.blur(sigmaX: 5.0, sigmaY: 5.0), + child: Container( + decoration: BoxDecoration( + color: MyColors.grey57Color.withOpacity( + 0.3, ), ), - const Text( - "Ringing...", - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.w600, - color: Color( - 0xffC6C6C6, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.max, + children: [ + 40.height, + Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Container( + margin: const EdgeInsets.all(21.0), + child: Container( + margin: const EdgeInsets.only( + left: 10.0, + right: 10.0, + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + SvgPicture.asset( + "assets/images/user.svg", + height: 70, + width: 70, + fit: BoxFit.cover, + ), + 10.height, + Text( + provider.outGoingCallData.receiverName!, + style: const TextStyle( + fontSize: 21, + decoration: TextDecoration.none, + fontWeight: FontWeight.bold, + color: MyColors.white, + letterSpacing: -1.26, + height: 23 / 12, + ), + ), + const Text( + "On Call", + style: TextStyle( + fontSize: 16, + decoration: TextDecoration.none, + fontWeight: FontWeight.w600, + color: Color( + 0xffC6C6C6, + ), + letterSpacing: -0.48, + height: 23 / 24, + ), + ), + const SizedBox( + height: 2, + ), + ], + ), + ), + ), + ], ), - letterSpacing: -0.48, - height: 23 / 24, - ), - ), - const SizedBox( - height: 2, + ], ), - ], + ), ), ), ), - ], - ), - const Spacer(), - Container( - margin: const EdgeInsets.only( - bottom: 70.0, - left: 49, - right: 49, - ), - child: Row( - mainAxisSize: MainAxisSize.max, - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - if (widget.isVideoCall) - RawMaterialButton( - onPressed: () { - callProvider.camOff(); - }, - elevation: 2.0, - fillColor: callProvider.isCamOff ? MyColors.green2DColor : Colors.grey, - padding: const EdgeInsets.all( - 15.0, + Align( + alignment: Alignment.bottomCenter, + child: Container( + padding: const EdgeInsets.only( + bottom: 20, + left: 40, + right: 40, + ), + child: Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + // if (provider.isVideoCall) + RawMaterialButton( + constraints: const BoxConstraints(), + onPressed: () { + provider.loudOn(); + }, + elevation: 2.0, + fillColor: provider.isLoudSpeaker ? MyColors.textMixColor : Colors.grey, + padding: const EdgeInsets.all( + 10.0, + ), + shape: const CircleBorder(), + child: const Icon( + Icons.volume_up, + color: MyColors.white, + size: 30.0, + ), ), - shape: const CircleBorder(), - child: Icon( - callProvider.isCamOff ? Icons.videocam_off : Icons.videocam, - color: MyColors.white, - size: 35.0, + RawMaterialButton( + constraints: const BoxConstraints(), + onPressed: () { + provider.camOff(); + }, + elevation: 2.0, + fillColor: provider.isCamOff ? MyColors.textMixColor : Colors.grey, + padding: const EdgeInsets.all( + 10.0, + ), + shape: const CircleBorder(), + child: Icon( + provider.isCamOff ? Icons.videocam_off : Icons.videocam, + color: MyColors.white, + size: 30.0, + ), + ), + RawMaterialButton( + constraints: const BoxConstraints(), + onPressed: () { + provider.switchCamera(); + }, + elevation: 2.0, + fillColor: provider.isFrontCamera ? Colors.grey : MyColors.textMixColor, + padding: const EdgeInsets.all( + 10.0, + ), + shape: const CircleBorder(), + child: Icon( + provider.isFrontCamera ? Icons.switch_camera_outlined : Icons.switch_camera, + color: MyColors.white, + size: 30.0, + ), ), - ) - else - RawMaterialButton( - onPressed: () { - callProvider.loudOn(); - }, - elevation: 2.0, - fillColor: callProvider.isLoudSpeaker ? MyColors.green2DColor : Colors.grey, - padding: const EdgeInsets.all( - 15.0, + RawMaterialButton( + constraints: const BoxConstraints(), + onPressed: () { + provider.micOff(); + }, + elevation: 2.0, + fillColor: provider.isMicOff ? MyColors.textMixColor : Colors.grey, + padding: const EdgeInsets.all( + 10.0, + ), + shape: const CircleBorder(), + child: Icon( + provider.isMicOff ? Icons.mic_off : Icons.mic, + color: MyColors.white, + size: 30.0, + ), ), - shape: const CircleBorder(), - child: const Icon( - Icons.volume_up, - color: MyColors.white, - size: 35.0, + RawMaterialButton( + constraints: const BoxConstraints(), + onPressed: () { + provider.endCall(isUserOnline: cpm.isUserOnline).then((bool value) { + if (value) { + Navigator.of(context).pop(); + print("Reintiiiiiiitttiiiiiiii"); + provider.initStreams(); + } + }); + }, + elevation: 2.0, + fillColor: MyColors.redA3Color, + padding: const EdgeInsets.all( + 10.0, + ), + shape: const CircleBorder(), + child: const Icon( + Icons.call_end, + color: MyColors.white, + size: 30.0, + ), + ), + ], + ), + ), + ), + ], + ), + ) + : provider.isOutGoingCall + ? SizedBox( + width: double.infinity, + height: double.infinity, + child: Stack( + alignment: FractionalOffset.center, + children: [ + if (!provider.isAudioCall && provider.isVideoCall) + Positioned.fill( + child: RTCVideoView( + provider.remoteRenderer, + objectFit: RTCVideoViewObjectFit.RTCVideoViewObjectFitCover, + key: const Key('remote'), ), ), - RawMaterialButton( - onPressed: () { - callProvider.micOff(); - }, - elevation: 2.0, - fillColor: callProvider.isMicOff ? MyColors.green2DColor : Colors.grey, - padding: const EdgeInsets.all( - 15.0, - ), - shape: const CircleBorder(), - child: Icon( - callProvider.isMicOff ? Icons.mic_off : Icons.mic, - color: MyColors.white, - size: 35.0, + if (provider.isVideoCall) + DraggableWidget( + bottomMargin: 20, + topMargin: 40, + intialVisibility: true, + horizontalSpace: 20, + shadowBorderRadius: 50, + initialPosition: AnchoringPosition.topLeft, + dragController: dragController, + normalShadow: const BoxShadow(spreadRadius: 0.0, blurRadius: 0.0), + draggingShadow: const BoxShadow(spreadRadius: 0.0, blurRadius: 0.0), + child: SizedBox( + height: 200, + width: 140, + child: RTCVideoView( + provider.localVideoRenderer, + mirror: true, + objectFit: RTCVideoViewObjectFit.RTCVideoViewObjectFitCover, + ), + ), ), - ), - RawMaterialButton( - onPressed: () { - callProvider.endCall().then((value) { - if (value) { - Navigator.of(context).pop(); - } - }); - }, - elevation: 2.0, - fillColor: MyColors.redA3Color, - padding: const EdgeInsets.all( - 15.0, + if (!provider.isVideoCall) + Positioned.fill( + child: ClipRect( + child: BackdropFilter( + filter: ImageFilter.blur(sigmaX: 5.0, sigmaY: 5.0), + child: Container( + decoration: BoxDecoration( + color: MyColors.grey57Color.withOpacity( + 0.3, + ), + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.max, + children: [ + 40.height, + Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Container( + margin: const EdgeInsets.all(21.0), + child: Container( + margin: const EdgeInsets.only( + left: 10.0, + right: 10.0, + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + SvgPicture.asset( + "assets/images/user.svg", + height: 70, + width: 70, + fit: BoxFit.cover, + ), + 10.height, + Text( + provider.outGoingCallData.receiverName!, + style: const TextStyle( + fontSize: 21, + decoration: TextDecoration.none, + fontWeight: FontWeight.bold, + color: MyColors.white, + letterSpacing: -1.26, + height: 23 / 12, + ), + ), + const Text( + "On Call", + style: TextStyle( + fontSize: 16, + decoration: TextDecoration.none, + fontWeight: FontWeight.w600, + color: Color( + 0xffC6C6C6, + ), + letterSpacing: -0.48, + height: 23 / 24, + ), + ), + const SizedBox( + height: 2, + ), + ], + ), + ), + ), + ], + ), + ], + ), + ), + ), + ), ), - shape: const CircleBorder(), - child: const Icon( - Icons.call_end, - color: MyColors.white, - size: 35.0, + Align( + alignment: Alignment.bottomCenter, + child: Container( + padding: const EdgeInsets.only( + bottom: 20, + left: 40, + right: 40, + ), + child: Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + // if (provider.isVideoCall) + RawMaterialButton( + constraints: const BoxConstraints(), + onPressed: () { + provider.loudOn(); + }, + elevation: 2.0, + fillColor: provider.isLoudSpeaker ? MyColors.textMixColor : Colors.grey, + padding: const EdgeInsets.all( + 10.0, + ), + shape: const CircleBorder(), + child: const Icon( + Icons.volume_up, + color: MyColors.white, + size: 30.0, + ), + ), + RawMaterialButton( + constraints: const BoxConstraints(), + onPressed: () { + provider.camOff(); + }, + elevation: 2.0, + fillColor: provider.isCamOff ? MyColors.textMixColor : Colors.grey, + padding: const EdgeInsets.all( + 10.0, + ), + shape: const CircleBorder(), + child: Icon( + provider.isCamOff ? Icons.videocam_off : Icons.videocam, + color: MyColors.white, + size: 30.0, + ), + ), + RawMaterialButton( + constraints: const BoxConstraints(), + onPressed: () { + provider.switchCamera(); + }, + elevation: 2.0, + fillColor: provider.isFrontCamera ? Colors.grey : MyColors.textMixColor, + padding: const EdgeInsets.all( + 10.0, + ), + shape: const CircleBorder(), + child: Icon( + provider.isFrontCamera ? Icons.switch_camera_outlined : Icons.switch_camera, + color: MyColors.white, + size: 30.0, + ), + ), + RawMaterialButton( + constraints: const BoxConstraints(), + onPressed: () { + provider.micOff(); + }, + elevation: 2.0, + fillColor: provider.isMicOff ? MyColors.textMixColor : Colors.grey, + padding: const EdgeInsets.all( + 10.0, + ), + shape: const CircleBorder(), + child: Icon( + provider.isMicOff ? Icons.mic_off : Icons.mic, + color: MyColors.white, + size: 30.0, + ), + ), + RawMaterialButton( + constraints: const BoxConstraints(), + onPressed: () { + provider.endCall(isUserOnline: cpm.isUserOnline).then((bool value) { + if (value) { + Navigator.of(context).pop(); + } + }); + }, + elevation: 2.0, + fillColor: MyColors.redA3Color, + padding: const EdgeInsets.all( + 10.0, + ), + shape: const CircleBorder(), + child: const Icon( + Icons.call_end, + color: MyColors.white, + size: 30.0, + ), + ), + ], + ), ), ), ], ), - ), - ], - ), - ), - ), - ), - ), - ], - ); - }), - ); - } - - BoxDecoration cardRadius(double radius, {required Color color, double? elevation}) { - return BoxDecoration( - shape: BoxShape.rectangle, - color: color ?? Colors.white, - borderRadius: BorderRadius.all(Radius.circular(radius)), - boxShadow: [BoxShadow(color: const Color(0xff000000).withOpacity(.05), blurRadius: elevation ?? 27, offset: const Offset(-2, 3))], + ) + : const SizedBox(); + }, + ), ); } } + +/// if (Platform.isAndroid) { +// SystemNavigator.pop(); +// } else if (Platform.isIOS) { +// exit(0); +// } diff --git a/lib/ui/chat/call/chat_outgoing_call_screen.dart b/lib/ui/chat/call/chat_outgoing_call_screen.dart index 5fefa22..2767e57 100644 --- a/lib/ui/chat/call/chat_outgoing_call_screen.dart +++ b/lib/ui/chat/call/chat_outgoing_call_screen.dart @@ -6,13 +6,11 @@ import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_webrtc/flutter_webrtc.dart'; import 'package:mohem_flutter_app/classes/colors.dart'; -import 'package:mohem_flutter_app/classes/utils.dart'; import 'package:mohem_flutter_app/extensions/int_extensions.dart'; -import 'package:mohem_flutter_app/main.dart'; import 'package:mohem_flutter_app/models/chat/call.dart'; import 'package:mohem_flutter_app/provider/chat_call_provider.dart'; import 'package:mohem_flutter_app/provider/chat_provider_model.dart'; -import 'package:mohem_flutter_app/ui/chat/call/start_call_screen.dart'; +import 'package:mohem_flutter_app/ui/chat/call/chat_incoming_call_screen.dart'; import 'package:provider/provider.dart'; class OutGoingCall extends StatefulWidget { @@ -43,215 +41,144 @@ class _OutGoingCallState extends State { callProvider.initLocalCamera(chatProvmodel: chatProvider, callData: widget.outGoingCallData, context: context); } + @override + void dispose() { + super.dispose(); + } + @override Widget build(BuildContext context) { return Scaffold( - body:Consumer(builder: (BuildContext context, ChatCallProvider chatcp, Widget? child) { - if (chatcp.isCallEnded) Navigator.pop(context); - return Stack( - alignment: FractionalOffset.center, - children: [ - if (chatcp.isVideoCall) - Positioned.fill( - child: RTCVideoView( - callProvider.localVideoRenderer, - objectFit: RTCVideoViewObjectFit.RTCVideoViewObjectFitCover, + body: Consumer(builder: (BuildContext context, ChatCallProvider chatcp, Widget? child) { + if (chatcp.isCallEnded) { + Navigator.pop(context); + print("Reintiiiiiiittt"); + chatcp.initStreams(); + } + return Stack( + alignment: FractionalOffset.center, + children: [ + if (chatcp.isVideoCall) + Positioned.fill( + child: RTCVideoView( + chatcp.localVideoRenderer, + objectFit: RTCVideoViewObjectFit.RTCVideoViewObjectFitCover, + ), + ), + Positioned.fill( + child: ClipRect( + child: BackdropFilter( + filter: ImageFilter.blur(sigmaX: 5.0, sigmaY: 5.0), + child: Container( + decoration: BoxDecoration( + color: MyColors.grey57Color.withOpacity( + 0.3, ), ), - Positioned.fill( - child: ClipRect( - child: BackdropFilter( - filter: ImageFilter.blur(sigmaX: 5.0, sigmaY: 5.0), - child: Container( - decoration: BoxDecoration( - color: MyColors.grey57Color.withOpacity( - 0.3, - ), - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.max, - children: [ - 40.height, - Row( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Container( - margin: const EdgeInsets.all(21.0), - child: Container( - margin: const EdgeInsets.only( - left: 10.0, - right: 10.0, - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ - SvgPicture.asset( - "assets/images/user.svg", - height: 70, - width: 70, - fit: BoxFit.cover, - ), - 10.height, - Text( - widget.outGoingCallData.receiverName.toString().replaceAll(".", " "), - style: const TextStyle( - fontSize: 21, - fontWeight: FontWeight.bold, - color: MyColors.white, - letterSpacing: -1.26, - height: 23 / 12, - ), - ), - const Text( - "Ringing...", - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.w600, - color: Color( - 0xffC6C6C6, - ), - letterSpacing: -0.48, - height: 23 / 24, - ), - ), - const SizedBox( - height: 2, - ), - ], - ), - ), - ), - ], - ), - // Container( - // margin: const EdgeInsets.all(21.0), - // width: MediaQuery.of(context).size.width, - // decoration: cardRadius(15.0, color: MyColors.black, elevation: null), - // child: Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // mainAxisSize: MainAxisSize.min, - // children: [ - // Container( - // padding: const EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 6.0), - // child: Text( - // "TranslationBase.of(context).appoInfo", - // style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: MyColors.white, letterSpacing: -0.64, height: 23 / 12), - // ), - // ), - // Container( - // padding: const EdgeInsets.only(left: 16.0, right: 16.0), - // child: Text( - // "widget.OutGoingCallData.appointmentdate + widget.OutGoingCallData.appointmenttime", - // style: TextStyle(fontSize: 12.0, letterSpacing: -0.48, color: Color(0xff8E8E8E), fontWeight: FontWeight.w600), - // ), - // ), - // Container( - // padding: const EdgeInsets.only(left: 16.0, right: 16.0, bottom: 21.0), - // child: Text( - // "widget.OutGoingCallData.clinicname", - // style: TextStyle(fontSize: 12.0, letterSpacing: -0.48, color: Color(0xff8E8E8E), fontWeight: FontWeight.w600), - // ), - // ), - // ], - // ), - // ), - const Spacer(), - Container( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.max, + children: [ + 40.height, + Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Container( + margin: const EdgeInsets.all(21.0), + child: Container( margin: const EdgeInsets.only( - bottom: 70.0, - left: 49, - right: 49, + left: 10.0, + right: 10.0, ), - child: Row( - mainAxisSize: MainAxisSize.max, - mainAxisAlignment: MainAxisAlignment.center, + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ - // if (widget.isVideoCall) - // RawMaterialButton( - // onPressed: () { - // callProvider.camOff(); - // }, - // elevation: 2.0, - // fillColor: callProvider.isCamOff ? MyColors.green2DColor : Colors.grey, - // padding: const EdgeInsets.all( - // 15.0, - // ), - // shape: const CircleBorder(), - // child: Icon( - // callProvider.isCamOff ? Icons.videocam_off : Icons.videocam, - // color: MyColors.white, - // size: 35.0, - // ), - // ) - // else - // RawMaterialButton( - // onPressed: () { - // callProvider.loudOn(); - // }, - // elevation: 2.0, - // fillColor: callProvider.isLoudSpeaker ? MyColors.green2DColor : Colors.grey, - // padding: const EdgeInsets.all( - // 15.0, - // ), - // shape: const CircleBorder(), - // child: const Icon( - // Icons.volume_up, - // color: MyColors.white, - // size: 35.0, - // ), - // ), - // RawMaterialButton( - // onPressed: () { - // callProvider.micOff(); - // }, - // elevation: 2.0, - // fillColor: callProvider.isMicOff ? MyColors.green2DColor : Colors.grey, - // padding: const EdgeInsets.all( - // 15.0, - // ), - // shape: const CircleBorder(), - // child: Icon( - // callProvider.isMicOff ? Icons.mic_off : Icons.mic, - // color: MyColors.white, - // size: 35.0, - // ), - // ), - RawMaterialButton( - onPressed: () { - callProvider.endCall().then((bool value) { - if (value) { - Navigator.of(context).pop(); - } - }); - }, - elevation: 2.0, - fillColor: MyColors.redA3Color, - padding: const EdgeInsets.all( - 15.0, - ), - shape: const CircleBorder(), - child: const Icon( - Icons.call_end, + SvgPicture.asset( + "assets/images/user.svg", + height: 70, + width: 70, + fit: BoxFit.cover, + ), + 10.height, + Text( + widget.outGoingCallData.receiverName.toString().replaceAll(".", " "), + style: const TextStyle( + fontSize: 21, + fontWeight: FontWeight.bold, color: MyColors.white, - size: 35.0, + letterSpacing: -1.26, + height: 23 / 12, ), ), + const Text( + "Ringing...", + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.w600, + color: Color( + 0xffC6C6C6, + ), + letterSpacing: -0.48, + height: 23 / 24, + ), + ), + const SizedBox( + height: 2, + ), ], ), ), + ), + ], + ), + const Spacer(), + Container( + margin: const EdgeInsets.only( + bottom: 70.0, + left: 49, + right: 49, + ), + child: Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + RawMaterialButton( + onPressed: () { + chatcp.endCall(isUserOnline: chatProvider.isUserOnline).then((bool value) { + if (value) { + Navigator.of(context).pop(); + print("Reintiiiiiiitttzzzz"); + chatcp.initStreams(); + } + }); + }, + elevation: 2.0, + fillColor: MyColors.redA3Color, + padding: const EdgeInsets.all( + 15.0, + ), + shape: const CircleBorder(), + child: const Icon( + Icons.call_end, + color: MyColors.white, + size: 35.0, + ), + ), ], ), ), - ), + ], ), ), - ], - ); - }), + ), + ), + ), + ], + ); + }), ); } diff --git a/lib/ui/chat/call/start_call_screen.dart b/lib/ui/chat/call/start_call_screen.dart deleted file mode 100644 index 09448d5..0000000 --- a/lib/ui/chat/call/start_call_screen.dart +++ /dev/null @@ -1,593 +0,0 @@ -import 'dart:convert'; -import 'dart:core'; -import 'dart:ui'; -import 'package:draggable_widget/draggable_widget.dart'; -import 'package:flutter/foundation.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_callkit_incoming/flutter_callkit_incoming.dart'; -import 'package:flutter_svg/flutter_svg.dart'; -import 'package:flutter_webrtc/flutter_webrtc.dart'; -import 'package:mohem_flutter_app/app_state/app_state.dart'; -import 'package:mohem_flutter_app/classes/colors.dart'; -import 'package:mohem_flutter_app/extensions/int_extensions.dart'; -import 'package:mohem_flutter_app/main.dart'; -import 'package:mohem_flutter_app/models/chat/get_user_login_token_model.dart'; -import 'package:mohem_flutter_app/models/chat/incoming_call_model.dart'; -import 'package:mohem_flutter_app/provider/chat_call_provider.dart'; -import 'package:mohem_flutter_app/provider/chat_provider_model.dart'; -import 'package:provider/provider.dart'; - -class StartCallPage extends StatefulWidget { - - @override - _StartCallPageState createState() => _StartCallPageState(); -} - -class _StartCallPageState extends State { - DragController dragController = DragController(); - bool isOutGoingCall = false; - bool isIncomingCall = false; - late ChatCallProvider cProv; - late ChatProviderModel provider; - - @override - void initState() { - super.initState(); - cProv = Provider.of(context, listen: false); - provider = Provider.of(context, listen: false); - startCall(); - } - - @override - void dispose() { - super.dispose(); - } - - void startCall() async { - IncomingCallModel? sessionData; - dynamic calls = await FlutterCallkitIncoming.activeCalls(); - if (calls.isNotEmpty) { - sessionData = IncomingCallModel.fromRawJson(jsonEncode(calls[0])); - isIncomingCall = sessionData.extra!.isIncomingCall!; - } - if (isIncomingCall) { - if (provider.isUserOnline) { - if (kDebugMode) { - print("====== Processing Incoming Call in Online State ========="); - } - await cProv.startIncomingCallViaKit(inCallData: sessionData!.extra!.callerDetails!.toJson()); - cProv.init(); - } else { - if (kDebugMode) { - print("====== Processing Incoming Call ========="); - } - await cProv.startIncomingCallViaKit(inCallData: sessionData!.extra!.callerDetails!.toJson()); - try { - AppState().setchatUserDetails = UserAutoLoginModel(response: Response.fromJson(sessionData.extra!.loginDetails!.toJson()), errorResponses: null); - await provider.buildHubConnection(context: context, ccProvider: cProv).whenComplete(() { - cProv.init(); - }); - } catch (e) { - logger.w(e); - } - if (kDebugMode) { - print('========== END =============='); - } - } - } else if (isOutGoingCall) { - if (kDebugMode) { - print("====== Processing Outgoing Call ========="); - } - } else { - if (kDebugMode) { - print("====== Something Wrong With Call ========="); - } - } - logger.d(sessionData!.extra!.isIncomingCall); - } - - - - // void connection({required data, required bool isUserOnline}) async { - // if (isUserOnline) { - // cProv.isUserOnline = isUserOnline; - // cProv.startIncomingCallViaKit(inCallData: data); - // } else { - // dynamic callData = await jsonDecode(data); - // AppState().setchatUserDetails = UserAutoLoginModel( - // response: Response.fromJson(callData[0]["loginDetails"]), - // errorResponses: null, - // ); - // Utils.saveStringFromPrefs( - // "userLoginChatDetails", - // UserAutoLoginModel( - // response: Response.fromJson(callData[0]["loginDetails"]), - // errorResponses: null, - // ).toJson().toString()); - // cProv.startIncomingCallViaKit(inCallData: data); - // try { - // await prov.buildHubConnection(context: AppRoutes.navigatorKey.currentContext!, ccProvider: cProv).whenComplete(() { - // cProv.init(); - // }); - // } catch (e) { - // logger.w(e); - // } - // } - // } - - @override - Widget build(BuildContext context) { - return Scaffold( - extendBody: true, - body: Consumer2( - builder: (BuildContext context, ChatCallProvider provider, ChatProviderModel cpm, Widget? child) { - return provider.isIncomingCallLoader - ? const SizedBox( - width: double.infinity, - height: double.infinity, - child: Center(child: CircularProgressIndicator()), - ) - : provider.isIncomingCall - ? SizedBox( - width: double.infinity, - height: double.infinity, - child: Stack( - alignment: FractionalOffset.center, - children: [ - if (!provider.isAudioCall && provider.isVideoCall) - Positioned.fill( - child: RTCVideoView( - provider.remoteRenderer, - objectFit: RTCVideoViewObjectFit.RTCVideoViewObjectFitCover, - key: const Key('remote'), - ), - ), - if (provider.isVideoCall) - DraggableWidget( - bottomMargin: 20, - topMargin: 40, - intialVisibility: true, - horizontalSpace: 20, - shadowBorderRadius: 50, - initialPosition: AnchoringPosition.topLeft, - dragController: dragController, - normalShadow: const BoxShadow(spreadRadius: 0.0, blurRadius: 0.0), - draggingShadow: const BoxShadow(spreadRadius: 0.0, blurRadius: 0.0), - child: SizedBox( - height: 200, - width: 140, - child: RTCVideoView( - provider.localVideoRenderer, - mirror: true, - objectFit: RTCVideoViewObjectFit.RTCVideoViewObjectFitCover, - ), - ), - ), - if (!provider.isVideoCall) - Positioned.fill( - child: ClipRect( - child: BackdropFilter( - filter: ImageFilter.blur(sigmaX: 5.0, sigmaY: 5.0), - child: Container( - decoration: BoxDecoration( - color: MyColors.grey57Color.withOpacity( - 0.3, - ), - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.max, - children: [ - 40.height, - Row( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Container( - margin: const EdgeInsets.all(21.0), - child: Container( - margin: const EdgeInsets.only( - left: 10.0, - right: 10.0, - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ - SvgPicture.asset( - "assets/images/user.svg", - height: 70, - width: 70, - fit: BoxFit.cover, - ), - 10.height, - Text( - provider.outGoingCallData.receiverName!, - style: const TextStyle( - fontSize: 21, - decoration: TextDecoration.none, - fontWeight: FontWeight.bold, - color: MyColors.white, - letterSpacing: -1.26, - height: 23 / 12, - ), - ), - const Text( - "On Call", - style: TextStyle( - fontSize: 16, - decoration: TextDecoration.none, - fontWeight: FontWeight.w600, - color: Color( - 0xffC6C6C6, - ), - letterSpacing: -0.48, - height: 23 / 24, - ), - ), - const SizedBox( - height: 2, - ), - ], - ), - ), - ), - ], - ), - ], - ), - ), - ), - ), - ), - Align( - alignment: Alignment.bottomCenter, - child: Container( - padding: const EdgeInsets.only( - bottom: 20, - left: 40, - right: 40, - ), - child: Row( - mainAxisSize: MainAxisSize.max, - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - // if (provider.isVideoCall) - RawMaterialButton( - constraints: const BoxConstraints(), - onPressed: () { - provider.loudOn(); - }, - elevation: 2.0, - fillColor: provider.isLoudSpeaker ? MyColors.textMixColor : Colors.grey, - padding: const EdgeInsets.all( - 10.0, - ), - shape: const CircleBorder(), - child: const Icon( - Icons.volume_up, - color: MyColors.white, - size: 30.0, - ), - ), - RawMaterialButton( - constraints: const BoxConstraints(), - onPressed: () { - provider.camOff(); - }, - elevation: 2.0, - fillColor: provider.isCamOff ? MyColors.textMixColor : Colors.grey, - padding: const EdgeInsets.all( - 10.0, - ), - shape: const CircleBorder(), - child: Icon( - provider.isCamOff ? Icons.videocam_off : Icons.videocam, - color: MyColors.white, - size: 30.0, - ), - ), - RawMaterialButton( - constraints: const BoxConstraints(), - onPressed: () { - provider.switchCamera(); - }, - elevation: 2.0, - fillColor: provider.isFrontCamera ? Colors.grey : MyColors.textMixColor, - padding: const EdgeInsets.all( - 10.0, - ), - shape: const CircleBorder(), - child: Icon( - provider.isFrontCamera ? Icons.switch_camera_outlined : Icons.switch_camera, - color: MyColors.white, - size: 30.0, - ), - ), - RawMaterialButton( - constraints: const BoxConstraints(), - onPressed: () { - provider.micOff(); - }, - elevation: 2.0, - fillColor: provider.isMicOff ? MyColors.textMixColor : Colors.grey, - padding: const EdgeInsets.all( - 10.0, - ), - shape: const CircleBorder(), - child: Icon( - provider.isMicOff ? Icons.mic_off : Icons.mic, - color: MyColors.white, - size: 30.0, - ), - ), - RawMaterialButton( - constraints: const BoxConstraints(), - onPressed: () { - provider.endCall().then((bool value) { - if (value) { - Navigator.of(context).pop(); - } - }); - }, - elevation: 2.0, - fillColor: MyColors.redA3Color, - padding: const EdgeInsets.all( - 10.0, - ), - shape: const CircleBorder(), - child: const Icon( - Icons.call_end, - color: MyColors.white, - size: 30.0, - ), - ), - ], - ), - ), - ), - ], - ), - ) - : provider.isOutGoingCall - ? SizedBox( - width: double.infinity, - height: double.infinity, - child: Stack( - alignment: FractionalOffset.center, - children: [ - if (!provider.isAudioCall && provider.isVideoCall) - Positioned.fill( - child: RTCVideoView( - provider.remoteRenderer, - objectFit: RTCVideoViewObjectFit.RTCVideoViewObjectFitCover, - key: const Key('remote'), - ), - ), - if (provider.isVideoCall) - DraggableWidget( - bottomMargin: 20, - topMargin: 40, - intialVisibility: true, - horizontalSpace: 20, - shadowBorderRadius: 50, - initialPosition: AnchoringPosition.topLeft, - dragController: dragController, - normalShadow: const BoxShadow(spreadRadius: 0.0, blurRadius: 0.0), - draggingShadow: const BoxShadow(spreadRadius: 0.0, blurRadius: 0.0), - child: SizedBox( - height: 200, - width: 140, - child: RTCVideoView( - provider.localVideoRenderer, - mirror: true, - objectFit: RTCVideoViewObjectFit.RTCVideoViewObjectFitCover, - ), - ), - ), - if (!provider.isVideoCall) - Positioned.fill( - child: ClipRect( - child: BackdropFilter( - filter: ImageFilter.blur(sigmaX: 5.0, sigmaY: 5.0), - child: Container( - decoration: BoxDecoration( - color: MyColors.grey57Color.withOpacity( - 0.3, - ), - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.max, - children: [ - 40.height, - Row( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Container( - margin: const EdgeInsets.all(21.0), - child: Container( - margin: const EdgeInsets.only( - left: 10.0, - right: 10.0, - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ - SvgPicture.asset( - "assets/images/user.svg", - height: 70, - width: 70, - fit: BoxFit.cover, - ), - 10.height, - Text( - provider.outGoingCallData.receiverName!, - style: const TextStyle( - fontSize: 21, - decoration: TextDecoration.none, - fontWeight: FontWeight.bold, - color: MyColors.white, - letterSpacing: -1.26, - height: 23 / 12, - ), - ), - const Text( - "On Call", - style: TextStyle( - fontSize: 16, - decoration: TextDecoration.none, - fontWeight: FontWeight.w600, - color: Color( - 0xffC6C6C6, - ), - letterSpacing: -0.48, - height: 23 / 24, - ), - ), - const SizedBox( - height: 2, - ), - ], - ), - ), - ), - ], - ), - ], - ), - ), - ), - ), - ), - Align( - alignment: Alignment.bottomCenter, - child: Container( - padding: const EdgeInsets.only( - bottom: 20, - left: 40, - right: 40, - ), - child: Row( - mainAxisSize: MainAxisSize.max, - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - // if (provider.isVideoCall) - RawMaterialButton( - constraints: const BoxConstraints(), - onPressed: () { - provider.loudOn(); - }, - elevation: 2.0, - fillColor: provider.isLoudSpeaker ? MyColors.textMixColor : Colors.grey, - padding: const EdgeInsets.all( - 10.0, - ), - shape: const CircleBorder(), - child: const Icon( - Icons.volume_up, - color: MyColors.white, - size: 30.0, - ), - ), - RawMaterialButton( - constraints: const BoxConstraints(), - onPressed: () { - provider.camOff(); - }, - elevation: 2.0, - fillColor: provider.isCamOff ? MyColors.textMixColor : Colors.grey, - padding: const EdgeInsets.all( - 10.0, - ), - shape: const CircleBorder(), - child: Icon( - provider.isCamOff ? Icons.videocam_off : Icons.videocam, - color: MyColors.white, - size: 30.0, - ), - ), - RawMaterialButton( - constraints: const BoxConstraints(), - onPressed: () { - provider.switchCamera(); - }, - elevation: 2.0, - fillColor: provider.isFrontCamera ? Colors.grey : MyColors.textMixColor, - padding: const EdgeInsets.all( - 10.0, - ), - shape: const CircleBorder(), - child: Icon( - provider.isFrontCamera ? Icons.switch_camera_outlined : Icons.switch_camera, - color: MyColors.white, - size: 30.0, - ), - ), - RawMaterialButton( - constraints: const BoxConstraints(), - onPressed: () { - provider.micOff(); - }, - elevation: 2.0, - fillColor: provider.isMicOff ? MyColors.textMixColor : Colors.grey, - padding: const EdgeInsets.all( - 10.0, - ), - shape: const CircleBorder(), - child: Icon( - provider.isMicOff ? Icons.mic_off : Icons.mic, - color: MyColors.white, - size: 30.0, - ), - ), - RawMaterialButton( - constraints: const BoxConstraints(), - onPressed: () { - provider.endCall().then((bool value) { - if (value) { - Navigator.of(context).pop(); - } - }); - }, - elevation: 2.0, - fillColor: MyColors.redA3Color, - padding: const EdgeInsets.all( - 10.0, - ), - shape: const CircleBorder(), - child: const Icon( - Icons.call_end, - color: MyColors.white, - size: 30.0, - ), - ), - ], - ), - ), - ), - ], - ), - ) - : SizedBox( - child: Container( - color: Colors.red, - width: 200, - height: 200, - ), - ); - }, - ), - ); - } -} - -/// if (Platform.isAndroid) { -// SystemNavigator.pop(); -// } else if (Platform.isIOS) { -// exit(0); -// }