Pushing till working demo

dev_faiz
Faiz Hashmi 3 years ago
parent c73daeb8e8
commit c9f978f0eb

@ -1,3 +1,5 @@
import 'dart:developer';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:queuing_system/core/base/base_app_client.dart'; import 'package:queuing_system/core/base/base_app_client.dart';
import 'package:queuing_system/core/response_model/patient_call.dart'; import 'package:queuing_system/core/response_model/patient_call.dart';
@ -6,25 +8,22 @@ const _getCallRequestInfoByClinicInfo = "/GetCallRequestInfoByClinincInfo";
const _call_UpdateNotIsQueueRecordByIDAsync = "/Call_UpdateNotIsQueueRecordByID"; const _call_UpdateNotIsQueueRecordByIDAsync = "/Call_UpdateNotIsQueueRecordByID";
class API { class API {
static GetCallRequestInfoByClinincInfo(String deviceIp, {@required Function(List<Tickets>) onSuccess, @required Function(dynamic) onFailure}) async { static getCallRequestInfoByClinicInfo(String deviceIp, {@required Function(List<Tickets>) onSuccess, @required Function(dynamic) onFailure}) async {
final body = {"IPAdress": deviceIp}; final body = {"IPAdress": deviceIp};
BaseAppClient.post(_getCallRequestInfoByClinicInfo, BaseAppClient.post(_getCallRequestInfoByClinicInfo,
body: body, body: body,
onSuccess: (response, status) { onSuccess: (response, status) {
if (status == 200) { if (status == 200) {
var calledByNurse = (response["CalledByNurse"] as List).map((j) => Tickets.fromJson(j)).toList(); var calledByNurse = (response["CalledByNurse"] as List).map((j) => Tickets.fromJson(j)).toList();
print("calledByNurse Length: ${calledByNurse.length}"); log("calledByNurse Length: ${calledByNurse.length}");
final patients = (response["ClinicCurrentPatient"] as List).map((j) => Tickets.fromJson(j)).toList(); final patients = (response["ClinicCurrentPatient"] as List).map((j) => Tickets.fromJson(j)).toList();
print("patients Length: ${patients.length}"); log("patients Length: ${patients.length}");
calledByNurse.addAll(patients); calledByNurse.addAll(patients);
// calledByNurse.sort((a, b) => a.callNo.compareTo(b.callNo)); // calledByNurse.sort((a, b) => a.callNo.compareTo(b.callNo));
// final clinicCurrentPatient = (response["ClinicCurrentPatient"] as List).map((j) => Tickets.fromJson(j)).toList();
onSuccess(calledByNurse.reversed.toList()); onSuccess(calledByNurse.reversed.toList());
} else { } else {
onFailure(response); onFailure(response);
@ -33,7 +32,7 @@ class API {
onFailure: (error, status) => onFailure(error)); onFailure: (error, status) => onFailure(error));
} }
static Call_UpdateNotIsQueueRecordByIDAsync(String deviceIp, {@required Tickets ticket, @required Function(List<Tickets>) onSuccess, @required Function(dynamic) onFailure}) async { static callUpdateNotIsQueueRecordByIDAsync(String deviceIp, {@required Tickets ticket, @required Function(List<Tickets>) onSuccess, @required Function(dynamic) onFailure}) async {
if (ticket.id == null) { if (ticket.id == null) {
return; return;
} }
@ -46,7 +45,7 @@ class API {
body: body, body: body,
onSuccess: (response, status) { onSuccess: (response, status) {
if (status == 200) { if (status == 200) {
ticket.call_updated = true; ticket.callUpdated = true;
_ticketsUpdated.add(ticket); _ticketsUpdated.add(ticket);
} }
}, },

@ -1,3 +1,5 @@
import 'dart:math';
import 'package:queuing_system/utils/call_type.dart'; import 'package:queuing_system/utils/call_type.dart';
class Tickets { class Tickets {
@ -16,15 +18,11 @@ class Tickets {
this.queueNo, this.queueNo,
}); });
String getParsedDateTime(String date) { int getRandomNum() {
print("gotDate: $date"); return Random().nextInt(1);
DateTime dateTime = DateTime.parse(date);
} }
Tickets.fromJson(dynamic json) { Tickets.fromJson(dynamic json) {
print("here json: $json");
id = json['ID']; id = json['ID'];
callNo = json['CallNo']; callNo = json['CallNo'];
roomNo = json['RoomNo']; roomNo = json['RoomNo'];
@ -38,6 +36,7 @@ class Tickets {
patientID = json['PatientID']; patientID = json['PatientID'];
queueNo = json['QueueNo']; queueNo = json['QueueNo'];
callNoStr = json['CallNoStr'] ?? json['CallNo'].toString(); callNoStr = json['CallNoStr'] ?? json['CallNo'].toString();
isAcknowledged = getRandomNum();
} }
int id; int id;
@ -53,7 +52,8 @@ class Tickets {
int patientID; int patientID;
String queueNo; String queueNo;
String callNoStr; String callNoStr;
bool call_updated = false; bool callUpdated = false;
int isAcknowledged;
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final map = <String, dynamic>{}; final map = <String, dynamic>{};
@ -75,7 +75,7 @@ class Tickets {
@override @override
String toString() { String toString() {
return (callNo).toString(); return (callNoStr).toString();
} }
CallType getCallType() { CallType getCallType() {

@ -14,7 +14,6 @@ import 'package:queuing_system/utils/call_type.dart';
import 'package:queuing_system/utils/signalR_utils.dart'; import 'package:queuing_system/utils/signalR_utils.dart';
import 'package:queuing_system/utils/utils.dart'; import 'package:queuing_system/utils/utils.dart';
import 'package:queuing_system/widget/data_display/app_texts_widget.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.15.11"; // Testing IP
// var DEVICE_IP = "10.10.14.11"; // Testing IP // var DEVICE_IP = "10.10.14.11"; // Testing IP
@ -55,7 +54,6 @@ class _MyHomePageState extends State<MyHomePage> {
TextEditingController controller = TextEditingController(); TextEditingController controller = TextEditingController();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return AppScaffold( return AppScaffold(
@ -148,26 +146,58 @@ class _MyHomePageState extends State<MyHomePage> {
} }
} }
String getCallTypeText(Tickets ticket) {
final callType = ticket.getCallType();
switch (callType) {
case CallType.RECEPTION:
return "Please Visit Doctor";
break;
case CallType.NURSE:
return "Please Visit Nurse";
break;
case CallType.DOCTOR:
return "Please Visit Doctor";
break;
case CallType.NONE:
return "";
break;
default:
return "";
}
}
CallByVoice voiceCaller; CallByVoice voiceCaller;
voiceCall() async { voiceCall() async {
var j = {
"ID": 4182,
"PatientID": 123123,
"MobileNo": "05***6794",
"DoctorName": "Shakiera",
"DoctorNameN": "Shakeria",
"PatientGender": 1,
"CallNo": 123,
"callType": 1,
"RoomNo": "10",
"CreatedOn": "/Date(1673771382130+0300)/",
"EditedOn": "/Date(1673771384500+0300)/",
"CallNoStr": "A-5",
"QueueNo": null
};
waitings = [Tickets.fromJson(j)];
if (waitings.isNotEmpty && voiceCaller == null) { if (waitings.isNotEmpty && voiceCaller == null) {
final postVoice = waitings.first.getCallType().audio('en'); final postVoice = getCallTypeText(waitings.first);
voiceCaller = CallByVoice(waitings.first.callNoStr.toString(), preVoice: 'ticket_number.mp3', postVoice: postVoice, lang: 'en'); voiceCaller = CallByVoice(waitings.first.callNoStr.toString(), preVoice: "Ticket Number", postVoice: postVoice, lang: 'en');
await voiceCaller.start(); await voiceCaller.startCalling();
voiceCaller = null; voiceCaller = null;
} }
} }
printWaiting() {
for (var value in waitings) {
print("waiting: ${value.callNoStr}");
}
}
onUpdateAvailable(data) async { onUpdateAvailable(data) async {
waitings.clear(); waitings.clear();
API.GetCallRequestInfoByClinincInfo(DEVICE_IP, onSuccess: (waitingCalls) { API.getCallRequestInfoByClinicInfo(DEVICE_IP, onSuccess: (waitingCalls) {
setState(() { setState(() {
waitings = waitingCalls; waitings = waitingCalls;
// currents = currentInClinic; // currents = currentInClinic;
@ -175,9 +205,7 @@ class _MyHomePageState extends State<MyHomePage> {
log("\n\n"); log("\n\n");
log("--------------------"); log("--------------------");
// log("Current: $currentInClinic"); log("waiting: $waitings");
// log("Waiting: $waitingCalls");
printWaiting();
log("--------------------"); log("--------------------");
log("\n\n"); log("\n\n");
@ -186,12 +214,14 @@ class _MyHomePageState extends State<MyHomePage> {
} }
updateTickets() { updateTickets() {
// List<Tickets> _ticketsToUpdate = waitings.where((t) => t.call_updated == false).toList(); if (waitings != null && waitings.isNotEmpty) {
// API.Call_UpdateNotIsQueueRecordByIDAsync(DEVICE_IP, ticket: _ticketsToUpdate.first, onSuccess: (tickets_updated) { List<Tickets> _ticketsToUpdate = waitings.where((t) => t.callUpdated == false).toList();
// print("[${tickets_updated.length}] Tickets Updated: $tickets_updated"); API.callUpdateNotIsQueueRecordByIDAsync(DEVICE_IP, ticket: _ticketsToUpdate.first, onSuccess: (tickets_updated) {
// }, onFailure: (e) { log("[${tickets_updated.length}] Tickets Updated: $tickets_updated");
// print("API UPDate Tickets Failed with : ${e.toString()}"); }, onFailure: (e) {
// }); log("API UPDate Tickets Failed with : ${e.toString()}");
});
}
} }
onConnect() { onConnect() {

@ -1,5 +1,7 @@
import 'dart:developer';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:just_audio/just_audio.dart'; import 'package:flutter_tts/flutter_tts.dart';
class CallByVoice { class CallByVoice {
final String lang; final String lang;
@ -9,42 +11,50 @@ class CallByVoice {
CallByVoice(this.ticketNo, {this.lang = 'en', @required this.preVoice, @required this.postVoice}); CallByVoice(this.ticketNo, {this.lang = 'en', @required this.preVoice, @required this.postVoice});
final _player = AudioPlayer(); final FlutterTts textToSpeech = FlutterTts();
double volume = 1.0;
double pitch = 0.9;
double rate = 0.5;
Future<dynamic> _getLanguages() async => await textToSpeech.getLanguages;
start() async { startCalling() async {
log("languages: ${await _getLanguages()}");
log("no: $ticketNo");
textToSpeech.setLanguage("en-US");
var splitText = ticketNo.split("-");
// Create Pre Voice Players // Create Pre Voice Players
if (preVoice != null && preVoice.isNotEmpty) { if (preVoice != null && preVoice.isNotEmpty) {
await _player.setAsset('assets/voice_$lang/$preVoice'); textToSpeech.setSpeechRate(rate);
await _player.play(); textToSpeech.setPitch(pitch);
textToSpeech.setVolume(volume);
await textToSpeech.speak(preVoice + " .. " + splitText[0] + " .. " + splitText[1] + " .. " + postVoice);
} }
// Create Ticket Number Voice Players // // Create Ticket Number Voice Players
final characters = ticketNo.characters.toList(); // final characters = ticketNo.characters.toList();
for (int i = 0; i < characters.length; i++) { // for (int i = 0; i < characters.length; i++) {
final no = characters[i]; // final no = characters[i];
if (no.isNotEmpty && no != "-" && no != "_" && no != " ") { // if (no.isNotEmpty && no != "-" && no != "_" && no != " ") {
await Future.delayed(const Duration(milliseconds: 200)); //
// await _player.stop();
await _player.stop(); // await _player.setAsset('assets/voice_$lang/${no.toUpperCase()}.mp3');
await _player.setAsset('assets/voice_$lang/${no.toUpperCase()}.mp3'); // await _player.play();
await _player.play(); // }
} // }
}
// Create Post Voice Players // Create Post Voice Players
if (postVoice != null && postVoice.isNotEmpty) { // if (postVoice != null && postVoice.isNotEmpty) {
await Future.delayed(const Duration(milliseconds: 1000)); // await Future.delayed(const Duration(milliseconds: 1000));
//
await _player.stop(); // await _player.stop();
await _player.setAsset('assets/voice_$lang/$postVoice'); // await _player.setAsset('assets/voice_$lang/$postVoice');
await _player.play(); // await _player.play();
} // }
_player.dispose();
}
stop() async {
await _player.stop();
} }
// stop() async {
// await _player.stop();
// }
} }

@ -7,14 +7,14 @@ import Foundation
import audio_session import audio_session
import connectivity_macos import connectivity_macos
import flutter_tts
import just_audio import just_audio
import path_provider_macos import path_provider_macos
import text_to_speech_macos
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
AudioSessionPlugin.register(with: registry.registrar(forPlugin: "AudioSessionPlugin")) AudioSessionPlugin.register(with: registry.registrar(forPlugin: "AudioSessionPlugin"))
ConnectivityPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlugin")) ConnectivityPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlugin"))
FlutterTtsPlugin.register(with: registry.registrar(forPlugin: "FlutterTtsPlugin"))
JustAudioPlugin.register(with: registry.registrar(forPlugin: "JustAudioPlugin")) JustAudioPlugin.register(with: registry.registrar(forPlugin: "JustAudioPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
TextToSpeechMacOsPlugin.register(with: registry.registrar(forPlugin: "TextToSpeechMacOsPlugin"))
} }

@ -151,6 +151,13 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" version: "0.0.0"
flutter_tts:
dependency: "direct main"
description:
name: flutter_tts
url: "https://pub.dartlang.org"
source: hosted
version: "3.6.3"
flutter_web_plugins: flutter_web_plugins:
dependency: transitive dependency: transitive
description: flutter description: flutter
@ -427,34 +434,6 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.4.12" version: "0.4.12"
text_to_speech:
dependency: "direct main"
description:
name: text_to_speech
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.3"
text_to_speech_macos:
dependency: transitive
description:
name: text_to_speech_macos
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.1"
text_to_speech_platform_interface:
dependency: transitive
description:
name: text_to_speech_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
text_to_speech_web:
dependency: transitive
description:
name: text_to_speech_web
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.2"
tuple: tuple:
dependency: transitive dependency: transitive
description: description:

@ -40,7 +40,7 @@ dependencies:
http: ^0.13.0 http: ^0.13.0
blinking_text: ^1.0.2 blinking_text: ^1.0.2
just_audio: ^0.9.31 just_audio: ^0.9.31
text_to_speech: ^0.2.3 flutter_tts: ^3.6.3
#signalr core #signalr core
signalr_core: ^1.1.1 signalr_core: ^1.1.1

@ -6,6 +6,9 @@
#include "generated_plugin_registrant.h" #include "generated_plugin_registrant.h"
#include <flutter_tts/flutter_tts_plugin.h>
void RegisterPlugins(flutter::PluginRegistry* registry) { void RegisterPlugins(flutter::PluginRegistry* registry) {
FlutterTtsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FlutterTtsPlugin"));
} }

@ -3,6 +3,7 @@
# #
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
flutter_tts
) )
list(APPEND FLUTTER_FFI_PLUGIN_LIST list(APPEND FLUTTER_FFI_PLUGIN_LIST

Loading…
Cancel
Save