import 'dart:async'; import 'package:doctor_app_flutter/models/livecare/session_status_model.dart'; import 'package:doctor_app_flutter/providers/livecare_provider.dart'; import 'package:doctor_app_flutter/util/VideoChannel.dart'; import 'package:doctor_app_flutter/util/dr_app_shared_pref.dart'; import 'package:flutter/material.dart'; import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; import 'package:provider/provider.dart'; import 'package:doctor_app_flutter/util/dr_app_toast_msg.dart'; import 'package:doctor_app_flutter/util/helpers.dart'; class VideoCallPage extends StatefulWidget { @override _VideoCallPageState createState() => _VideoCallPageState(); } DrAppSharedPreferances sharedPref = DrAppSharedPreferances(); class _VideoCallPageState extends State { Timer _timmerInstance; int _start = 0; String _timmer = ''; LiveCareProvider _liveCareProvider; bool _isInit = true; var _tokenData; var patientData = {}; String image_url = 'https://hmgwebservices.com/Images/MobileImages/DUBAI/'; //bool _isOutOfStuck = false; Helpers helpers = new Helpers(); @override void didChangeDependencies() { super.didChangeDependencies(); if (_isInit) { _liveCareProvider = Provider.of(context); startCall(); } _isInit = false; } void connectOpenTok(tokenData) async { _tokenData = tokenData; /* opentok functionalites need to be written */ await VideoChannel.openVideoCallScreen( kToken: 'T1==cGFydG5lcl9pZD00NjgwMzIyNCZzaWc9NWRhNmExMzU4ZDViZGU3OTA5NDY4ODRhNzI4ZGUxZTRmMjZmNzcwMjpzZXNzaW9uX2lkPTFfTVg0ME5qZ3dNekl5Tkg1LU1UVTVNelk0TXpZek9EWXdNMzV1Y0V4V1lWUlZTbTVIY3k5dVdHWm1NMWxPYTNjelpIVi1mZyZjcmVhdGVfdGltZT0xNTkzNjgzNjYyJm5vbmNlPTAuODAxMzMzMzUxMDQwNzE5NSZyb2xlPXB1Ymxpc2hlciZleHBpcmVfdGltZT0xNTk2Mjc1NjYyJmluaXRpYWxfbGF5b3V0X2NsYXNzX2xpc3Q9', kSessionId: '1_MX40NjgwMzIyNH5-MTU5MzY4MzYzODYwM35ucExWYVRVSm5Hcy9uWGZmM1lOa3czZHV-fg', kApiKey: '46803224', vcId: 3245, tokenID: "hfkjshdf347r8743", generalId: "Cs2020@2016\$2958", doctorId: 1485, onFailure: (String error) { //TODO handling Failure }, onCallEnd: () { //TODO handling onCallEnd }, onCallNotRespond: (SessionStatusModel sessionStatusModel) { //TODO handling onCalcallNotRespondlEnd }); } String getTimerTime(int start) { int minutes = (start ~/ 60); String sMinute = ''; if (minutes.toString().length == 1) { sMinute = '0' + minutes.toString(); } else sMinute = minutes.toString(); int seconds = (start % 60); String sSeconds = ''; if (seconds.toString().length == 1) { sSeconds = '0' + seconds.toString(); } else sSeconds = seconds.toString(); return sMinute + ':' + sSeconds; } startCall() async { patientData = await sharedPref.getObj(LIVE_CARE_PATIENT); _liveCareProvider.startCall(patientData, false).then((result) { connectOpenTok(result); }).catchError((error) => {helpers.showErrorToast(error), Navigator.of(context).pop()}); } @override void dispose() { super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( body: SafeArea( child: Container( height: MediaQuery.of(context).size.height, width: MediaQuery.of(context).size.width, decoration: BoxDecoration( color: Colors.white, ), padding: EdgeInsets.all(50.0), child: Column( mainAxisAlignment: MainAxisAlignment.start, mainAxisSize: MainAxisSize.max, crossAxisAlignment: CrossAxisAlignment.center, children: [ SizedBox( height: 10.0, ), Text( 'Dailing...', style: TextStyle( color: Colors.deepPurpleAccent, fontWeight: FontWeight.w300, fontSize: 15), ), SizedBox( height: MediaQuery.of(context).size.height * 0.02, ), Text( patientData["PatientName"], style: TextStyle( color: Colors.deepPurpleAccent, fontWeight: FontWeight.w900, fontSize: 20), ), SizedBox( height: MediaQuery.of(context).size.height * 0.02, ), Container( child: Text( _timmer == '' ? 'Connecting' : 'Connected', style: TextStyle( color: Colors.deepPurpleAccent, fontWeight: FontWeight.w300, fontSize: 15), )), SizedBox( height: MediaQuery.of(context).size.height * 0.02, ), ClipRRect( borderRadius: BorderRadius.circular(200.0), child: Image.network( patientData["Gender"] == "1" ? image_url + 'unkown.png' : image_url + 'unkowwn_female.png', height: 200.0, width: 200.0, ), ), SizedBox( height: MediaQuery.of(context).size.height * .2, ), Container( width: 70.0, height: 70.0, child: FloatingActionButton( onPressed: () { Navigator.of(context).pop(); }, elevation: 30.0, shape: CircleBorder(side: BorderSide(color: Colors.red)), mini: false, child: Icon( Icons.call_end, color: Colors.red, size: 35, ), backgroundColor: Colors.red[100], )) ], ), ), ), ); } } class FunctionalButton extends StatefulWidget { final title; final icon; final Function() onPressed; const FunctionalButton({Key key, this.title, this.icon, this.onPressed}) : super(key: key); @override _FunctionalButtonState createState() => _FunctionalButtonState(); } class _FunctionalButtonState extends State { @override Widget build(BuildContext context) { return Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.center, mainAxisSize: MainAxisSize.min, children: [ RawMaterialButton( onPressed: widget.onPressed, splashColor: Colors.deepPurpleAccent, fillColor: Colors.white, elevation: 10.0, shape: CircleBorder(), child: Padding( padding: const EdgeInsets.all(15.0), child: Icon( widget.icon, size: 30.0, color: Colors.deepPurpleAccent, ), ), ), Container( margin: EdgeInsets.symmetric(vertical: 10.0, horizontal: 2.0), child: Text( widget.title, style: TextStyle(fontSize: 15.0, color: Colors.deepPurpleAccent), ), ) ], ); } }