|
|
|
|
import 'dart:developer';
|
|
|
|
|
|
|
|
|
|
import 'package:connectivity/connectivity.dart';
|
|
|
|
|
import 'package:flutter/material.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';
|
|
|
|
|
import 'package:queuing_system/home/home_screen_components.dart';
|
|
|
|
|
import 'package:queuing_system/utils/call_by_voice.dart';
|
|
|
|
|
import 'package:queuing_system/utils/call_type.dart';
|
|
|
|
|
import 'package:queuing_system/utils/signalR_utils.dart';
|
|
|
|
|
import 'package:queuing_system/utils/utils.dart';
|
|
|
|
|
import 'package:queuing_system/widget/data_display/app_texts_widget.dart';
|
|
|
|
|
import 'package:text_to_speech/text_to_speech.dart';
|
|
|
|
|
|
|
|
|
|
var DEVICE_IP = "10.10.15.11"; // Testing IP
|
|
|
|
|
// var DEVICE_IP = "10.10.14.11"; // Testing IP
|
|
|
|
|
// var DEVICE_IP = "10.10.15.11";
|
|
|
|
|
|
|
|
|
|
// var DEVICE_IP = "10.70.249.21"; // (Make sure by Haroon before use it) Production IP
|
|
|
|
|
|
|
|
|
|
class MyHomePage extends StatefulWidget {
|
|
|
|
|
String title = "MyHomePage";
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<MyHomePage> createState() => _MyHomePageState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _MyHomePageState extends State<MyHomePage> {
|
|
|
|
|
SignalRHelper signalRHelper = SignalRHelper();
|
|
|
|
|
|
|
|
|
|
List<Tickets> waitings = [];
|
|
|
|
|
List<Tickets> currents = [];
|
|
|
|
|
|
|
|
|
|
bool isLoading = false;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
listenNetworkConnectivity();
|
|
|
|
|
|
|
|
|
|
if (!signalRHelper.getConnectionState()) {
|
|
|
|
|
signalRHelper.startSignalRConnection(DEVICE_IP, onUpdateAvailable: onUpdateAvailable, onConnect: onConnect, onConnecting: onConnecting, onDisconnect: onDisconnect);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
super.initState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TextEditingController controller = TextEditingController();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return AppScaffold(
|
|
|
|
|
appBar: AppHeader(),
|
|
|
|
|
body: content(),
|
|
|
|
|
bottomNavigationBar: Container(
|
|
|
|
|
color: Colors.grey.withOpacity(0.1),
|
|
|
|
|
height: Utils.getHeight(),
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
child: Row(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
children: [
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
const SizedBox(width: 20),
|
|
|
|
|
AppText(
|
|
|
|
|
"Powered By",
|
|
|
|
|
fontSize: SizeConfig.getWidthMultiplier() * 2.6,
|
|
|
|
|
fontFamily: 'Poppins-Medium.ttf',
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 20),
|
|
|
|
|
Image.asset(
|
|
|
|
|
"assets/images/cloud_logo.png",
|
|
|
|
|
height: SizeConfig.getHeightMultiplier() * 4,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
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),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onUpdateIPPressed() async {
|
|
|
|
|
if (controller.text.isNotEmpty) {
|
|
|
|
|
isLoading = true;
|
|
|
|
|
setState(() {});
|
|
|
|
|
DEVICE_IP = controller.text;
|
|
|
|
|
|
|
|
|
|
await signalRHelper.connection.stop();
|
|
|
|
|
if (!signalRHelper.getConnectionState()) {
|
|
|
|
|
await signalRHelper.startSignalRConnection(DEVICE_IP, onUpdateAvailable: onUpdateAvailable, onConnect: onConnect, onConnecting: onConnecting, onDisconnect: onDisconnect);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
controller.clear();
|
|
|
|
|
waitings.clear();
|
|
|
|
|
isLoading = false;
|
|
|
|
|
setState(() {});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget content() {
|
|
|
|
|
// waitings = waitings.sublist(0,3);
|
|
|
|
|
voiceCall();
|
|
|
|
|
|
|
|
|
|
if (waitings.isEmpty) {
|
|
|
|
|
// No Patient in Queue
|
|
|
|
|
return noPatientInQueue();
|
|
|
|
|
} else if (waitings.length > 4) {
|
|
|
|
|
// Return Content With Side List
|
|
|
|
|
return priorityTicketsWithSideList(waitings);
|
|
|
|
|
} else {
|
|
|
|
|
// Return Content In Center Aligned
|
|
|
|
|
return priorityTickets(waitings);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CallByVoice voiceCaller;
|
|
|
|
|
|
|
|
|
|
voiceCall() async {
|
|
|
|
|
if (waitings.isNotEmpty && voiceCaller == null) {
|
|
|
|
|
final postVoice = waitings.first.getCallType().audio('en');
|
|
|
|
|
voiceCaller = CallByVoice(waitings.first.callNoStr.toString(), preVoice: 'ticket_number.mp3', postVoice: postVoice, lang: 'en');
|
|
|
|
|
await voiceCaller.start();
|
|
|
|
|
voiceCaller = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printWaiting() {
|
|
|
|
|
for (var value in waitings) {
|
|
|
|
|
print("waiting: ${value.callNoStr}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onUpdateAvailable(data) async {
|
|
|
|
|
waitings.clear();
|
|
|
|
|
API.GetCallRequestInfoByClinincInfo(DEVICE_IP, onSuccess: (waitingCalls) {
|
|
|
|
|
setState(() {
|
|
|
|
|
waitings = waitingCalls;
|
|
|
|
|
// currents = currentInClinic;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
log("\n\n");
|
|
|
|
|
log("--------------------");
|
|
|
|
|
// log("Current: $currentInClinic");
|
|
|
|
|
// log("Waiting: $waitingCalls");
|
|
|
|
|
printWaiting();
|
|
|
|
|
log("--------------------");
|
|
|
|
|
log("\n\n");
|
|
|
|
|
|
|
|
|
|
updateTickets();
|
|
|
|
|
}, onFailure: (error) {});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateTickets() {
|
|
|
|
|
// List<Tickets> _ticketsToUpdate = waitings.where((t) => t.call_updated == false).toList();
|
|
|
|
|
// API.Call_UpdateNotIsQueueRecordByIDAsync(DEVICE_IP, ticket: _ticketsToUpdate.first, onSuccess: (tickets_updated) {
|
|
|
|
|
// print("[${tickets_updated.length}] Tickets Updated: $tickets_updated");
|
|
|
|
|
// }, onFailure: (e) {
|
|
|
|
|
// print("API UPDate Tickets Failed with : ${e.toString()}");
|
|
|
|
|
// });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onConnect() {
|
|
|
|
|
log("SignalR: onConnect");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onDisconnect(exception) {
|
|
|
|
|
log("SignalR: onDisconnect");
|
|
|
|
|
// signalRHelper.startSignalRConnection(DEVICE_IP, onUpdateAvailable: onUpdateAvailable, onConnect: onConnect, onConnecting: onConnecting, onDisconnect: onDisconnect);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onConnecting() {
|
|
|
|
|
log("SignalR: onConnecting");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
listenNetworkConnectivity() async {
|
|
|
|
|
Connectivity().onConnectivityChanged.listen((event) {
|
|
|
|
|
switch (event) {
|
|
|
|
|
case ConnectivityResult.wifi:
|
|
|
|
|
signalRHelper.connection.start();
|
|
|
|
|
break;
|
|
|
|
|
case ConnectivityResult.none:
|
|
|
|
|
signalRHelper.closeConnection(context);
|
|
|
|
|
break;
|
|
|
|
|
case ConnectivityResult.mobile:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|