|
|
|
@ -2,6 +2,7 @@ import 'dart:collection';
|
|
|
|
|
import 'dart:math';
|
|
|
|
|
|
|
|
|
|
import 'package:diplomaticquarterapp/config/config.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/models/Appointments/DoctorListResponse.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/models/Appointments/DoctorProfile.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/pages/BookAppointment/DoctorProfile.dart';
|
|
|
|
@ -33,6 +34,8 @@ import 'package:flutter/cupertino.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter_tts/flutter_tts.dart';
|
|
|
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
|
|
// import 'package:speech_to_text/speech_recognition_error.dart';
|
|
|
|
|
// import 'package:speech_to_text/speech_recognition_result.dart';
|
|
|
|
|
// import 'package:speech_to_text/speech_to_text.dart';
|
|
|
|
@ -44,9 +47,10 @@ class BottomBarSearch extends StatefulWidget {
|
|
|
|
|
|
|
|
|
|
class _SearchBot extends State<BottomBarSearch> {
|
|
|
|
|
SearchProvider searchProvider = new SearchProvider();
|
|
|
|
|
RobotProvider Provider = RobotProvider();
|
|
|
|
|
RobotProvider robotProvider = RobotProvider();
|
|
|
|
|
bool isLoading = false;
|
|
|
|
|
bool isError = false;
|
|
|
|
|
|
|
|
|
|
// final SpeechToText speech = SpeechToText();
|
|
|
|
|
String error = '';
|
|
|
|
|
String _currentLocaleId = "";
|
|
|
|
@ -64,6 +68,7 @@ class _SearchBot extends State<BottomBarSearch> {
|
|
|
|
|
|
|
|
|
|
bool _isInit = true;
|
|
|
|
|
TextEditingController searchController = TextEditingController();
|
|
|
|
|
ProjectViewModel projectProvider;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
@ -74,40 +79,37 @@ class _SearchBot extends State<BottomBarSearch> {
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
projectProvider = Provider.of(context);
|
|
|
|
|
return BottomAppBar(
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisSize: MainAxisSize.max,
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: SizedBox(
|
|
|
|
|
height: 64,
|
|
|
|
|
child: Material(
|
|
|
|
|
type: MaterialType.transparency,
|
|
|
|
|
child: TextField(
|
|
|
|
|
keyboardType: TextInputType.multiline,
|
|
|
|
|
maxLines: null,
|
|
|
|
|
controller: searchController,
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
hintText: TranslationBase.of(context).textToSpeech,
|
|
|
|
|
suffixIcon: IconButton(
|
|
|
|
|
icon: Icon(Icons.mic),
|
|
|
|
|
onPressed: () async {
|
|
|
|
|
setState(() {
|
|
|
|
|
searchController.text = '';
|
|
|
|
|
});
|
|
|
|
|
// await flutterTts.speak("Hello!");
|
|
|
|
|
//Future.delayed(const Duration(seconds: 1), () {
|
|
|
|
|
initSpeechState()
|
|
|
|
|
.then((value) => startVoiceSearch());
|
|
|
|
|
//});
|
|
|
|
|
},
|
|
|
|
|
)),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
child: Row(mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceAround, children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: SizedBox(
|
|
|
|
|
height: 64,
|
|
|
|
|
child: Material(
|
|
|
|
|
type: MaterialType.transparency,
|
|
|
|
|
child: TextField(
|
|
|
|
|
keyboardType: TextInputType.multiline,
|
|
|
|
|
maxLines: null,
|
|
|
|
|
controller: searchController,
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
hintText: TranslationBase.of(context).textToSpeech,
|
|
|
|
|
suffixIcon: IconButton(
|
|
|
|
|
icon: Icon(Icons.mic),
|
|
|
|
|
onPressed: () async {
|
|
|
|
|
setState(() {
|
|
|
|
|
searchController.text = '';
|
|
|
|
|
});
|
|
|
|
|
// await flutterTts.speak("Hello!");
|
|
|
|
|
//Future.delayed(const Duration(seconds: 1), () {
|
|
|
|
|
initSpeechState().then((value) => startVoiceSearch());
|
|
|
|
|
//});
|
|
|
|
|
},
|
|
|
|
|
)),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
]),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -164,10 +166,7 @@ class _SearchBot extends State<BottomBarSearch> {
|
|
|
|
|
Future<void> initSpeechState() async {
|
|
|
|
|
// await speech.initialize(onError: errorListener, onStatus: statusListener);
|
|
|
|
|
|
|
|
|
|
_currentLocaleId =
|
|
|
|
|
TranslationBase.of(AppGlobal.context).locale.languageCode == 'en'
|
|
|
|
|
? 'en-GB'
|
|
|
|
|
: 'ar-SA'; // systemLocale.localeId;
|
|
|
|
|
_currentLocaleId = TranslationBase.of(AppGlobal.context).locale.languageCode == 'en' ? 'en-GB' : 'ar-SA'; // systemLocale.localeId;
|
|
|
|
|
flutterTts.setLanguage(_currentLocaleId);
|
|
|
|
|
|
|
|
|
|
// if (!mounted) return;
|
|
|
|
@ -187,16 +186,9 @@ class _SearchBot extends State<BottomBarSearch> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getPages(text) {
|
|
|
|
|
var request = {
|
|
|
|
|
'VoiceMessage': text,
|
|
|
|
|
'Lang': TranslationBase.of(AppGlobal.context).locale.languageCode == 'en'
|
|
|
|
|
? 'En'
|
|
|
|
|
: 'Ar'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
searchProvider
|
|
|
|
|
.getBotPages(request)
|
|
|
|
|
.then((value) => {getCommands(value['Understand'])});
|
|
|
|
|
var request = {'VoiceMessage': text, 'Lang': TranslationBase.of(AppGlobal.context).locale.languageCode == 'en' ? 'En' : 'Ar'};
|
|
|
|
|
|
|
|
|
|
searchProvider.getBotPages(request).then((value) => {getCommands(value['Understand'])});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getCommands(result) async {
|
|
|
|
@ -207,9 +199,7 @@ class _SearchBot extends State<BottomBarSearch> {
|
|
|
|
|
case '100':
|
|
|
|
|
{
|
|
|
|
|
List clnicID = unique(result['ClinicId']);
|
|
|
|
|
if (result['ProjectId'] != 0 &&
|
|
|
|
|
clnicID.length > 0 &&
|
|
|
|
|
result['DoctorId'].length > 0) {
|
|
|
|
|
if (result['ProjectId'] != 0 && clnicID.length > 0 && result['DoctorId'].length > 0) {
|
|
|
|
|
if (clnicID.length == 1) {
|
|
|
|
|
getDoctorsList(
|
|
|
|
|
result['ProjectId'],
|
|
|
|
@ -221,9 +211,7 @@ class _SearchBot extends State<BottomBarSearch> {
|
|
|
|
|
} else {
|
|
|
|
|
goToClinic(clnicID);
|
|
|
|
|
}
|
|
|
|
|
} else if (result['ProjectId'] != 0 &&
|
|
|
|
|
clnicID.length > 0 &&
|
|
|
|
|
result['DoctorId'].length == 0) {
|
|
|
|
|
} else if (result['ProjectId'] != 0 && clnicID.length > 0 && result['DoctorId'].length == 0) {
|
|
|
|
|
if (clnicID.length == 1) {
|
|
|
|
|
getDoctorsList(
|
|
|
|
|
result['ProjectId'],
|
|
|
|
@ -233,9 +221,7 @@ class _SearchBot extends State<BottomBarSearch> {
|
|
|
|
|
} else {
|
|
|
|
|
goToClinic(clnicID);
|
|
|
|
|
}
|
|
|
|
|
} else if (result['ProjectId'] == 0 &&
|
|
|
|
|
clnicID.length > 0 &&
|
|
|
|
|
result['DoctorId'].length == 0) {
|
|
|
|
|
} else if (result['ProjectId'] == 0 && clnicID.length > 0 && result['DoctorId'].length == 0) {
|
|
|
|
|
if (clnicID.length == 1) {
|
|
|
|
|
getDoctorsList(
|
|
|
|
|
result['ProjectId'],
|
|
|
|
@ -245,9 +231,7 @@ class _SearchBot extends State<BottomBarSearch> {
|
|
|
|
|
} else {
|
|
|
|
|
goToClinic(clnicID);
|
|
|
|
|
}
|
|
|
|
|
} else if (result['ProjectId'] == 0 &&
|
|
|
|
|
clnicID.length > 0 &&
|
|
|
|
|
result['DoctorId'].length > 0) {
|
|
|
|
|
} else if (result['ProjectId'] == 0 && clnicID.length > 0 && result['DoctorId'].length > 0) {
|
|
|
|
|
if (clnicID.length == 1) {
|
|
|
|
|
getDoctorsList(
|
|
|
|
|
result['ProjectId'],
|
|
|
|
@ -394,12 +378,11 @@ class _SearchBot extends State<BottomBarSearch> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getDoctorProfile(projectId, clinicId, doctorId, context, doctorData) {
|
|
|
|
|
int languageID = projectProvider.isArabic ? 1 : 2;
|
|
|
|
|
List<DoctorProfileList> docProfileList = [];
|
|
|
|
|
DoctorsListService service = new DoctorsListService();
|
|
|
|
|
|
|
|
|
|
service
|
|
|
|
|
.getDoctorsProfile(doctorId, clinicId, projectId, context)
|
|
|
|
|
.then((res) {
|
|
|
|
|
service.getDoctorsProfile(doctorId, clinicId, projectId, languageID, context).then((res) {
|
|
|
|
|
if (res['MessageStatus'] == 1) {
|
|
|
|
|
if (res['DoctorProfileList'].length != 0) {
|
|
|
|
|
res['DoctorProfileList'].forEach((v) {
|
|
|
|
@ -407,8 +390,7 @@ class _SearchBot extends State<BottomBarSearch> {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
navigateToDoctorProfile(context, doctorData[0], docProfileList[0],
|
|
|
|
|
isAppo: true);
|
|
|
|
|
navigateToDoctorProfile(context, doctorData[0], docProfileList[0], isAppo: true);
|
|
|
|
|
//speak();
|
|
|
|
|
}
|
|
|
|
|
}).catchError((err) {
|
|
|
|
@ -417,33 +399,29 @@ class _SearchBot extends State<BottomBarSearch> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getDoctorsList(projectId, clinicId, context, {doctorId, doctorName}) {
|
|
|
|
|
int languageID = projectProvider.isArabic ? 1 : 2;
|
|
|
|
|
List<DoctorList> doctorsList = [];
|
|
|
|
|
List<String> arr = [];
|
|
|
|
|
List<String> arrDistance = [];
|
|
|
|
|
DoctorsListService service = new DoctorsListService();
|
|
|
|
|
GifLoaderDialogUtils.showMyDialog(context);
|
|
|
|
|
service
|
|
|
|
|
.getDoctorsList(clinicId, projectId, false, context,
|
|
|
|
|
doctorId: doctorId, doctorName: doctorName)
|
|
|
|
|
.then((res) {
|
|
|
|
|
service.getDoctorsList(clinicId, projectId, false, languageID, context, doctorId: doctorId, doctorName: doctorName).then((res) {
|
|
|
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
|
if (res['MessageStatus'] == 1) {
|
|
|
|
|
setState(() {
|
|
|
|
|
if (res['SearchDoctorsByTime_IsVoiceCommandList'] != null &&
|
|
|
|
|
res['SearchDoctorsByTime_IsVoiceCommandList'].length != 0) {
|
|
|
|
|
if (res['SearchDoctorsByTime_IsVoiceCommandList'] != null && res['SearchDoctorsByTime_IsVoiceCommandList'].length != 0) {
|
|
|
|
|
doctorsList.clear();
|
|
|
|
|
res['SearchDoctorsByTime_IsVoiceCommandList'].forEach((v1) {
|
|
|
|
|
v1['DoctorList'].forEach((v) {
|
|
|
|
|
doctorsList.add(new DoctorList.fromJson(v));
|
|
|
|
|
arr.add(new DoctorList.fromJson(v).projectName!);
|
|
|
|
|
arr.add(new DoctorList.fromJson(v).projectName!);
|
|
|
|
|
arrDistance.add(new DoctorList.fromJson(v)
|
|
|
|
|
.projectDistanceInKiloMeters
|
|
|
|
|
.toString());
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
if (doctorsList.length == 1) {
|
|
|
|
|
getDoctorProfile(
|
|
|
|
|
projectId, clinicId, doctorId[0], context, doctorsList);
|
|
|
|
|
getDoctorProfile(projectId, clinicId, doctorId[0], context, doctorsList);
|
|
|
|
|
|
|
|
|
|
//speak();
|
|
|
|
|
} else {
|
|
|
|
@ -454,15 +432,14 @@ class _SearchBot extends State<BottomBarSearch> {
|
|
|
|
|
|
|
|
|
|
res['DoctorList'].forEach((v) {
|
|
|
|
|
doctorsList.add(new DoctorList.fromJson(v));
|
|
|
|
|
arr.add(new DoctorList.fromJson(v).projectName!);
|
|
|
|
|
arr.add(new DoctorList.fromJson(v).projectName!);
|
|
|
|
|
arrDistance.add(new DoctorList.fromJson(v)
|
|
|
|
|
.projectDistanceInKiloMeters
|
|
|
|
|
.toString());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (doctorsList.length == 1) {
|
|
|
|
|
getDoctorProfile(
|
|
|
|
|
projectId, clinicId, doctorId[0], context, doctorsList);
|
|
|
|
|
getDoctorProfile(projectId, clinicId, doctorId[0], context, doctorsList);
|
|
|
|
|
|
|
|
|
|
//speak();
|
|
|
|
|
} else {
|
|
|
|
@ -479,8 +456,7 @@ class _SearchBot extends State<BottomBarSearch> {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future navigateToDoctorProfile(context, docObject, docProfile,
|
|
|
|
|
{isAppo}) async {
|
|
|
|
|
Future navigateToDoctorProfile(context, docObject, docProfile, {isAppo}) async {
|
|
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
FadePage(
|
|
|
|
@ -497,11 +473,7 @@ class _SearchBot extends State<BottomBarSearch> {
|
|
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
FadePage(
|
|
|
|
|
page: BranchView(
|
|
|
|
|
doctorsList: docList,
|
|
|
|
|
result: result,
|
|
|
|
|
num: numAll,
|
|
|
|
|
resultDistance: arrDistance),
|
|
|
|
|
page: BranchView(doctorsList: docList, result: result, num: numAll, resultDistance: arrDistance),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|