@ -2,9 +2,13 @@ import 'dart:collection';
import ' dart:io ' ;
import ' dart:math ' ;
import ' package:cached_network_image/cached_network_image.dart ' ;
import ' package:diplomaticquarterapp/config/config.dart ' ;
import ' package:diplomaticquarterapp/config/shared_pref_kay.dart ' ;
import ' package:diplomaticquarterapp/core/service/AuthenticatedUserObject.dart ' ;
import ' package:diplomaticquarterapp/core/service/medical/vital_sign_service.dart ' ;
import ' package:diplomaticquarterapp/core/viewModels/project_view_model.dart ' ;
import ' package:diplomaticquarterapp/locator.dart ' ;
import ' package:diplomaticquarterapp/models/Appointments/DoctorListResponse.dart ' ;
import ' package:diplomaticquarterapp/models/Appointments/DoctorProfile.dart ' ;
import ' package:diplomaticquarterapp/models/Authentication/authenticated_user.dart ' ;
@ -13,6 +17,7 @@ import 'package:diplomaticquarterapp/pages/AlHabibMedicalService/parking_page.da
import ' package:diplomaticquarterapp/pages/Blood/blood_donation.dart ' ;
import ' package:diplomaticquarterapp/pages/Blood/my_balance_page.dart ' ;
import ' package:diplomaticquarterapp/pages/BookAppointment/widgets/BranchView.dart ' ;
import ' package:diplomaticquarterapp/pages/ContactUs/LiveChat/livechat_page.dart ' ;
import ' package:diplomaticquarterapp/pages/ContactUs/findus/findus_page.dart ' ;
import ' package:diplomaticquarterapp/pages/DrawerPages/family/my-family.dart ' ;
import ' package:diplomaticquarterapp/pages/ErService/AmbulanceReq.dart ' ;
@ -55,9 +60,10 @@ import 'package:speech_to_text/speech_to_text.dart';
import ' package:diplomaticquarterapp/pages/BookAppointment/DoctorProfile.dart ' ;
import ' package:diplomaticquarterapp/pages/BookAppointment/Search.dart ' ;
import ' package:flutter/cupertino.dart ' ;
import ' package:diplomaticquarterapp/pages/pharmacies/screens/pharmacy_module_page.dart ' ;
import ' package:smart_progress_bar/smart_progress_bar.dart ' ;
import ' package:url_launcher/url_launcher.dart ' ;
import ' package:diplomaticquarterapp/pages/AlHabibMedicalService/%E2%80%8B%20health_calculators.dart ' ;
class FloatingSearchButton extends StatefulWidget {
@ override
@ -93,10 +99,10 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
var sharedPref = new AppSharedPreferences ( ) ;
bool _hasSpeech = false ;
ProjectViewModel projectProvider ;
bool isAnimationEnable = true ;
AnimationController controller ;
Animation < Offset > offset ;
String networkImage ;
@ override
void initState ( ) {
controller =
@ -104,6 +110,7 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
offset = Tween < Offset > ( begin: Offset . zero , end: Offset ( 0.0 , 1.0 ) )
. animate ( controller ) ;
controller . reverse ( ) ;
initialSpeak ( ) ;
Future . delayed ( const Duration ( seconds: 2 ) , ( ) {
requestPermissions ( ) ;
getUserData ( ) ;
@ -122,14 +129,23 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
super . initState ( ) ;
}
@ override
void didUpdateWidget ( FloatingSearchButton oldWidget ) {
super . didUpdateWidget ( oldWidget ) ;
/ / event . controller . stream . listen ( ( p ) {
/ / if ( p [ ' animationEnable ' ] ! = ' false ' ) {
/ / initialSpeak ( ) ;
/ / }
/ / } ) ;
}
AuthenticatedUserObject authenticatedUserObject =
locator < AuthenticatedUserObject > ( ) ;
VitalSignService _vitalSignService = locator < VitalSignService > ( ) ;
@ override
Widget build ( BuildContext context ) {
projectProvider = Provider . of ( context ) ;
return Container (
child:
SlideTransition (
position: offset ,
child: getStack ( ) ) ) ;
child: SlideTransition ( position: offset , child: getStack ( ) ) ) ;
}
Widget getStack ( ) {
@ -138,10 +154,15 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
width: 150 ,
margin: EdgeInsets . only ( left: 20.0 ) ,
child: Stack ( children: < Widget > [
GestureDetector (
child: Container (
child: Image . asset ( ' assets/images/gif/robot-idle.gif ' ) ,
child: networkImage ! = null ? CachedNetworkImage (
imageUrl: networkImage ,
placeholder: ( context , url ) = > Image . asset ( ' assets/images/gif/robot-idle.gif ' ) ,
errorWidget: ( context , url , error ) = > Icon ( Icons . error ) ,
) : Image . asset ( isAnimationEnable = = true
? ' assets/images/gif/robot-speaking.gif '
: ' assets/images/gif/robot-idle.gif ' ) ,
) ,
onTap: ( ) {
initSpeechState ( ) . then ( ( value ) = > { startVoiceSearch ( ) } ) ;
@ -244,7 +265,6 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
}
void errorListener ( SpeechRecognitionError error ) {
print ( error ) ;
event . setValue ( { " searchText " : ' null ' } ) ;
/ / setState ( ( ) {
/ / reconizedWord = " ${ error . errorMsg } - ${ error . permanent } " ;
@ -283,64 +303,6 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
doctorId: result [ ' DoctorId ' ] ,
doctorName: null ,
) ;
/ / List clnicID = unique ( result [ ' ClinicId ' ] ) ;
/ / if ( result [ ' ProjectId ' ] ! = 0 & &
/ / clnicID . length > 0 & &
/ / result [ ' DoctorId ' ] . length > 0 ) {
/ / if ( clnicID . length = = 1 ) {
/ / getDoctorsList (
/ / result [ ' ProjectId ' ] ,
/ / clnicID [ 0 ] ,
/ / context ,
/ / doctorId: result [ ' DoctorId ' ] ,
/ / doctorName: null ,
/ / ) ;
/ / } else {
/ / goToClinic ( clnicID ) ;
/ / }
/ / } else if ( result [ ' ProjectId ' ] ! = 0 & &
/ / clnicID . length > 0 & &
/ / result [ ' DoctorId ' ] . length = = 0 ) {
/ / if ( clnicID . length = = 1 ) {
/ / getDoctorsList (
/ / result [ ' ProjectId ' ] ,
/ / clnicID [ 0 ] ,
/ / context ,
/ / ) ;
/ / } else {
/ / goToClinic ( clnicID ) ;
/ / }
/ / } else if ( result [ ' ProjectId ' ] = = 0 & &
/ / clnicID . length > 0 & &
/ / result [ ' DoctorId ' ] . length = = 0 ) {
/ / if ( clnicID . length = = 1 ) {
/ / getDoctorsList (
/ / result [ ' ProjectId ' ] ,
/ / clnicID [ 0 ] ,
/ / context ,
/ / ) ;
/ / } else {
/ / goToClinic ( clnicID ) ;
/ / }
/ / } else if ( result [ ' ProjectId ' ] = = 0 & &
/ / clnicID . length > 0 & &
/ / result [ ' DoctorId ' ] . length > 0 ) {
/ / if ( clnicID . length = = 1 ) {
/ / getDoctorsList (
/ / result [ ' ProjectId ' ] ,
/ / clnicID [ 0 ] ,
/ / context ,
/ / doctorId: result [ ' DoctorId ' ] ,
/ / doctorName: null ,
/ / ) ;
/ / } else {
/ / goToClinic ( clnicID ) ;
/ / }
/ / } else {
/ / goToClinic ( clnicID ) ;
/ / }
/ / speak ( ) ;
}
break ;
case ' 102 ' :
@ -639,6 +601,7 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
case ' 44 ' :
{
/ / chat need be implmented here .
Navigator . push ( context , FadePage ( page: LiveChatPage ( ) ) ) ;
}
break ;
case ' 45 ' :
@ -656,14 +619,54 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
Navigator . push ( context , FadePage ( page: FeedbackHomePage ( ) ) ) ;
}
break ;
case ' 45 ' :
{
launch ( ' https://hmg.com/ir/ar/Pages/ShareInformation/home.aspx ' ) ;
break ;
}
case ' 46 ' :
{
launch ( ' https://hmg.com/ir/ar/pages/home.aspx ' ) ;
break ;
}
case ' 47 ' :
{
/ / this . cs . sharedService . setSharedData ( true , " isComingFromVoiceCommand " ) ;
/ / this . cs . openFeedback ( ) ;
Navigator . push ( context , FadePage ( page: FeedbackHomePage ( ) ) ) ;
break ;
}
case ' 48 ' :
{
Navigator . push ( context , FadePage ( page: PharmacyPage ( ) ) ) ;
break ;
}
case ' 50 ' :
{
this . signOut ( ) ;
break ;
}
case ' 51 ' :
{
/ / Women health calculator
/ / this . cs . sharedService . setSharedData ( true , " isOpenWomenHealthCalculator " ) ;
/ / this . cs . navigateForward ( ' /calculators/calculator ' ) ;
Navigator . push ( context , FadePage ( page: HealthCalculators ( ) ) ) ;
break ;
}
case ' 52 ' :
{
/ / this . bridge . openMyInvoices ( ) ;
break ;
}
case ' 53 ' :
{
launch ( " tel://920066666 " ) ;
break ;
}
default :
{
/ / Navigator . pushAndRemoveUntil (
/ / context ,
/ / MaterialPageRoute (
/ / builder: ( context ) = > LandingPage ( ) ) ,
/ / ( Route < dynamic > r ) = > false ) ;
speak ( ) ;
}
break ;
@ -783,17 +786,22 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
}
speak ( ) async {
/ / var voice = await flutterTts . getVoices ;
setState ( ( ) {
this . networkImage = results [ ' AnimationURL ' ] ;
this . isAnimationEnable = true ;
} ) ;
if ( _currentLocaleId = = ' en ' & & results [ ' ReturnMessage ' ] ! = null ) {
await flutterTts . setVoice ( { " name " : " en-au-x-aub-network " , " locale " : " en-AU " } ) ;
await flutterTts
. setVoice ( { " name " : " en-au-x-aub-network " , " locale " : " en-AU " } ) ;
await flutterTts . speak ( results [ ' ReturnMessage ' ] ) ;
} else if ( results [ ' ReturnMessage_Ar ' ] ! = null ) {
await flutterTts . setVoice ( { " name " : " ar-xa-x-ard-network " , " locale " : " ar " } ) ;
await flutterTts
. setVoice ( { " name " : " ar-xa-x-ard-network " , " locale " : " ar " } ) ;
await flutterTts . speak ( results [ ' ReturnMessage_Ar ' ] ) ;
}
/ / Future . delayed ( const Duration ( seconds: 10 ) , ( ) {
/ / initSpeechState ( ) . then ( ( value ) = > startVoiceSearch ( ) ) ;
/ / } ) ;
stopAnimation ( ) ;
}
goToClinic ( List ids ) {
@ -816,6 +824,50 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
user = AuthenticatedUser . fromJson (
await this . sharedPref . getObject ( USER_PROFILE ) ) ;
}
/ / await flutterTts . setVoice ( " en-us-x-sfg#male_1-local " ) ;
}
initialSpeak ( ) async {
results = {
' ReturnMessage_Ar ' :
" هذه الخدمة تم تصميمها لتتمكن من ربط الملفات الطبية للعائلة بملفك الطبي حتى تتمكن من إدارة سجلاتهم عن طريق تسجيل الدخول إلى ملفك الطبي. " ,
' ReturnMessage ' :
" Through this service, you will be able to link your family medical files to your medical file so that you can manage their records by login to your medical file. "
} ;
this . speak ( ) ;
if ( Provider . of < ProjectViewModel > ( context , listen: false ) . isArabic = =
false & &
results [ ' ReturnMessage ' ] ! = null ) {
await flutterTts
. setVoice ( { " name " : " en-au-x-aub-network " , " locale " : " en-AU " } ) ;
await flutterTts . speak ( results [ ' ReturnMessage ' ] ) ;
} else if ( results [ ' ReturnMessage_Ar ' ] ! = null ) {
await flutterTts
. setVoice ( { " name " : " ar-xa-x-ard-network " , " locale " : " ar " } ) ;
await flutterTts . speak ( results [ ' ReturnMessage_Ar ' ] ) ;
}
this . isAnimationEnable = true ;
stopAnimation ( ) ;
}
stopAnimation ( ) {
flutterTts . setCompletionHandler ( ( ) = > {
event . setValue ( { " animationEnable " : ' false ' } ) ,
setState ( ( ) {
this . networkImage = null ;
this . isAnimationEnable = false ;
} )
} ) ;
}
signOut ( ) async {
authenticatedUserObject . logout ( ) ;
projectProvider . isLogin = false ;
await authenticatedUserObject . getUser ( ) ;
_vitalSignService . heightCm = " " ;
_vitalSignService . weightKg = " " ;
await sharedPref . clear ( ) ;
this . user = null ;
Navigator . of ( context ) . pushNamed ( HOME ) ;
}
}