import 'dart:ui'; import 'package:camera/camera.dart'; import 'package:diplomaticquarterapp/models/LiveCare/IncomingCallData.dart'; import 'package:diplomaticquarterapp/models/LiveCare/room_model.dart'; import 'package:diplomaticquarterapp/pages/conference/web_rtc/call_home_page.dart'; import 'package:diplomaticquarterapp/pages/conference/web_rtc/call_home_page_.dart'; import 'package:diplomaticquarterapp/pages/conference/widgets/platform_exception_alert_dialog.dart'; import 'package:diplomaticquarterapp/pages/landing/landing_page.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/uitl/utils_new.dart'; import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; import 'package:flutter/material.dart'; import 'package:just_audio/just_audio.dart'; class IncomingCall extends StatefulWidget { IncomingCallData incomingCallData; IncomingCall({@required this.incomingCallData}); @override _IncomingCallState createState() => _IncomingCallState(); } class _IncomingCallState extends State with SingleTickerProviderStateMixin { AnimationController _animationController; final player = AudioPlayer(); CameraController _controller; Future _initializeControllerFuture; bool isCameraReady = false; @override void initState() { _animationController = AnimationController(vsync: this, duration: Duration(milliseconds: 500)); isCameraReady = false; WidgetsBinding.instance.addPostFrameCallback((_) => _runAnimation()); print(widget.incomingCallData.doctorname); print(widget.incomingCallData.clinicname); print(widget.incomingCallData.speciality); super.initState(); } @override void dispose() { _animationController.dispose(); player.stop(); _controller.dispose(); disposeAudioResources(); super.dispose(); } @override Widget build(BuildContext context) { return AppScaffold( isShowAppBar: false, isShowDecPage: false, body: FutureBuilder( future: _initializeControllerFuture, builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.done) { return Stack( alignment: FractionalOffset.center, children: [ new Positioned.fill( child: new AspectRatio(aspectRatio: _controller.value.aspectRatio, child: new CameraPreview(_controller)), ), new Positioned.fill( child: new ClipRect( child: new BackdropFilter( filter: new ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0), child: new Container( decoration: new BoxDecoration(color: Colors.grey[800].withOpacity(0.8)), child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.max, children: [ Container( margin: const EdgeInsets.all(21.0), child: Row( children: [ Image.asset( "assets/images/new/logo.png", height: 70, width: 70, ), Container( margin: const EdgeInsets.only(left: 10.0, right: 10.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Text( widget.incomingCallData.doctorname, style: TextStyle(fontSize: 21, fontWeight: FontWeight.bold, color: Colors.white, letterSpacing: -1.26, height: 23 / 12), ), Text( TranslationBase.of(context).videoAppo, style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: Color(0xffC6C6C6), letterSpacing: -0.48, height: 23 / 24), ), SizedBox(height: 2), ], ), ), ], ), ), Container( margin: const EdgeInsets.all(21.0), width: MediaQuery.of(context).size.width, decoration: cardRadius(15.0, color: Colors.black), 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: Colors.white, letterSpacing: -0.64, height: 23 / 12), ), ), Container( padding: const EdgeInsets.only(left: 16.0, right: 16.0), child: Text( widget.incomingCallData.appointmentdate + ", " + widget.incomingCallData.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.incomingCallData.clinicname, style: TextStyle(fontSize: 12.0, letterSpacing: -0.48, color: Color(0xff8E8E8E), fontWeight: FontWeight.w600), ), ), ], ), ), Spacer(), Container( margin: EdgeInsets.only(bottom: 70.0, left: 49, right: 49), child: Row( mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ RotationTransition( turns: Tween(begin: 0.0, end: -.1).chain(CurveTween(curve: Curves.elasticIn)).animate(_animationController), child: Container( child: RawMaterialButton( onPressed: () { _submit(); }, elevation: 2.0, fillColor: Colors.green, child: Icon( Icons.call, color: Colors.white, size: 35.0, ), padding: EdgeInsets.all(15.0), shape: CircleBorder(), ), )), Container( child: RawMaterialButton( onPressed: () { backToHome(); }, elevation: 2.0, fillColor: Colors.red, child: Icon( Icons.call_end, color: Colors.white, size: 35.0, ), padding: EdgeInsets.all(15.0), shape: CircleBorder(), ), ), ], ), ), ], ), ), ), ), ), ], ); } else { return const Center(child: CircularProgressIndicator()); } }, ), // body: isCameraReady // ? // : Container( // height: 200.0, // width: 200.0, // color: Colors.green, // ), // body: Container( // decoration: BoxDecoration(color: Colors.grey[700]), // child: Column( // mainAxisAlignment: MainAxisAlignment.start, // mainAxisSize: MainAxisSize.max, // children: [ // Container( // margin: EdgeInsets.only(top: 30.0), // alignment: Alignment.center, // child: Text("Incoming Video Call", textAlign: TextAlign.center, style: TextStyle(fontSize: 26.0, color: Colors.white, letterSpacing: 1.0)), // ), // Container( // alignment: Alignment.center, // margin: EdgeInsets.fromLTRB(50.0, 30.0, 50.0, 20.0), // child: Image.asset('assets/images/new-design/hmg_full_logo_hd_white.png'), // ), // Container( // margin: EdgeInsets.fromLTRB(30.0, 10.0, 30.0, 0.0), // child: Divider( // color: Colors.white, // thickness: 1.0, // ), // ), // Container( // margin: EdgeInsets.only(top: 20.0), // alignment: Alignment.center, // child: Text("Dr Eyad Ismail Abu Jayab", textAlign: TextAlign.center, style: TextStyle(fontSize: 22.0, fontWeight: FontWeight.bold, letterSpacing: 0.8, color: Colors.white)), // ), // Container( // margin: EdgeInsets.only(top: 10.0), // alignment: Alignment.center, // child: Text("ENT Clinic", textAlign: TextAlign.center, style: TextStyle(fontSize: 22.0, letterSpacing: 0.8, color: Colors.white)), // ), // Container( // margin: EdgeInsets.only(top: 10.0), // alignment: Alignment.center, // child: Text("Speciality", textAlign: TextAlign.center, style: TextStyle(fontSize: 22.0, letterSpacing: 0.8, color: Colors.white)), // ), // Container( // decoration: BoxDecoration( // color: Colors.grey[900].withOpacity(0.8), // borderRadius: BorderRadius.all(Radius.circular(10.0)), // ), // padding: EdgeInsets.all(20.0), // margin: EdgeInsets.only(top: 20.0), // child: Column( // children: [ // Text("Appointment Information", textAlign: TextAlign.center, style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold, letterSpacing: 1.0, color: Colors.white)), // Container( // margin: EdgeInsets.only(top: 20.0), // child: Text("Sun, 15th Dec, 2019, 09:00", textAlign: TextAlign.center, style: TextStyle(fontSize: 20.0, letterSpacing: 1.0, color: Colors.white)), // ), // Container( // margin: EdgeInsets.only(top: 20.0), // child: Text("ENT Clinic", textAlign: TextAlign.center, style: TextStyle(fontSize: 20.0, letterSpacing: 1.0, color: Colors.white)), // ), // ], // ), // ), // Container( // margin: EdgeInsets.only(top: 100.0), // alignment: Alignment.center, // child: Row( // mainAxisSize: MainAxisSize.max, // mainAxisAlignment: MainAxisAlignment.spaceEvenly, // children: [ // RotationTransition( // turns: Tween(begin: 0.0, end: -.1).chain(CurveTween(curve: Curves.elasticIn)).animate(_animationController), // child: Container( // child: RawMaterialButton( // onPressed: () { // _submit(); // }, // elevation: 2.0, // fillColor: Colors.green, // child: Icon( // Icons.call, // color: Colors.white, // size: 35.0, // ), // padding: EdgeInsets.all(15.0), // shape: CircleBorder(), // ), // )), // Container( // child: RawMaterialButton( // onPressed: () { // LandingPage.isOpenCallPage = false; // backToHome(); // }, // elevation: 2.0, // fillColor: Colors.red, // child: Icon( // Icons.call_end, // color: Colors.white, // size: 35.0, // ), // padding: EdgeInsets.all(15.0), // shape: CircleBorder(), // ), // ), // ], // ), // ), // ], // )), ); } void _runAnimation() async { final cameras = await availableCameras(); final firstCamera = cameras[1]; _controller = CameraController( // Get a specific camera from the list of available cameras. firstCamera, // Define the resolution to use. ResolutionPreset.medium, ); _initializeControllerFuture = _controller.initialize(); setState(() { isCameraReady = true; }); setAudioFile(); for (int i = 0; i < 100; i++) { await _animationController.forward(); await _animationController.reverse(); } } Future _submit() async { // backToHome(); try { final roomModel = RoomModel(name: widget.incomingCallData.name, token: widget.incomingCallData.sessionId, identity: widget.incomingCallData.identity); // await Navigator.of(context).push( // MaterialPageRoute( // fullscreenDialog: true, // builder: (BuildContext context) => // ConferencePage(roomModel: roomModel), // ), // ); await _controller.dispose(); await Navigator.of(context).pushReplacement( MaterialPageRoute( fullscreenDialog: true, builder: (BuildContext context) => CallHomePage(receiverId: widget.incomingCallData.receiverID, callerId: widget.incomingCallData.callerID), ), ); } catch (err) { print(err); await PlatformExceptionAlertDialog( exception: err, ).show(context); } } void backToHome() { LandingPage.isOpenCallPage = false; player.stop(); // disposeAudioResources(); Navigator.of(context).pop(); } disposeAudioResources() async { await player.dispose(); } void setAudioFile() async { player.stop(); await player.setVolume(1.0); // full volume try { await player.setAsset('assets/sounds/ring_60Sec.mp3').then((value) { player.setLoopMode(LoopMode.one); // loop ring sound player.play(); }).catchError((err) { print("Error: $err"); }); } catch (e) { print("Error: $e"); } } }