@ -101,7 +101,7 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
var sharedPref = new AppSharedPreferences ( ) ;
bool _hasSpeech = false ;
ProjectViewModel projectProvider ;
bool isAnimationEnable = tru e;
bool isAnimationEnable = fals e;
AnimationController controller ;
Animation < Offset > offset ;
String networkImage ;
@ -111,22 +111,30 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
AnimationController ( vsync: this , duration: Duration ( seconds: 1 ) ) ;
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 ( ) ;
} ) ;
controller . reverse ( ) ;
event . controller . stream . listen ( ( p ) {
if ( p [ ' isRobotVisible ' ] = = ' true ' ) {
if ( this . mounted ) {
setState ( ( ) {
sharedPref . setBool ( IS_ROBOT_VISIBLE , true ) ;
controller . reverse ( ) ;
} ) ;
}
}
} ) ;
event . controller . stream . listen ( ( p ) {
if ( p [ ' startPopUp ' ] = = ' true ' ) {
if ( this . mounted ) {
new RoboSearch ( context: context ) . showAlertDialog ( context ) ;
initSpeechState ( ) . then ( ( value ) = > { startVoiceSearch ( ) } ) ;
}
}
} ) ;
super . initState ( ) ;
}
@ -171,7 +179,6 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
: ' assets/images/gif/robot-idle.gif ' ) ,
) ,
onTap: ( ) {
new RoboSearch ( context: context ) . showAlertDialog ( context ) ;
initSpeechState ( ) . then ( ( value ) = > { startVoiceSearch ( ) } ) ;
} ,
@ -184,7 +191,7 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
setState ( ( ) {
if ( this . mounted ) {
controller . forward ( ) ;
/ / isShow = false ;
sharedPref . setBool ( IS_ROBOT_VISIBLE , false ) ;
}
} ) ;
} ,
@ -220,26 +227,14 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
reconizedWord = result . recognizedWords ;
event . setValue ( { " searchText " : reconizedWord } ) ;
if ( result . finalResult = = true ) {
/ / setState ( ( ) {
/ / setState ( ( ) {
/ / searchText = reconizedWord ;
/ / } ) ;
Future . delayed ( const Duration ( seconds: 1 ) , ( ) {
_speak ( reconizedWord ) ;
RoboSearch . closeAlertDialog ( context ) ;
} ) ;
}
/ / } ) ;
}
Future _speak ( reconizedWord ) async {
/ / Navigator . of ( AppGlobal . context ) . pop ( ) ;
/ / await flutterTts . speak ( reconizedWord ) ;
/ / RoboSearch . closeAlertDialog ( context ) ;
getPages ( reconizedWord ) ;
}
@ -799,13 +794,15 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
) ;
}
speak ( ) async {
speak ( {isInit } ) async {
setState ( ( ) {
this . networkImage = results [ ' AnimationURL ' ] ;
this . isAnimationEnable = true ;
} ) ;
if ( _currentLocaleId = = ' en ' & & results [ ' ReturnMessage ' ] ! = null ) {
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 ' ] ) ;
@ -815,7 +812,7 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
await flutterTts . speak ( results [ ' ReturnMessage_Ar ' ] ) ;
}
stopAnimation ( ) ;
stopAnimation ( isInit: isInit ) ;
}
goToClinic ( List ids ) {
@ -847,25 +844,32 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
' 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 ' ] ) ;
if ( await sharedPref . getBool ( IS_ROBOT_INIT ) = = null ) {
this . speak ( isInit: true ) ;
controller . reverse ( ) ;
} else {
controller . forward ( ) ;
}
/ / 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 ( ) ;
/ / this . isAnimationEnable = true ;
/ / stopAnimation ( ) ;
}
stopAnimation ( ) {
stopAnimation ( { isInit } ) async {
if ( isInit & & ( await sharedPref . getBool ( IS_ROBOT_INIT ) = = null ) ) {
sharedPref . setBool ( IS_ROBOT_INIT , isInit ) ;
}
flutterTts . setCompletionHandler ( ( ) = > {
event . setValue ( { " animationEnable " : ' false ' } ) ,
setState ( ( ) {
@ -946,11 +950,16 @@ class RoboSearch {
child: Text ( searchText ! = null & & searchText ! = ' null '
? searchText
: ' Try saying something ' ) ) ) ,
/ / searchText = = ' null ' ? Center ( child: RaisedButton ( child: Text ( ' Retry ' ) , onPressed: ( ) {
/ / / / RoboSearch . closeAlertDialog ( context ) ;
/ / new FloatingSearchButton ( ) . createState ( ) . startVoiceSearch ( ) ;
/ / } , ) ) : SizedBox ( )
searchText = = ' null '
? Center (
child: RaisedButton (
child: Text ( ' Retry ' ) ,
onPressed: ( ) {
RoboSearch . closeAlertDialog ( context ) ;
event . setValue ( { ' startPopUp ' : ' true ' } ) ;
} ,
) )
: SizedBox ( )
] ) ,
) ) ;
} ) ,