|  |  |  | @ -2,9 +2,9 @@ import 'dart:developer'; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | import 'package:connectivity/connectivity.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:flutter/material.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:just_audio/just_audio.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:queuing_system/core/api.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:queuing_system/core/base/app_scaffold_widget.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:queuing_system/core/config/config.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:queuing_system/core/config/size_config.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:queuing_system/core/response_model/patient_call.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:queuing_system/header/app_header.dart'; | 
		
	
	
		
			
				
					|  |  |  | @ -22,7 +22,9 @@ var DEVICE_IP = "10.10.15.11"; // Testing IP | 
		
	
		
			
				|  |  |  |  | // var DEVICE_IP = "10.70.249.21"; // (Make sure by Haroon before use it) Production IP | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | class MyHomePage extends StatefulWidget { | 
		
	
		
			
				|  |  |  |  |   String title = "MyHomePage"; | 
		
	
		
			
				|  |  |  |  |   final String title = "MyHomePage"; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   const MyHomePage({Key key}) : super(key: key); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   @override | 
		
	
		
			
				|  |  |  |  |   State<MyHomePage> createState() => _MyHomePageState(); | 
		
	
	
		
			
				
					|  |  |  | @ -82,30 +84,30 @@ class _MyHomePageState extends State<MyHomePage> { | 
		
	
		
			
				|  |  |  |  |                 ), | 
		
	
		
			
				|  |  |  |  |               ], | 
		
	
		
			
				|  |  |  |  |             ), | 
		
	
		
			
				|  |  |  |  |             Row( | 
		
	
		
			
				|  |  |  |  |               children: [ | 
		
	
		
			
				|  |  |  |  |                 const SizedBox(width: 60), | 
		
	
		
			
				|  |  |  |  |                 SizedBox( | 
		
	
		
			
				|  |  |  |  |                     width: 200, | 
		
	
		
			
				|  |  |  |  |                     child: TextField( | 
		
	
		
			
				|  |  |  |  |                       controller: controller, | 
		
	
		
			
				|  |  |  |  |                     )), | 
		
	
		
			
				|  |  |  |  |                 const SizedBox(width: 30), | 
		
	
		
			
				|  |  |  |  |                 isLoading | 
		
	
		
			
				|  |  |  |  |                     ? const CircularProgressIndicator() | 
		
	
		
			
				|  |  |  |  |                     : ElevatedButton( | 
		
	
		
			
				|  |  |  |  |                         onPressed: onUpdateIPPressed, | 
		
	
		
			
				|  |  |  |  |                         child: const Text( | 
		
	
		
			
				|  |  |  |  |                           "Update IP", | 
		
	
		
			
				|  |  |  |  |                           style: TextStyle(color: Colors.white), | 
		
	
		
			
				|  |  |  |  |                         ), | 
		
	
		
			
				|  |  |  |  |                         style: ElevatedButton.styleFrom(backgroundColor: AppGlobal.appRedColor), | 
		
	
		
			
				|  |  |  |  |                       ), | 
		
	
		
			
				|  |  |  |  |                 const SizedBox(width: 30), | 
		
	
		
			
				|  |  |  |  |                 Text("IP: $DEVICE_IP", style: const TextStyle(fontWeight: FontWeight.w600)), | 
		
	
		
			
				|  |  |  |  |                 const SizedBox(width: 20), | 
		
	
		
			
				|  |  |  |  |               ], | 
		
	
		
			
				|  |  |  |  |             ), | 
		
	
		
			
				|  |  |  |  |             // Row( | 
		
	
		
			
				|  |  |  |  |             //   children: [ | 
		
	
		
			
				|  |  |  |  |             //     const SizedBox(width: 60), | 
		
	
		
			
				|  |  |  |  |             //     SizedBox( | 
		
	
		
			
				|  |  |  |  |             //         width: 200, | 
		
	
		
			
				|  |  |  |  |             //         child: TextField( | 
		
	
		
			
				|  |  |  |  |             //           controller: controller, | 
		
	
		
			
				|  |  |  |  |             //         )), | 
		
	
		
			
				|  |  |  |  |             //     const SizedBox(width: 30), | 
		
	
		
			
				|  |  |  |  |             //     isLoading | 
		
	
		
			
				|  |  |  |  |             //         ? const CircularProgressIndicator() | 
		
	
		
			
				|  |  |  |  |             //         : ElevatedButton( | 
		
	
		
			
				|  |  |  |  |             //             onPressed: onUpdateIPPressed, | 
		
	
		
			
				|  |  |  |  |             //             child: const Text( | 
		
	
		
			
				|  |  |  |  |             //               "Update IP", | 
		
	
		
			
				|  |  |  |  |             //               style: TextStyle(color: Colors.white), | 
		
	
		
			
				|  |  |  |  |             //             ), | 
		
	
		
			
				|  |  |  |  |             //             style: ElevatedButton.styleFrom(backgroundColor: AppGlobal.appRedColor), | 
		
	
		
			
				|  |  |  |  |             //           ), | 
		
	
		
			
				|  |  |  |  |             //     const SizedBox(width: 30), | 
		
	
		
			
				|  |  |  |  |             //     Text("IP: $DEVICE_IP", style: const TextStyle(fontWeight: FontWeight.w600)), | 
		
	
		
			
				|  |  |  |  |             //     const SizedBox(width: 20), | 
		
	
		
			
				|  |  |  |  |             //   ], | 
		
	
		
			
				|  |  |  |  |             // ), | 
		
	
		
			
				|  |  |  |  |           ], | 
		
	
		
			
				|  |  |  |  |         ), | 
		
	
		
			
				|  |  |  |  |       ), | 
		
	
	
		
			
				
					|  |  |  | @ -168,35 +170,64 @@ class _MyHomePageState extends State<MyHomePage> { | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   CallByVoice voiceCaller; | 
		
	
		
			
				|  |  |  |  |   final AudioPlayer audioPlayer = AudioPlayer(); | 
		
	
		
			
				|  |  |  |  |   int callFlag = 0; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   voiceCall() async { | 
		
	
		
			
				|  |  |  |  |     //TODO: After calling this voice call, we should delay for milliseconds that is given by API. After that we will check if there are more patients in isQueuePatients we will remove the patient from waiting list and then update the state | 
		
	
		
			
				|  |  |  |  |     //DONE: After calling this voice call, we should delay for milliseconds that is given by API. After that we will check if there are more patients in isQueuePatients we will remove the patient from waiting list and then update the state | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     if (waitings.isNotEmpty && voiceCaller == null) { | 
		
	
		
			
				|  |  |  |  |       final postVoice = getCallTypeText(waitings.first); | 
		
	
		
			
				|  |  |  |  |       voiceCaller = CallByVoice(waitings.first.callNoStr.toString(), preVoice: "Ticket Number", postVoice: postVoice, lang: 'en'); | 
		
	
		
			
				|  |  |  |  |       await voiceCaller.startCalling(); | 
		
	
		
			
				|  |  |  |  |       voiceCaller = null; | 
		
	
		
			
				|  |  |  |  |     if (waitings.isNotEmpty) { | 
		
	
		
			
				|  |  |  |  |       if (waitings.first.isToneReq) { | 
		
	
		
			
				|  |  |  |  |         audioPlayer.setAsset("assets/tones/call_tone.mp3"); | 
		
	
		
			
				|  |  |  |  |         await audioPlayer.play(); | 
		
	
		
			
				|  |  |  |  |         await Future.delayed(const Duration(seconds: 2)); | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |       if (waitings.first.isVoiceReq && voiceCaller == null) { | 
		
	
		
			
				|  |  |  |  |         final postVoice = getCallTypeText(waitings.first); | 
		
	
		
			
				|  |  |  |  |         voiceCaller = CallByVoice(waitings.first.queueNo.toString(), preVoice: "Ticket Number", postVoice: postVoice, lang: 'en'); | 
		
	
		
			
				|  |  |  |  |         await voiceCaller.startCalling(); | 
		
	
		
			
				|  |  |  |  |         voiceCaller = null; | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |     if (isQueuePatients.isNotEmpty) { | 
		
	
		
			
				|  |  |  |  |       await Future.delayed(Duration(milliseconds: int.parse(isQueuePatients.first.queueDuration) * 10)).whenComplete(() async { | 
		
	
		
			
				|  |  |  |  |         isQueuePatients.removeAt(0); | 
		
	
		
			
				|  |  |  |  |         Tickets ticket = waitings.elementAt(0); | 
		
	
		
			
				|  |  |  |  |         waitings.removeAt(0); | 
		
	
		
			
				|  |  |  |  |         waitings.add(ticket); | 
		
	
		
			
				|  |  |  |  |         if (isQueuePatients.isNotEmpty) { | 
		
	
		
			
				|  |  |  |  |           setState(() {}); | 
		
	
		
			
				|  |  |  |  |           isQueuePatients.removeAt(0); | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |         if (waitings.isNotEmpty) { | 
		
	
		
			
				|  |  |  |  |           Tickets ticket = waitings.elementAt(0); | 
		
	
		
			
				|  |  |  |  |           waitings.removeAt(0); | 
		
	
		
			
				|  |  |  |  |           waitings.add(ticket); | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |         if (isQueuePatients.isEmpty && callFlag == 1) { | 
		
	
		
			
				|  |  |  |  |           callFlag == 0; | 
		
	
		
			
				|  |  |  |  |           await Future.delayed(const Duration(seconds: 3)); | 
		
	
		
			
				|  |  |  |  |         if (isQueuePatients.isNotEmpty) { | 
		
	
		
			
				|  |  |  |  |           setState(() {}); | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |       }); | 
		
	
		
			
				|  |  |  |  |     } else { | 
		
	
		
			
				|  |  |  |  |       // if (isQueuePatients.isEmpty && callFlag == 1) { | 
		
	
		
			
				|  |  |  |  |       //   callFlag == 0; | 
		
	
		
			
				|  |  |  |  |       //   await Future.delayed(const Duration(seconds: 3)); | 
		
	
		
			
				|  |  |  |  |       //   waitings.clear(); | 
		
	
		
			
				|  |  |  |  |       //   API.getCallRequestInfoByClinicInfo(DEVICE_IP, onSuccess: (waitingCalls, isQueuePatientsCalls) { | 
		
	
		
			
				|  |  |  |  |       //     setState(() { | 
		
	
		
			
				|  |  |  |  |       //       waitings = waitingCalls; | 
		
	
		
			
				|  |  |  |  |       //       isQueuePatients = isQueuePatientsCalls; | 
		
	
		
			
				|  |  |  |  |       //       // currents = currentInClinic; | 
		
	
		
			
				|  |  |  |  |       //     }); | 
		
	
		
			
				|  |  |  |  |       // | 
		
	
		
			
				|  |  |  |  |       //     log("--------------------"); | 
		
	
		
			
				|  |  |  |  |       //     log("waiting: $waitings"); | 
		
	
		
			
				|  |  |  |  |       //     log("isQueuePatients: $isQueuePatients"); | 
		
	
		
			
				|  |  |  |  |       //     log("--------------------"); | 
		
	
		
			
				|  |  |  |  |       // | 
		
	
		
			
				|  |  |  |  |       //     updateTickets(); | 
		
	
		
			
				|  |  |  |  |       //   }, onFailure: (error) {}); | 
		
	
		
			
				|  |  |  |  |       // } | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   onUpdateAvailable(data) async { | 
		
	
		
			
				|  |  |  |  |     print("here is the data: $data"); | 
		
	
		
			
				|  |  |  |  |     if (isQueuePatients.isNotEmpty && callFlag == 0) { | 
		
	
		
			
				|  |  |  |  |       callFlag = 1; | 
		
	
		
			
				|  |  |  |  |       return; | 
		
	
	
		
			
				
					|  |  |  | 
 |